Hi Alberto,
Since the Merit Function Editor lets you put multiple DMFS operands, I doubt that there’s a method to retrieve the row number of the DMFS operand. To me, it seems you’ll have to scan the rows as you mentioned.
Curious to hear other people’s answer though.
Take care,
David
Hi Alberto,
If you simply call the ISEQOptimizationWizard2, then OpticStudio will automatically update the DMFS the same way it would if you called the wizard from the GUI:
- If there is already a DMFS operand in the MFE, then all operands below the DMFS are deleted and the DMF is rebuilt
- If there is not a DMFS operand in the MFE, then all operands are deleted and only the DMF will exist
If you want to keep this manual, then yes, you will need to scan all the rows of the MFE in order to find the first DMFS (if there is a second DMFS, OpticStudio will automatically re-write if you rebuild a DMFS); none of the methods attached to the IMertiFunctionEditor will allow you to get data values for more than 1 row at a time.
The DMFS should be close to the top so even with dozens or hundreds of calls to GetOperandAt()
method should be extremely quick. However, if you either have thousands of operands before your DMFS or you need to extract extra data from all the operands under the DMFS, this can be a very time consuming loop, especially if you’re using interpreted code such as Python/Matlab. I would suggest calling the SaveMeritFunction()
method and then manually parse the text .MF file. If memory serves, with Python I can parse 100,000 rows in under 2 seconds by reading directly from the text file.
Hi David and Michael,
your help is very appreciated.
Based on your suggestions I coded this simple function which scans the whole MF and returns the row number of all DMFS operands:
def DMFSfind(TheMFE):
out = ]
for rowN in range(1, TheMFE.NumberOfRows):
t = TheMFE.GetOperandAt(rowN).TypeName
if t=='DMFS':
out.append(rowN)
return out
The MF I’m working with is pretty short, therefore I was not forced to save and parse a txt file, as thoroughly explained by Michael.
Glad to hear you have a working solution. If you want to save just a little bit more speed & since OpticStudio only wants to have 1 DMFS in the MFE, you can have another return function inside the for
loop as well. Also, it probably won’t matter for practical purposes, but you’re missing the last operand in the MFE (the range
function in Python excludes the end point), so you’ll always want to add +1 to anything in the API which has a “number of xxx” in it.
def DMFSfind(TheMFE):
out = /]
for rowN in range(1, TheMFE.NumberOfRows + 1):
t = TheMFE.GetOperandAt(rowN).TypeName
if t=='DMFS':
out.append(rowN)
return out
return out
Thank you @MichaelH ! I completely missed the range issue.