Solved

Change wavelength in Geometric Image Analysis

  • 21 March 2023
  • 4 replies
  • 166 views

Hi All,

I’m trying to automate some Geometric Image Analysis tasks but am struggling to change the wavelength in geometric image analysis.

python 3.10.9

Optics Studio 23.1

 

I’ve set up the image analysis I want in the project (Cross X, Field size, image size, pixels etc). I’m trying now to loop over wavelengths and save the results. My problem is I can’t figure out how to change the wavelength number within ZOS-API. As far as I can tell the IMA keywords don’t have Wavelength. Thanks for any help!

from the help of ModifySettings keywords

 

Geometric Image Analysis

IMA_FIELD: The field size.

IMA_IMAGESIZE: The image size.

IMA_IMANAME: The image file name.

IMA_KRAYS: The number of rays x 1000.

IMA_NA: The numerical aperture.

IMA_OUTNAME: The output file name.

IMA_SURFACE: The surface number.

IMA_PIXELS: The number of pixels.

 

example code:

geo = TheSystem.Analyses.New_GeometricImageAnalysis()
geo_set = geo.GetSettings()
cfgfile = os.path.join(pth,'geo_an_sett.cfg')
geo_set.SaveTo(cfgfile)

geo_set.ModifySettings(cfgfile,'IMA_Wavelength'?,'1')  # I can’t find an appropriate keyword to give here

geo_set.LoadFrom(cfgfile)
geo.ApplyAndWaitForCompletion()
res = geo.GetResults()
res.GetTextFile(os.path.join(pth,'textfile.txt'))

r1 = np.loadtxt('analysis/textfile.txt',skiprows=18)[:,1]

 

nb.

geo_set.Wavelength gives an attribute error.

In [33]: geo_set.Wavelength.SetWavelengthNumber(1)

Traceback (most recent call last):

  Cell In[33], line 1
    geo_set.Wavelength.SetWavelengthNumber(1)

AttributeError: 'IAS_' object has no attribute 'Wavelength'

icon

Best answer by David.Nguyen 21 March 2023, 12:26

View original

4 replies

Userlevel 7
Badge +2

Dear Adam,

 

Whenever you try a new analysis in the ZOS-API, I strongly suggest evaluating the property HasAnalysisSpecificSettings. If True, this property tells you that the settings have been fully implemented in the ZOS-API and you don’t need to use the ModifySettings method.

In the case of Geometric Image Analysis, you can type:

geo = TheSystem.Analyses.New_GeometricImageAnalysis()
print(geo.HasAnalysisSpecificSettings)

And it should print True.

It is a bit tricky to find in the Syntax Help (you need to click on IAS_ in the analysis interface next to GetSettings() and then find the square box which points to the Geometric Image Analysis), but these are the specific settings of Geometric Image Analysis:

 The way you use these settings are as follow:

geo = TheSystem.Analyses.New_GeometricImageAnalysis()

# Geometric Image Analysis Settings
geo_settings = geo.GetSettings()

# Wavelength
geo_settings.Wavelength.SetWavelengthNumber(1)

# Field
geo_settings.Field.SetFieldNumber(1)

# Field size
geo_settings.FieldSize = 1.0

# Apply settings and run analysis
geo.ApplyAndWaitForCompletion()

I hope this helps. Take care,

 

David

Hi David,

Thanks a lot for your reply. I saw that it has the specific settings flag True but couldn’t find the methods in the documentation---until now!

Does your code run for you?

geo_settings does not show the official methods. I tried running your code and get an AttributeError

 

# Geometric Image Analysis
geo = TheSystem.Analyses.New_GeometricImageAnalysis()

# Geometric Image Analysis Settings
geo_settings = geo.GetSettings()

# Wavelength
geo_settings.Wavelength.SetWavelengthNumber(1)

 

 

Traceback (most recent call last):

  Cell In[15], line 1
    geo_settings.Wavelength.SetWavelengthNumber(1)

AttributeError: 'IAS_' object has no attribute 'Wavelength'

 

The documentation says it’s implemented, but the behavior I’m seeing is as if it isn’t…

Thanks for any insight

Userlevel 7
Badge +2

Yes, the piece of code I gave you run on my machine (Python 3.8.13, Pythonnet 2.5.2).

What version of Pythonnet are you using? It should be 2.5.2 or older. If you find that you are running Pythonnet 3.0, please try 2.5.2. There have been issues with analyses and pythonnet > 2.5.2. Also, I don’t know if Pythonnet 2.5.2 is compatible with Python 3.10.9, you should check that out. Have a look at that perhaps:

Take care,

 

David

Brilliant! pythonnet version solved it.

Thanks for your help!

Reply