A Python package used to communicate with Zemax OpticStudio through the API
Project description
ZOSPy
About
Wrapper around the Ansys OpticStudio API that provides a more intuitive way to interact with the ZOS-API through Python using a .NET connection, as described in this Journal of Open Source Software paper. It thereby allows you to do more optics modelling with less coding.
In addition to full access to all the OpticStudio fucntions through the ZOS-API, ZOSPy provides the following features:
- Wrapper functions for several OpticStudio analyses in
zospy.analyses
; - Easy access to solvers in
zospy.solvers
; - Easy access to all API constants in
zospy.constants
; - Autocomplete for all ZOS-API endpoints and constants;
- Solves common problems related to Python.NET 3 and interaction with the ZOS-API.
Installing
ZOSPy is available on PyPi
pip install zospy
And through conda:
conda install conda-forge::zospy
Example
Create and draw a simple optical system consisting of a single lens:
import matplotlib.pyplot as plt
import zospy as zp
zos = zp.ZOS()
oss = zos.connect()
# Create a new, empty system
oss.new()
# Set aperture and wavelength
oss.SystemData.Aperture.ApertureType = zp.constants.SystemData.ZemaxApertureType.FloatByStopSize
oss.SystemData.Wavelengths.GetWavelength(1).Wavelength = 0.543 # in μm
# Set the object at infinity
surface_object = oss.LDE.GetSurfaceAt(0)
surface_object.Thickness = float("inf")
# Add a dummy surface for visualization purposes
input_beam = oss.LDE.InsertNewSurfaceAt(1)
input_beam.Comment = "input beam"
input_beam.Thickness = 10
# Use a stop diameter of 4 mm
surface_stop = oss.LDE.GetSurfaceAt(2)
surface_stop.SemiDiameter = 2
# Add a lens with n = 1.5
lens_front = oss.LDE.InsertNewSurfaceAt(3)
lens_front.Comment = "lens front"
lens_front.Radius = 20
lens_front.Thickness = 1
zp.solvers.material_model(lens_front.MaterialCell, refractive_index=1.5)
lens_back = oss.LDE.InsertNewSurfaceAt(4)
lens_back.Comment = "lens back"
lens_back.Radius = -20
lens_back.Thickness = 19.792 # System is in focus
# Show the system in the 3D viewer
draw_3d = zp.analyses.systemviewers.Viewer3D(surface_line_thickness="Thick", rays_line_thickness="Thick").run(oss)
plt.imshow(draw_3d.Data)
plt.axis("off")
plt.show()
Please refer to the documentation for more information on how to use ZOSPy. More elaborate examples can be found in the example gallery.
Warranty and liability
The code is provided as is, without any warranty. It is solely intended for research purposes. No warranty is given and no rights can be derived from it, as is also stated in the MIT license.
Dependencies
ZOSPy officially supports Python 3.9 - 3.13. It may work with older Python versions, but support is not provided for these versions. Furthermore, a working installation of Ansys Zemax OpticStudio is required.
Compatibility
See the documentation for the most up-to-date compatibility information.
Referencing
When publishing results obtained with this package, please cite our paper in the Journal of Open Source Software:
Vught, L. van, Haasjes, C. & Beenakker, J.W.M. (2024). ZOSPy: Optical ray tracing in Python through OpticStudio. Journal of Open Source Software, 9(96), 5756. https://doi.org/10.21105/joss.05756
Contributing
Please read our contribution guidelines prior to opening a Pull Request.
Contact
Feel free to contact us via e-mail at zospy@mreye.nl for any inquiries, or visit mreye.nl to discover our research.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file zospy-2.1.2.tar.gz
.
File metadata
- Download URL: zospy-2.1.2.tar.gz
- Upload date:
- Size: 46.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
10c6a0d5861c54714b481b6c96f53f9ad159c4884d6b83ee9d912e746e96167c
|
|
MD5 |
a98220a96741ccf1a4c43a30bb37826a
|
|
BLAKE2b-256 |
89953504ad6232c11051b17e31d0dacc2c6369b0bad7f2206e5491d17248fc8c
|
Provenance
The following attestation bundles were made for zospy-2.1.2.tar.gz
:
Publisher:
python-publish.yml
on MREYE-LUMC/ZOSPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
zospy-2.1.2.tar.gz
-
Subject digest:
10c6a0d5861c54714b481b6c96f53f9ad159c4884d6b83ee9d912e746e96167c
- Sigstore transparency entry: 241644377
- Sigstore integration time:
-
Permalink:
MREYE-LUMC/ZOSPy@f3081b8a3e496f1e537201f3c3f1d31343f6367c
-
Branch / Tag:
refs/tags/v2.1.2
- Owner: https://github.com/MREYE-LUMC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
python-publish.yml@f3081b8a3e496f1e537201f3c3f1d31343f6367c
-
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file zospy-2.1.2-py3-none-any.whl
.
File metadata
- Download URL: zospy-2.1.2-py3-none-any.whl
- Upload date:
- Size: 314.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
83271aabf873161639ebea64c8de662becf7ef349bb3ea08e5dfd897acc3f20a
|
|
MD5 |
ada475993036a6d5a3fa1d65ed6e7a2d
|
|
BLAKE2b-256 |
6d5799946f594c0814fdee087086c2b853becc205ec1802d742a2032422e2c7f
|
Provenance
The following attestation bundles were made for zospy-2.1.2-py3-none-any.whl
:
Publisher:
python-publish.yml
on MREYE-LUMC/ZOSPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
zospy-2.1.2-py3-none-any.whl
-
Subject digest:
83271aabf873161639ebea64c8de662becf7ef349bb3ea08e5dfd897acc3f20a
- Sigstore transparency entry: 241644395
- Sigstore integration time:
-
Permalink:
MREYE-LUMC/ZOSPy@f3081b8a3e496f1e537201f3c3f1d31343f6367c
-
Branch / Tag:
refs/tags/v2.1.2
- Owner: https://github.com/MREYE-LUMC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
python-publish.yml@f3081b8a3e496f1e537201f3c3f1d31343f6367c
-
Trigger Event:
workflow_dispatch
-
Statement type: