Solved

# ZPL Macros: Efficient ways of getting data points from the MTF

• 158 views

• Student
• 0 replies

Hello,

I am trying to develop a ZPL macro that will be used in my merit function so that different wavelengths and different fields will all share the same MTF. I am currently getting very good results with my code, but it is a little bit slow at roughly 8 seconds per cycle which is worrisome as I am currently only doing 1 field with 3 wavelengths. I was wondering how GETMTF actually works since it seems like it is calculating the entire MTF and only extracts the value for a single specified frequency when GETMTF is ran. For my purpose, it would be more efficient to calculate the entire MTF once for each wavelength/field, and then I could just grab the values directly from the MTF rather than having to run a loop combined with GETMTF to get the values I need to calculate MSE.  Please let me know if you have any suggestions on making my code more efficient or any alternative methods to solve this problem.

icon

Best answer by Mark.Nicholson 29 July 2023, 18:43

View original

Userlevel 7
+3

Hi Cameron,

That’s a nice piece of code you’ve written there.

In general, I always prefer to get data using available operands rather than the GETwhatever keywords. Back in the day we wrote GET* keywords for every analysis feature, but soon realized that this would end up with hundreds of keywords. Instead, we wrote the OPER/OPEV keywords that allowed you to call optimization operands directly. Since every analysis feature already comes with optimization operands, this was way more efficient.

For MTF there is an additional reason to use operands. As you said, GETMTF will calculate the entire spectrum of response, and then return the desired values. There are two ways to compute MTF, by Fourier transform of the pupil function, or by autocorrelation of the pupil function. Since when optimizing we want data at a specific frequency, we use autocorrelation to produce the data at the specified frequency, rather than getting the whole spectrum and then extracting the single value needed.

You could also write a merit function (or a macro that writes a merit function) that computes all the data you want. Save it as MyMerit.MF, load it and read it out line by line to get the data you want. Assuming you want the same data returned many times, that would be my preferred approach. Also, if you use an MTFT(settings) then put the MTFS(settings) on the next line. The T operand computes both T and S, and caches the S for the next operand. That cache gets flushed if the next operand is not the corresponding S operand, so you can speed up the calculation by a further factor of two through the order in which you get the data.

• Mark