Code Monkey home page Code Monkey logo

zospy's People

Contributors

andibarg avatar crnh avatar dependabot[bot] avatar jwmbeenakker avatar lucvv avatar noahrbn avatar omnistic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

zospy's Issues

JOSS paper content

This issue is part of my JOSS review, openjournals/joss-reviews#5756

When I read your paper, the main on-its-face takeaway is that using the native or as-provided interface to Zemax leaves room for improvement, and the principal contribution of ZOSPy is a better/easier to use one.

For example, quoting

With ZOSPy, we aim to provide an accessible interface to the OpticStudio API, enabling the user to focus on optical modelling instead of complex coding. Furthermore, we hope that the easy integration of the ray tracing workflow from optical design to analyses into Python scripts or Jupyter Notebooks facilitates open science.

By placing about a page of Python code as the first "what is it and how to use it" for the paper, that particular example in its whole is given quite a bit of significance. In that example, the lens data manager is filled in programmatically, with

input_beam = oss.LDE.InsertNewSurfaceAt(1)
input_beam.Thickness = 10
# Make a 10 mm thick lens with a radius of curvature of 30mm
# and material type BK10
front_surface = oss.LDE.GetSurfaceAt(2)
front_surface.Radius = 30
front_surface.Thickness = 10
front_surface.SemiDiameter = 15
front_surface.Material = "BK10"
back_surface = oss.LDE.InsertNewSurfaceAt(3)
back_surface.Radius = -30

This would be equivalent to, for example with Code V MacroPlus

INS S1
THI S2 10
INS S2
RDY S2 30
THI S2 10
GLA S2 BK10
INS S3
RDY S3 -30

So, a takeaway that one is inclined to make is that the prescription is stored in python form. The paper also criticizes the .zmx file format as proprietary, which re-inforces this idea. It is not clear that there is an alternative offered by ZOSPy to this; a python script creating a prescription in a non-uniform way is not really a "file format." So while the ZOSPy non-alternative is open source and cannot be proprietary by its nature, I don't think a solution to this problem has been presented, don't think it should be in the paper if a remedy to the problem is not present.

The paper also talks about "small number of" optical systems for the world without ZOSPy, which I find to be a strange point in two ways:

  1. non-survey papers would concern themselves only with a small number of systems anyway (the ones being studied)

  2. an irregular form of prescription entry would seem in conflict with analyzing large numbers of systems in an automated way


Claims are also made to ZOSPy being pythonic, but it seems most or all of the API is in CamelCase, which python only uses for class names, other variables being in snake_case. So, for example, oss.LDE.insert_new_surface_at(3), instead of the above.


Figure 2 is also not taken from the cited papers (I looked, having a copyright related concern about that), and is probably not generated easily using only ZOSPy? Neither the paper nor the docs (README, related #35 ) show how to extract ray path data with ZOSPy. I think the documentation should either cover how to generate similar graphics, or the paper be made more explicit about what portion of Fig 2 comes from ZOSPy, and what portion is made with other software.



Please do not misunderstand, I think something better than what Ansys provides directly is worth creating and worth publishing. But I think that the software should stand on its own merits, and the criticisms made of alternatives in the paper should be directly addressed (remedied) by ZOSPy

Saving after connect_as_extension

As noted on the Zemax forum, an error is currently raised when trying to use OpticStudioSystem.Save after connecting as extension. In this specific case, the private property _OpenFile is kept as None.

I can see two ways to fix this:

  1. Set the _OpenFile property directly after connecting as extension
  2. Dropping the 'OpenFile' attribute all together and directly checking OpticStudioSystem.SystemFile. As this is a private property, I would not directly consider it a breaking change.

It might be good to address this when addressing #34

Analyses Interface Broken

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()

PSF data grid does not seem to be centered correctly

Problem

While using the Huygens PSF analysis for a rotationally symmetric system, I noticed that the maximum value of the PSF is not at (0,0). This is in contrast to the output directly taken from OpticStudio. I provided a simplified example below to reproduce this. And in case you are wondering, it seems to have nothing to do with the "use centroid" option.

As far as I can see, the problem originates from the unpack_datagrid function in zputils.py. In row 104, we have:

df = pd.DataFrame(data=values, index=rows[::-1], columns=columns)

I inverted the array rows, which gave me the correct results:

df = pd.DataFrame(data=values, index=rows, columns=columns)

What is the reason for inverting rows in the first place? Do you see any issues with my solution? Is unpack_datagrid used by any other analysis that should be checked?

What version of ZOSPy are you running?

1.1.1

What version of OpticStudio are you running?

23.2.1

Which operating system do you use?

Windows 10

In which environment do you use ZOSPy?

  • Plain Pythons scripts (not in Spyder)
  • Jupyter notebooks
  • Spyder

In which connection modes does the problem occur?

  • Extension mode
  • Standalone mode

Example code

import os
import numpy as np
import zospy as zp
import matplotlib.pyplot as plt

# Load Zemax file
zos = zp.ZOS()
oss = zos.create_new_application(True)
oss.load(os.path.join(zos.Application.SamplesDir,
                      'Sequential',
                      'Objectives',
                      'Double Gauss 28 degree field.zmx')

# Get Huygens PSF
psfdata = zp.analyses.psf.huygens_psf(oss).Data

# Get center and max value
print(psfdata[0][0])
print(np.max(psfdata))

# Plot
plt.pcolormesh(psfdata.keys(),psfdata[0].keys(),psfdata)
plt.show()

Output

No response

Additional information

No response

LoadNewLensSeq() returns a ZemaxUI.ZOSAPI.ZemaxSystem instead of zospy.zpcore.OpticStudioSystem

Problem

As a result of searching with the LensCatalog tool, it is possible to retrieve an ILensCatalogLens. Then, one can retrieve an IOpticalSystem from the method LoadNewLensSeq() or LoadNewLensNonSeq(). Currently this IOpticalSystem is a ZemaxUI.ZOSAPI.ZemaxSystem, which is the default type from the ZOSAPI. In comparison, the primary OpticalSystem in ZOSPy is a zospy.zpcore.OpticStudioSystem object. I think it would be more consistant if the return of LoadNewLensSeq() would also be a zospy.zpcore.OpticStudioSystem object. I hope this makes sense, and thank you for your great work.

What version of ZOSPy are you running?

1.1.1

What version of OpticStudio are you running?

R2.00

Which operating system do you use?

Windows 10 Pro

In which environment do you use ZOSPy?

  • Plain Pythons scripts (not in Spyder)
  • Jupyter notebooks
  • Spyder

In which connection modes does the problem occur?

  • Extension mode
  • Standalone mode

Example code

import zospy as zp

zos = zp.ZOS()
zos.wakeup()
zos.connect_as_extension()
oss = zos.get_primary_system()

lensCatalog = oss.Tools.OpenLensCatalogs()
lensCatalog.RunAndWaitForCompletion()
dummySystem = lensCatalog.GetResult(0).LoadNewLensSeq()
lensCatalog.Close()

print(oss)
print(dummySystem)

Output

<zospy.zpcore.OpticStudioSystem object at 0x000002229CF74990>
ZemaxUI.ZOSAPI.ZemaxSystem






โ€‹

Additional information

No response

Deleting the `ZOS` instance doesn't (always) work

Problem

Several users of ZOSPy complained about being unable to create a new ZOS instance, even after deleting the existing instance using del zos (being unable to create a new instance when another instance exists is by design).
I looked into this and there are two main reasons for this problem:

  1. The use of an interactive Python environment like IPython or Jupyter notebooks. These environments may keep some references to variables even after deleting them, so the existing ZOS instance is not removed by the garbage collector after calling del zos.
  2. The existence of OpticStudioSystem instances. Every OpticStudioSystem contains a reference to the ZOS instance that created it. As a result, there will still be some references to this ZOS instance, and deleting zos will not result in its removal by the garbage collector. It is therefore necessary to

I am not sure if this should be considered a bug, as this is related to how Python works. Furthermore, it is not necessary to delete and recreate ZOS objects, as the same instance can be used to manage all OpticStudioSystem instances. Nevertheless, users expect to be able to delete ZOS (probably due to the OpticStudio documentation suggesting to do so) so we should at least consider adding a note about this behaviour to the documentation. It may also be possible to automatically delete all OpticStudioSystem instances when deleting zos, but this most likely involves messing with the garbage collector, which may be dangerous.

What version of ZOSPy are you running?

1.2.0

What version of OpticStudio are you running?

23R2

Which operating system do you use?

Windows 10 Enterprise

In which environment do you use ZOSPy?

  • Plain Pythons scripts (not in Spyder)
  • Jupyter notebooks
  • Spyder

In which connection modes does the problem occur?

  • Extension mode
  • Standalone mode

Example code

import logging

import zospy as zp

# Initiate logging so we can follow what ZOSPy is doing
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

zos = zp.ZOS()
oss = zos.connect(mode="extension")

del zos

# See the output below: if this doesn't print the empty set, the instance was not deleted
print(f"ZOS instances: {zp.ZOS._instances}")

Output

2024-01-11 12:46:33,917 - zospy.zpcore - DEBUG - Loading ZOS DLLs with preload set to False
2024-01-11 12:46:33,917 - zospy.api.apisupport - INFO - Obtaining Zemax Location from Windows Registry
2024-01-11 12:46:33,917 - zospy.api.apisupport - INFO - Found ZemaxFolder at XXX
2024-01-11 12:46:33,917 - zospy.api.apisupport - DEBUG - Closing registry key
2024-01-11 12:46:33,917 - zospy.api.apisupport - DEBUG - Registry key closed
2024-01-11 12:46:33,917 - zospy.api.apisupport - DEBUG - Adding reference XXX to clr
2024-01-11 12:46:33,933 - zospy.api.apisupport - DEBUG - Importing ZOSAPI_NetHelper
2024-01-11 12:46:33,935 - zospy.api.apisupport - INFO - ZOSAPI_NetHelper imported successfully
2024-01-11 12:46:33,935 - zospy.api.apisupport - INFO - Obtaining Zemax Directory from ZOSAPI_NetHelper
2024-01-11 12:46:33,946 - zospy.api.apisupport - INFO - Zemax OpticStudio found at XXX
2024-01-11 12:46:33,946 - zospy.api.apisupport - INFO - Searching and registering ZOSAPI DLLs
2024-01-11 12:46:33,946 - zospy.api.apisupport - DEBUG - ZOSAPI_Interfaces.dll found
2024-01-11 12:46:33,959 - zospy.api.apisupport - INFO - ZOSAPI_Interfaces imported to clr
2024-01-11 12:46:33,960 - zospy.api.apisupport - DEBUG - ZOSAPI.dll found
2024-01-11 12:46:33,963 - zospy.api.apisupport - INFO - ZOSAPI imported to clr
2024-01-11 12:46:33,963 - zospy.api.apisupport - DEBUG - Checking content of ZOSAPI_Interfaces.dll
2024-01-11 12:46:33,976 - zospy.api.apisupport - DEBUG - Loading ZOSAPI
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - ZOSAPI loaded
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - Loading nested namespaces
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis preloaded
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Data preloaded
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.PhysicalOptics preloaded
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.RayTracing preloaded
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings preloaded
2024-01-11 12:46:33,978 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Aberrations preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.DiffractionEfficiency preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.EncircledEnergy preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.ExtendedScene preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Fans preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Materials preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Mtf preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.NSCSurface preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Psf preloaded
2024-01-11 12:46:33,979 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RMS preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RMS.RMSField preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RMS.RMSFieldMap preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RayTracing preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Spot preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Surface preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Wavefront preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Tolerancing preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Tolerancing.QuickYield preloaded
2024-01-11 12:46:33,980 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Common preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.LDE preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.MCE preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.MFE preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.NCE preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.TDE preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Preferences preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.SystemData preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools preloaded
2024-01-11 12:46:33,981 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.FileManager preloaded
2024-01-11 12:46:33,982 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.General preloaded
2024-01-11 12:46:33,982 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.LMx preloaded
2024-01-11 12:46:33,983 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.Optimization preloaded
2024-01-11 12:46:33,983 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.RayTrace preloaded
2024-01-11 12:46:33,983 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.Tolerancing preloaded
2024-01-11 12:46:33,983 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Wizards preloaded
2024-01-11 12:46:34,145 - zospy.zpcore - DEBUG - Assigning ZOSAPI_Connection() to self.Connection
2024-01-11 12:46:34,476 - zospy.zpcore - DEBUG - ZOSAPI_Connection() already assigned self.Connection
ZOS instances: {2341316532496} <-- Not an empty set, so the instance has not been deleted
2024-01-11 12:46:35,024 - zospy.zpcore - DEBUG - Closing connections with Zemax OpticStudio

Additional information

When oss is deleted as well, the ZOS instance is correctly deleted:

import logging

import zospy as zp

# Initiate logging so we can follow what ZOSPy is doing
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

zos = zp.ZOS()
oss = zos.connect(mode="extension")

del oss
del zos

# See the output below: if this doesn't print the empty set, the instance was not deleted
print(f"ZOS instances: {zp.ZOS._instances}")

Output:

2024-01-11 12:49:02,026 - zospy.zpcore - DEBUG - Initializing ZOS instance
2024-01-11 12:49:02,027 - zospy.zpcore - INFO - ZOS instance initialized
2024-01-11 12:49:02,027 - zospy.zpcore - DEBUG - Loading ZOS DLLs with preload set to False
2024-01-11 12:49:02,027 - zospy.api.apisupport - INFO - Obtaining Zemax Location from Windows Registry
2024-01-11 12:49:02,027 - zospy.api.apisupport - INFO - Found ZemaxFolder at XXX
2024-01-11 12:49:02,027 - zospy.api.apisupport - DEBUG - Closing registry key
2024-01-11 12:49:02,027 - zospy.api.apisupport - DEBUG - Registry key closed
2024-01-11 12:49:02,027 - zospy.api.apisupport - DEBUG - Adding reference XXX to clr
2024-01-11 12:49:02,041 - zospy.api.apisupport - DEBUG - Importing ZOSAPI_NetHelper
2024-01-11 12:49:02,042 - zospy.api.apisupport - INFO - ZOSAPI_NetHelper imported successfully
2024-01-11 12:49:02,042 - zospy.api.apisupport - INFO - Obtaining Zemax Directory from ZOSAPI_NetHelper
2024-01-11 12:49:02,052 - zospy.api.apisupport - INFO - Zemax OpticStudio found at XXX
2024-01-11 12:49:02,052 - zospy.api.apisupport - INFO - Searching and registering ZOSAPI DLLs
2024-01-11 12:49:02,053 - zospy.api.apisupport - DEBUG - ZOSAPI_Interfaces.dll found
2024-01-11 12:49:02,065 - zospy.api.apisupport - INFO - ZOSAPI_Interfaces imported to clr
2024-01-11 12:49:02,066 - zospy.api.apisupport - DEBUG - ZOSAPI.dll found
2024-01-11 12:49:02,068 - zospy.api.apisupport - INFO - ZOSAPI imported to clr
2024-01-11 12:49:02,068 - zospy.api.apisupport - DEBUG - Checking content of ZOSAPI_Interfaces.dll
2024-01-11 12:49:02,081 - zospy.api.apisupport - DEBUG - Loading ZOSAPI
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - ZOSAPI loaded
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Loading nested namespaces
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis preloaded
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Data preloaded
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.PhysicalOptics preloaded
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.RayTracing preloaded
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings preloaded
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Aberrations preloaded
2024-01-11 12:49:02,083 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.DiffractionEfficiency preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.EncircledEnergy preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.ExtendedScene preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Fans preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Materials preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Mtf preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.NSCSurface preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Psf preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RMS preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RMS.RMSField preloaded
2024-01-11 12:49:02,084 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RMS.RMSFieldMap preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.RayTracing preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Spot preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Surface preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Settings.Wavefront preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Tolerancing preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Analysis.Tolerancing.QuickYield preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Common preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.LDE preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.MCE preloaded
2024-01-11 12:49:02,085 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.MFE preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.NCE preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Editors.TDE preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Preferences preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.SystemData preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.FileManager preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.General preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.LMx preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.Optimization preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.RayTrace preloaded
2024-01-11 12:49:02,086 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Tools.Tolerancing preloaded
2024-01-11 12:49:02,087 - zospy.api.apisupport - DEBUG - Nested namespace ZOSAPI.Wizards preloaded
2024-01-11 12:49:02,244 - zospy.zpcore - DEBUG - Assigning ZOSAPI_Connection() to self.Connection
2024-01-11 12:49:02,565 - zospy.zpcore - DEBUG - ZOSAPI_Connection() already assigned self.Connection
2024-01-11 12:49:02,676 - zospy.zpcore - DEBUG - Closing connections with Zemax OpticStudio
ZOS instances: set()

ValueError: Cannot have more than one active ZOS instance

I'm using OS 2023 R1.03 Premium with Python 3.10.9, Pythonnet 3.0.1

After installing ZOSPy, when I try to use:

import zospy as zp

zos = zp.ZOS()
zos.wakeup()
zos.connect_as_extension()
oss = zos.get_primary_system()

I get a

ValueError: Cannot have more than one active ZOS instance

This happens even after a fresh restart of my computer. My OS is setup with Programming..Interactive Extension (the OS boilerplate interactive extension code works for me). Is there anything I should do to clear any pre-existing connection? Thanks for your help.

locale.setlocale raising exception

Problem

cannot import ZOSPy 1.2.0 as is.
It is raising a locale.Error: unsupported locale setting

What version of ZOSPy are you running?

1.2.0

What version of OpticStudio are you running?

2023 R1.03

Which operating system do you use?

Windows 10

In which environment do you use ZOSPy?

  • Plain Pythons scripts (not in Spyder)
  • Jupyter notebooks
  • Spyder

In which connection modes does the problem occur?

  • Extension mode
  • Standalone mode

Example code

loc = locale.getlocale()
# in ZOSPy's __init__.py there is also a
# locale.setlocale(locale.LC_ALL, "") and some things happen to make ZOSPy aware of the user preferences
print(loc)
locale.setlocale(locale.LC_ALL, loc)

Output

('de_DE', 'cp1252')
Traceback (most recent call last):
  File "C:\Users\XXXXX\Documents\Python Scripts\locale-pain.py", line 11, in <module>
    locale.setlocale(locale.LC_ALL, loc)  # restore saved locale
  File "C:\Users\XXXXX\Anaconda3\lib\locale.py", line 610, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

Additional information

No response

Possible Easy Fix for Int / Enum Problem Mentioned in Readme

While running the example ZOSPy\examples\Escudero-Sanz eye model\Escudero-Sanz eye model.ipynb I get the error in Cell 11.

---------------------------------------------------------------------------
PythonException                           Traceback (most recent call last)
PythonException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value)

The above exception was the direct cause of the following exception:

ArgumentException                         Traceback (most recent call last)
ArgumentException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value) in method ZOSAPI.Editors.LDE.ISurfaceTypeSettings GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.SurfaceType) ---> Python.Runtime.PythonException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value)
   --- End of inner exception stack trace ---

The above exception was the direct cause of the following exception:

AggregateException                        Traceback (most recent call last)
AggregateException: One or more errors occurred. ---> System.ArgumentException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value) in method ZOSAPI.Editors.LDE.ISurfaceTypeSettings GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.SurfaceType) ---> Python.Runtime.PythonException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.ArgumentException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value) in method ZOSAPI.Editors.LDE.ISurfaceTypeSettings GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.SurfaceType) ---> Python.Runtime.PythonException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value)
   --- End of inner exception stack trace ---<---


The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
Cell In[11], line 18
     16 cf_surf.Comment = 'Cornea Front'
     17 # Following statement not needed but given as example
---> 18 zp.functions.lde.surface_change_type(cf_surf, int(zp.constants.Editors.LDE.SurfaceType.Standard)) 
     20 cf_surf.Radius = cf_radius
     21 cf_surf.Conic = cf_conic

File ~\Code\ZOSPy\zospy\functions\lde.py:68, in surface_change_type(surf, newtype)
     65 newtype = proc_constant(constants.Editors.LDE.SurfaceType, newtype)
     67 # Apply
---> 68 newsurftypesettings = surf.GetSurfaceTypeSettings(newtype)
     69 surf.ChangeType(newsurftypesettings)

TypeError: No method matches given arguments for ILDERow.GetSurfaceTypeSettings: (<class 'int'>)

This error can be fixed by simply skipping the call to your wrapper function. For example the Cornea Front surface can now use

# cornea front
cf_surf = oss.LDE.InsertNewSurfaceAt(n_surf)
cf_surf.Comment = 'Cornea Front'
# Following statement not needed but given as example
# zp.functions.lde.surface_change_type(cf_surf, int(zp.constants.Editors.LDE.SurfaceType.Standard))
cf_surf.ChangeType(cf_surf.GetSurfaceTypeSettings(zp.constants.Editors.LDE.SurfaceType.Standard))

Apparently the update to the new python .net interface allows the enums to be passed around without conversion to integers. At least I think this is cause of the issue. It goes along with the notification you posted in the Readme.

I do not know how or when you want to tackle fixing this problem, so submitting an issue not a pull request.

Expanded documentation

This issue is part of my JOSS review, openjournals/joss-reviews#5756

Copying verbatim, the grading criteria are:

Documentation

  • A statement of need: Do the authors clearly state what problems the software is designed to solve and who the target audience is?
  • Installation instructions: Is there a clearly-stated list of dependencies? Ideally these should be handled with an automated package management solution.
  • Example usage: Do the authors include examples of how to use the software (ideally to solve real-world analysis problems).
  • Functionality documentation: Is the core functionality of the software documented to a satisfactory level (e.g., API method documentation)?
  • Automated tests: Are there automated tests or manual steps described so that the functionality of the software can be verified?
  • Community guidelines: Are there clear guidelines for third parties wishing to 1) Contribute to the software 2) Report issues or problems with the software 3) Seek support

Most of these do exist. And the docstrings are even quite good, with the few I went looking for in the source code replete with examples! However, this is a large software package, and when a user visits its website (the Github repo is all that exists for this, as best I can tell), perhaps just 5% or something like that of it "is documented" in the README.

I think it would be a great enhancement if a documentation site was set up for your package, for example using sphinx and hosted on readthedocs. Or really whatever you like, but sphinx and the nbsphinx extension allow you to make quite delightful documentation with jupyter notebooks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.