Solved

zos api: change surface for geometric image analysis

  • 22 September 2023
  • 13 replies
  • 139 views

Hello! Can somebody please help me figure out how to change the surface for geometric image analysis? I’d like it to default to the image surface. 

gia_run = TheSystem.Analyses.New_Analysis_SettingsFirst(
ZOSAPI.Analysis.AnalysisIDM.GeometricImageAnalysis
) # make new analysis, but don't run it
gia_settings = gia_run.GetSettings()

# I was hoping for something like the following (this doesn't work though)
gia_settings.Surface = ZOSAPI.Analysis.Settings.Surface.IAS_Surface.UseImageSurface

Thanks!

Liz

icon

Best answer by David.Nguyen 22 September 2023, 19:40

View original

13 replies

Userlevel 7
Badge +2

You’re almost there, but you have to use something like so:

gia_settings.Surface.SetSurfaceNumber(<your_surface_number>)

The Surface property returns an interface that has several methods:

  • GetSurfaceNumber ()
  • SetSurfaceNumber (int N)
  • UseImageSurface ()
  • UseObjectiveSurface ()

You can find those if you click on IAS_Surface on the left of the Surface property in the Syntax Help.

I hope this helps. Take care,

 

David

got it, thanks for your help. for anybody interested in how I ultimately did this, I’m making zemax analyze the last surface with 

last_surface_number = TheLDE.NumberOfSurfaces - 1
gia_settings = gia_run.GetSettings()
gia_settings.Surface.SetSurfaceNumber(last_surface_number) #analyze GIA on the last surface

best,

Liz 

Userlevel 7
Badge +2

That’s an excellent solution.

Sorry if I wasn’t clear when I listed the methods of IAS_Surface, but you could also try:

gia_settings.Surface.UseImageSurface()

Take care,


David

GeometricBitmapImageAnalysis have same settings or different than GeometricImageAnalysis ?

with code below have error

AttributeError: 'AS_Default' object has no attribute 'Surface'

GeoBitIA = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricBitmapImageAnalysis)
GeoBitIA_settings = GeoBitIA.GetSettings()
GeoBitIA_settings.Surface.SetSurfaceNumber(2)

what is AS_Default? how find which code words should I use?

Userlevel 7
Badge +2

@Aleksandr.Makarov

 

Every analysis has a boolean property HasAnalysisSpecificSettings. If this property is True, it means its settings are available from the ZOS-API directly. Otherwise, it means you’ll need to use a settings file or you might not even be able to access those settings. Geometric Bitamp Image Analysis returns False.

my_analysis = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricBitmapImageAnalysis)
print(my_analysis.HasAnalysisSpecificSettings)

The latter approach is similar to what you’d do in ZPL and I wrote a topic about how to modify those settings that are not otherwise accessible some time ago here. In the settings of each analysis you have the following methods to perform the same operations as in ZPL more or less:

Hopefully this is clear, let me know if you need a more detailed example.

Take care,


David

@David.Nguyen

what is best way to save GeometricBitmapImageAnalysis results as image?

I finded txt way. is here image options?

 

what is best way to save GeometricBitmapImageAnalysis results as image?

 

finded solution

PS you have strange bug on site 

 

David.Nguyen strange, but “output” field dont filled with “output” or “outputfile” commands without error

and this code make double calculations for some reason.

GeoBitIA = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricBitmapImageAnalysis)
_settings = GeoBitIA.GetSettings()
_settings.Output = '061820_Myfile.JPG'
GeoBitIA.ApplyAndWaitForCompletion()

 

Userlevel 7
Badge +2

@Aleksandr.Makarov

 

It seems I wasn’t clear with my previous answer. The settings of Geometric Bitmap Analysis are not implemented in the ZOS-API yet. Therefore, I can understand that your code above doesn’t work. Instead, this is what you need to do:

geometric_bitmap_settings_filepath = "E:/custom_geometric_bitmap_analysis_settings.CFG"

geometric_bitmap_analysis = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricBitmapImageAnalysis)
geometric_bitmap_settings = geometric_bitmap_analysis.GetSettings()
geometric_bitmap_settings.SaveTo(geometric_bitmap_settings_filepath)
geometric_bitmap_settings.ModifySettings(geometric_bitmap_settings_filepath, "GBM_OUTPUT", "061820_Myfile.JPG")
geometric_bitmap_settings.LoadFrom(geometric_bitmap_settings_filepath)

geometric_bitmap_analysis.ApplyAndWaitForCompletion()

The ModifySettings method in the ZOS-API is similar to its ZPL counterpart MODIFYSETTINGS. It takes a string code (in this case GBM_OUTPUT) to modify a particular setting of an analysis inside the *.CFG file associated to it. The list of string codes can be found in the ZPL Help section of MODIFYSETTINGS.

Note that with this way of modifying the settings, you need to create the *.CFG file with SaveTo. This is similar to pressing the Save button at the bottom-right of your analysis settings.

I hope this is clearer. In the future, I believe ANSYS wants to have all the settings implemented in the ZOS-API but in the meantime we have to use this method.

Take care,

 

David

@David.Nguyen how I can customize folder where will be saved image?
I finded changing folder option(which for some reason not work for me), but not sure if zemax can understand where find “input image” for this analysis, if I change default folder to different in cycle  

 

Userlevel 7
Badge +2

@Aleksandr.Makarov 

 

Can’t you just move the data with Python?

https://stackoverflow.com/questions/8858008/how-do-i-move-a-file-in-python

I understand it would be nice if the data was saved at the right location from the git-go but on the flip side, the method you are referring to might add some overhead in a loop (but I haven’t tested it).

Take care,

 

David

@David.Nguyen why with this code, zemax make 2 calculations of same analysis? I have presaved .CFG file.

it work, but consume x2 time.

 

TheSystemData.Wavelengths.GetWavelength(2).Wavelength = wave_um

geometric_bitmap_analysis = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricBitmapImageAnalysis)
geometric_bitmap_settings = geometric_bitmap_analysis.GetSettings()

geometric_bitmap_settings.ModifySettings(geometric_bitmap_settings_filepath, "GBM_OUTPUT", file_name)
geometric_bitmap_settings.LoadFrom(geometric_bitmap_settings_filepath)

geometric_bitmap_analysis.ApplyAndWaitForCompletion()

 

 
Userlevel 7
Badge +2

@Aleksandr.Makarov 

 

Could you please create a new topic for this question? I feel it departs from the original topic here. Also, could you clarify in comparison to what you notice the 2x increase in time?

Take care,

 

David

Reply