Solved

PPG example not working

  • 28 June 2022
  • 5 replies
  • 115 views

I am totally new to OpticStudio, and I am trying to follow the PPG example to get started. However I am encountering this error when try to run the script:
Traceback (most recent call last):
  File ".\PPGsimulation.py", line 230, in <module>
    volPhysData.ModelSettings._S_DLLDefinedScattering.MeanPath = meanPath
AttributeError: 'NoneType' object has no attribute 'MeanPath'

I am experienced in Python, but don’t know the inside of the API, so it’s difficult for me to debug. I would appreciate if you can give me a pointer.


OpticStudio Pro Ver 22.2
Python 3.8 (Conda environment)
Windows 10 (virtual machine, fresh install)

icon

Best answer by Csilla Timar-Fulep 30 June 2022, 12:21

View original

5 replies

Userlevel 5
Badge +2

Hi Hongfeng,

Thanks for your post here on the Community Forums!
I am sorry to hear that you have problems running the PPG application example.

The AttributeError: 'NoneType' object has no attribute ' ' type of error usually appears if there is one tool already open, and you are trying to open a second one without closing the previous one. In OpticStudio, and also in the ZOS-API, only one tool can be open at a time. You can workaround this issue by closing the current tool, as suggested in the thread below:
What is this error "Attribute error: object has no attribute…" in the ZOS-API? | Zemax Community

Further troubleshooting steps for Attribute Errors, detailed discussions about how to interact with OpticStudio from the API, and the differences between using Python via COM or .NET connection can be found here:
ZOS-API Python: How to deal with AttributeError and apply the correct enumeration | Zemax Community

Specifically for the PPG example, could you please double-check the path of the file being opened by Python? It should be local and a .ZMX file (not only the .ZAR included in the article).

Finally, could you please try and run one of the sample codes we have in OpticStudio (help>ZOS-API Syntax Help>Examples>Example 01 - Python) to check if it is working out of the box for you? This is to verify that the connection between OpticStudio and the Python API works as expected.

If the problem still persists, please contact Zemax Support directly at support@zemax.com, so that we can provide targeted help for your problem.

Best,
Csilla

Thanks for the reply. 
I first followed the suggestion and added these two lines:

if TheSystem.Tools.CurrentTool is not None:
TheSystem.Tools.CurrentTool.Close()

But that didn’t help, error was the same. Then I reopened the downloaded .zar file with Optic Studio, which I believe extracts and overwrites the .zmx file, After exiting the Optic Studio I ran the script again, it started working! So I don’t know exactly what caused the problem, but I am glad it’s running now.

Again, thanks a lot for the help. I am sure I will need that gain soon :)

Userlevel 5
Badge +2

Hi again @Hongfeng ,

Thanks for sharing your findings and solution here.

Based on your description, it seems that maybe something was overwritten in the .ZMX file, and that caused the error in the ZOS-API script.

Should you have any further questions, please ask.

Best,
Csilla

Csilla,

Now I have several beginner questions about the simulation:

  1. the relative blood concentration in the script changes from 1 to 2 in each cycle, so this means a perfusion index of 100%, correct? Is this realistic?
  2. The output waveform varies a lot from one cycle to another, is this randomness caused mainly by scattering? How can I make it closer to real world waveform which is more regular between cycles?
  3. How critical is to have a RSMX source model? Right now I am just using a simple Source Rectangle, is the impact more on the near field or far field, considering I am trying to evaluate the effect of distance between LED and skin?

Thanks!

Hongfeng

Userlevel 5
Badge +2

Hi Hongfeng,

Regarding your first question, your understanding is correct, in our model the maximum blood content is twice the minimum. Published papers report a wide range of data, so it would be quite hard to set a best general value. This model was built for demonstration purposes, so we used this value as this was within the region, and it clearly showed the intended effect. If you have more accurate measurement data for a specific use group or application, you may refine the model using that.

Regarding the second question about the statistical noise in the results, yes, bulk scattering inside the media plays an important role in it. In order to try to achieve a better signal to noise ratio in the simulation results, you may try to increase the number of analysis rays. This article gives a nice explanation about statistical noise:
Detectors used in illumination design – Knowledgebase (zemax.com)
 

As for the third question about the RSMX source model, we used that model because it gives the most realistic representation of complex sources. If you are in the early stages of your design process, or if you don’t have access to your desired RSMX source model, you can try to use different source types and see how it affects the results. In case of using a Source Rectangle as you mentioned, you might also want to try using Sobol sampling instead of Random to decrease the statistical noise by using a pseudo-random set of rays instead of truly random ones. Unfortunately Sobol sampling was not available in our case using the Source File generated from the RSMX source model. This topic is discussed in detail in the following knowledgbase article:
Understanding Sobol sampling – Knowledgebase (zemax.com)

You may find further references about biological tissue modeling here:
Henyey-Greenstein bulk scatter model | Zemax Community
Zemax Article | Zemax Community

 

Best,
Csilla

Reply