Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyses Interface Broken #9

Closed
julian-irwin-tfs opened this issue Feb 15, 2023 · 5 comments
Closed

Analyses Interface Broken #9

julian-irwin-tfs opened this issue Feb 15, 2023 · 5 comments

Comments

@julian-irwin-tfs
Copy link

In example notebook Escudero-Sanz eye model\Escudero-Sanz eye model.ipynb the psf analysis code fails for a few different reasons.

Running this line:

psf = zp.analyses.psf.huygens_psf(oss, '256x256', '256x256', normalize=True, oncomplete='Sustain')

Gives this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[13], line 1
----> 1 psf = zp.analyses.psf.huygens_psf(oss, '256x256', '256x256', normalize=True, oncomplete='Sustain')

File ~\Code\ZOSPy\zospy\analyses\psf.py:61, in huygens_psf(oss, pupil_sampling, image_sampling, image_delta, rotation, wavelength, field, psftype, show_as, use_polarization, use_centroid, normalize, oncomplete)
     58 analysis = oss.Analyses.New_Analysis_SettingsFirst(constants.Analysis.AnalysisIDM.loc[analysistype])
     60 # Apply settings
---> 61 analysis.Settings.PupilSampleSize = utils.zputils.proc_constant(constants.Analysis.SampleSizes,
     62                                                                 utils.zputils.standardize_sampling(pupil_sampling))
     63 analysis.Settings.ImageSampleSize = utils.zputils.proc_constant(constants.Analysis.SampleSizes,
     64                                                                 utils.zputils.standardize_sampling(image_sampling))
     65 analysis.Settings.ImageDelta = image_delta

AttributeError: 'IA_' object has no attribute 'Settings'

In the ZOS API reference, I do not see a Settings attribute to the IA class. Perhaps this code does not work with the most recent release of ZOS API?

image

Python example 23 from the ZOS API Reference contains the following similar code for running analyses:

ray = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.RayFan)
ray_settings = ray.GetSettings()
ray_settings.NumberOfRays = max_rays / 2
ray_settings.Field.UseAllFields()
ray_settings.Wavelength.UseAllWavelengths()
@LucVV
Copy link
Contributor

LucVV commented Feb 15, 2023

Hi @julian-irwin-tfs,

Similar to your other issue, could you check which Python.Net version you are on? I think it should work with the newest version of the API and Python.Net 2.5.2, but will check somewhere this week to be sure.

@julian-irwin-tfs
Copy link
Author

I am using Python.Net 3.0 or greater. I had a hard time getting the older versions to install using python 3.9, 3.10 or 3.11. Pip kept trying to build wheels from scratch. Python.Net 3.0 installed right away, and I noticed that some of the issues in your code are fairly minor fixes.

However, the verbatim example code from the ZOS API reference also do not run on my system. They have some similar errors where Field or Wavelength attributes of an IAR results object are missing.

@crnh
Copy link
Collaborator

crnh commented Feb 16, 2023

This issue is caused by an issue with Python.NET 3.0 and greater. All / most Analysis objects implement their own specific interface (in this case IAS_HuygensPsf) that extends the IAS_ interface. However, when such an object is created, Python.NET 3.x will not return an object of the IAS_HuygensPsf interface, but of its parent interface instead. Due to this behaviour, all methods specific to the analysis cannot be called from ZOSPy. Fixing this issue seems unfortunately not a trivial task.

For the time being, I would advise to use Python.NET 2.5.2, which indeed does not work (well) with Python 3.9+. The latest supported version is Python 3.8.

Edit: we are currently running OpticStudio 23R1, and this problem only occurs when using Python.NET 3.0+.

@julian-irwin-tfs
Copy link
Author

Thanks! I tried again with Python 3.8 and got pythonnet 2.5.2 installed. Your example notebook now runs without errors. Thanks for the nice package. Sorry to bother you with redundant issue threads!

By the way, are you interested in the contribution of further examples? I primarily model spectrometers in Zemax. It might be nice to add a spectrometer example to your collection of ophthalmological examples. It would demonstrate a few more features such as diffraction gratings, paraxial surfaces, coordinate breaks, and possibly others.

@LucVV
Copy link
Contributor

LucVV commented Feb 17, 2023

Happy to hear it works now! Lets hope this issue gets sorted in the future.

About the examples: Sure, if you could send a pull request, we will evaluate it!

@crnh crnh closed this as completed Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants