MREYE-LUMC / ZOSPy

Wrapper around the Zemax OpticStudio API. Provides a more pythonic and intuitive way to interact with the ZOS-API through python using a .NET connection.
https://zospy.readthedocs.io
MIT License
43 stars 12 forks source link

Fft mtf map #65

Closed laser-axel closed 8 months ago

laser-axel commented 8 months ago

Proposed change

Added methods OpticStudioSystem.LDE.SurfaceByComment() and OpticStudioSystem.LDE.SurfaceByRegex() to keep scripts and tools functioning when a surface is added to the system Added zospy.analyses.mtfclasses to have some added features for the FFT-MFT and FFT-MFT-map for plotting in pyplo

Type of change

Additional information

Related issues

It is common practise for me to add environment variables to my windows user account to keep certain settings as the path to the dev-checkout of zospy persistent. I can change this to whatever you think is more convenient

Checklist

If you contributed an analysis:

If you contributed an example:

crnh commented 8 months ago

Hi @laser-axel,

Thanks for your contributions! These are a lot of different changes, and it is better to open separate pull requests for this:

Furthermore, here are some first points for improvement:

We are looking forward to your new pull requests, and don't hesitate to ask us any questions if something is unclear!

laser-axel commented 8 months ago

I totally agree to your first 3 bullets you mention at "points for improvement". Also I did not get tox and pytest to run the existing tests, so far. Regarding the plotting fuctions. Technically I did just added a colormap and a list of line-colors as attributes. All the actual plotting is done in the .jpynb. Anyway, I can remove that.

But I don't get the idea behind your "no classes and methods, use function calls instead"-appproach. Not intented as flame! I still like what you have done so far. Sorry. but that is absolutely contrary to my mindset. When a student in the lab comes with new piece of code with a call to a function with an object reference as 1st parameter and dozens of other parameters, I would say: "The object referenced should carry all those parameters and have a method to do that." And that`s the way the ZOSAPI originally works. There is certainly room for improvements and enhancements, but I don't see any benefits in chaning general way of organizing the myriads of features of Optic Studio. IMHO from going from the purely OO-approach in the ZOSAPI to a set of function calls witch object reference scheme is a kind of step backward rather than forward.

Was a nice try. I did enjoy trying get me idea here. Learned a lot. No hard feelings on my side!

Best regards, Axel

crnh commented 8 months ago

Regarding the plotting fuctions. Technically I did just added a colormap and a list of line-colors as attributes. All the actual plotting is done in the .jpynb. Anyway, I can remove that.

Everything related to colors and plot layout is very dependent on personal preferences. As stated in the referenced discussion, to make these functions suitable for wider use, they need a lot of customization options and proper unit tests. In the end, this adds a maintenance burden that we are currently not willing to bear.

If there appears to be a high demand for plotting functions in ZOSPy, then we are of course willing to add these. Even then, this functionality should be separated from the analysis functions, probably in a separate module.

But I don't get the idea behind your "no classes and methods, use function calls instead"-appproach.

When a student in the lab comes with new piece of code with a call to a function with an object reference as 1st parameter and dozens of other parameters, I would say: "The object referenced should carry all those parameters and have a method to do that."

I understand your preference for an object-oriented approach and in most cases this is indeed the right thing to choose. We also considered an object-oriented interface for the analyses, but in the end went for a procedural interface for a few reasons:

Regarding the number of parameters: wherever sensible, the number of parameters should be kept as small as possible. However, in the (scientific) Python ecosystem, it is not uncommon to have functions with a lot of parameters (see for example Matplotlib).

"The object referenced should carry all those parameters and have a method to do that."

Are you referring to the oss object that is passed to every analysis? I understand your concerns here, but (monkey) patching the objects from the ZOS-API is less elegant and results in a less maintainable solution. We may consider making the oss parameter optional and obtain the primary system by default, so it is not necessary to always supply the oss argument. However, this is more error-prone.

I did enjoy trying get me idea here.

Do you mean one of the purposes of this PR was to propose a new analysis interface? We do welcome such proposals, but please do this in a discussion as it boils down to an architectural change in ZOSPy.

Was a nice try.

Do you want to continue working on this PR, or should it be closed?

No hard feelings on my side!

Same for us!

laser-axel commented 8 months ago

This stems from the discussion the zemax communitz forum. I drew the line between added feature and architectural change somewhere else.