Skip to main content

I want to perform a sensitivity analysis on an optical system via ZOS API (Matlab in particular). The analysis concern the perturbation to lenses’ parameters due to manufacturing including glass data.

How can I change the refractive index?

If I try to use 

TheLDE.GetSurfaceAt(My_Surface).Material

I can’t modify the index and abbe values.

Thanks for help

Hi Nicolo,

 

If you want control over the refractive index and Abbe number, I suggest you use a Solve. There are two valid Solve types you can use. Either you can use a Model glass (Model Solve Type), which exposes the Index Nd, Abbe Vd, and dPgF. Basically, you define your material as a Model glass and you change it whenever you need to. Or you can use an Offset solve. In this case, you can give your surface a material, say N-BK7, and the Offset solve exposes a Nd Offset and a Vd Offset. The resulting material will be N-BK7 plus the offset (I hope it makes sense).

 

For tolerancing, I would use the Offset Solve, and here’s a small example:

 

MySurface = TheSystem.LDE.GetSurfaceAt(1)


MyMaterialCell = MySurface.MaterialCell


MyOffsetSolve = MyMaterialCell.CreateSolveType(ZOSAPI.Editors.SolveType.MaterialOffset)


MyOffsetSolve.NdOffset = 0.001
MyOffsetSolve.VdOffset = 0.05


MyMaterialCell.SetSolveData(MyOffsetSolve)

 

Hopefully the code is self-explanatory, let me know otherwise. Whatever the material of Surface 1 is, this code will offset the refractive index by 0.001 and the Abbe number by 0.05.

Take care,

 

David


Hi! Thank you for the answer and the reply. I have implemented that exact reply but the index just won’t change. It gives me the same value of Nd before and after doing the offset change.

 

I should also say that if I open the ZOS model, it takes sometime to implement this change. I have to refresh and this doesn’t happen with any other changes I do in the LDE.

 

surf = TheSystem.LDE.GetSurfaceAt(3)

cristal = TheSystem.LDE.GetGlass(3)

print(cristal)

MatCell = surf.MaterialCell

OffsetSolve = MatCell.CreateSolveType(ZOSAPI.Editors.SolveType.MaterialOffset)

OffsetSolve.NdOffset = 0.01

MatCell.SetSolveData(OffsetSolve)

cristal = TheSystem.LDE.GetGlass(3)

print(cristal)

 

I am triying to see the effect on RMS, which I compute with a MFE and there is no effect either (the prints are just for seeing if I am able to affect the Nd)

Do you know why this could be? Thank you!

 

 

@alex_gomez 

 

The issue has to do with pythonnet as documented here:

https://community.zemax.com/zos%2Dapi%2D12/pythonnet%2D3%2Dx%2Dis%2Dfixed%2D3945

For you, simply use this line of code with the additional __implementation__:

MyOffsetSolve = MyMaterialCell.CreateSolveType(ZOSAPI.Editors.SolveType.MaterialOffset).__implementation__

I hope this helps.

Take care,

 

David


Thanks a lot @David.Nguyen !! That was really helpful

 

I also read the thread you sent. To be honest I didn’t really understood everything but I think I kind of understand. It’s quite difficult for me to graps these things (I’m sure you realized seeing all the prints in my code XD) but I guess this is step by step.

 

By the way, do you know any book/course with examples that takes you by the hand to really understand all that stuff? The basic object-oriented programming seems easy but once you start to delve into it the are many things that I don’t get, honestly

 

Thanks again. Cheers!

Alex


@alex_gomez

 

Glad I could help somehow. This sort of compatibility issues is difficult to grasp for me as well. Fortunately, we have @MichaelH in the community who has an extensive knowledge of the API and Python. As a side note, a group of independent community members have written a wrapper for the ZOSAPI, which addresses some of those issues, such as the pythonnet issue:

However, if you begin with the ZOSAPI and Python, perhaps it is worth spending some time not using ZOSPy. The main reason for this is to learn how to find what you need in the Programming..ZOS-API Help..ZOS-API Syntax Help, which is an important source of information that can be tricky to navigate. One trick I can suggest: if you want to program something, think about how you would manually do it through the user interface of OpticStudio. Because it is very likely you have to follow the same kind of reasoning in the ZOSAPI. I find that it is only after you have a basic understanding of the ZOSAPI that you can really leverage ZOSPy.

I don’t have a particular book/course to recommend. I read Automate the Boring Stuff with Python but this is very basic and doesn’t go much into Python modules. I subscribed to DataCamp for a while, without having a project of my own and it didn’t stick. For me, I need to have a specific task to address, then I search for answers on the internet, try to aim for Stack Overflow or Stack Exchange (somehow in my Google those don’t appear at the top anymore...). Lately, I’ve used ChatGPT, and GitHub Copilot to help me, and while you have to remain cautious with those tools, they’ve been actually quite helpful for the general stuff. Finally, the people from ZOSPy had a wholesome discussion about how they got into programming:

https://github.com/MREYE-LUMC/ZOSPy/discussions/50

I hope this helps.

Take care,


David


@David.Nguyen 

Thanks again David! I absolutely understand what you mean and it’s been mi idea all along. However. time is really the issue here every time, I’m afraid. I am professor at the university and very rarely I get the time to learn anything for good, it’s always finding fixes for things and passing to the next task. Now we are in the middle of a project and I just have time to “get things running” fast, because on the side there are many things. It’s a bit difficult to focus. I will look into the resources you sayin any case, and try to get more into the guts, maybe when the lectures finish in May

Cheers!

Alex

 


Reply