Skip to main content

A Python package used to communicate with Zemax OpticStudio through the API

Project description

ZOSPy

About

Wrapper around the Zemax OpticStudio API that provides a more pythonic and intuitive way to interact with the ZOS-API through python using a .NET connection. It also takes care of initiating the connection.

Waranty 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 GNU General Public License Version 3.

Installing

ZOSPy is available on PyPi

pip install zospy

Dependencies

Python packages

  • Python for .NET (tested with version 2.5.2)

    Warning: (Oktober 2022) Some functions of the ZOS-API seem fail with the newest available version of Pythonnet (version 3.0.0.post1), resulting in the following error: "since Python.NET 3.0 int can not be converted to Enum implicitly.". Therefore, the required version of pythonnet has been set to version 2.5.2 as this seems to work fine. Upon running into similar errors, please check the installed pythonnet version. We are working on a solution for this problem.

  • pandas

  • NumPy

Software

Referencing

When publishing results obtained with this package, please cite the paper in which the package was first used:
van Vught L, Que I, Luyten GPM and Beenakker JWM. Effect of anatomical differences and intraocular lens design on Negative Dysphotopsia. JCRS: Sep 06, 2022. [doi: 10.1097/j.jcrs.0000000000001054 ] [JCRS]

If a direct reference of the package is also required, reference it using the following DOI:
DOI

Basic usage

Initiating connection

The connection as extension to running software OpticStudio is initiated as:

import zospy as zp
zos = zp.ZOS()
zos.wakeup()
zos.connect_as_extension(0)
oss = zos.get_primary_system()

Make sure that the OpticStudio software is setup to be connected to as extension through the API. Alternatively, a standalone OpticStudio application can be launched by changing the last two lines to:

zos.create_new_application()
oss = zos.get_primary_system()

Performing analyses

Implemented analyses are are available though zp.analyses. The available analyses are grouped in files that correspond to the analysis groups in OpticStudio (e.g. zp.analyses.mtfand zp.analyses.wavefront). Every analysis requires the OptiStudioSystem oss as first parameter.

Note: Up to version 0.6.0, some analyses where directly available through the OpticStudioSystem (oss) class. This has been changed as the namespace became cluttered.

Examples

from zp.analyses.mtf import fft_through_focus_mtf
mtf = fft_through_focus_mtf(oss, sampling='64x64', deltafocus=0.1, oncomplete='Close')
from zp.analyses.reports import cardinal_points
cp = cardinal_points(oss, surf1=3, surf2=4, oncomplete='Release')

A full description of the available function parameters is provided in the docstrings.

Constants

After initiating the connection, all api constants are available through zp.constants (e.g. zp.constants.Editors.LDE.SurfaceType). Note that that are only available after `zos.wakeup() is called as defined under Initiating connection.

Convenient functions

Some conventiant functions are available through zp.functions, e.g. to change a surface to a standard stuface:

newsurf = oss.LDE.InsertNewSurfaceAt(0)
zp.functions.lde.surface_change_type(newsurf, 'Standard')

Logging

Some basic logging is implemented through the standard python logging module (but still under development). The following implementation examples assume that import logging is executed.

  1. To enable logging output from all ZOSPy and other modules using logging.basicConfig:
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    
  2. To enable logging output from all ZOSPy and other modules using a root logger:
    fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    sh = logging.StreamHandler()
    sh.setFormatter(fmt)
    sh.setLevel(logging.DEBUG)
    
    logger = logging.getLogger()
    logger.addHandler(sh)
    
  3. To enable logging output from only ZOSPy
    logging.getLogger('zospy').addHandler(logging.StreamHandler())
    logging.getLogger('zospy').setLevel(logging.INFO)
    

Contact

Feel free to contact us for any inquiries:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zospy-0.6.1.tar.gz (39.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zospy-0.6.1-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file zospy-0.6.1.tar.gz.

File metadata

  • Download URL: zospy-0.6.1.tar.gz
  • Upload date:
  • Size: 39.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for zospy-0.6.1.tar.gz
Algorithm Hash digest
SHA256 22fc99ff6a3438af8fd46991133a6227d9a45b29bafb06e8f5d68d8bd434d5b9
MD5 57cb3b1c0f3c3424b78f37e5e9bb227a
BLAKE2b-256 2ff45c4c4ad3662c08eb1a523c1cde7e0307b0a48c797d5129ba251722bc1648

See more details on using hashes here.

File details

Details for the file zospy-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: zospy-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for zospy-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aba4965a219374f818ecf0387f5d6ec30c1b713ea7b1488699711284d251360f
MD5 8cfe0df56a747166d8fe5a9ecf5c4b53
BLAKE2b-256 51d61dab798b7c01351a770b03d4d2045de8c4f0a40e38ca8aa669090c9c45ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page