ZMXReader

class raytracing.ZMXReader(filepath)

Bases: object

Zemax file (ZMX) reader for compound lenses. The reader is not complete, but it can return a MatrixGroup that will behave like a compound lens with the spherical interfaces and spacing between elements.

This only works with ZMX files, not ZMF files. The ZMX files are text-based and the ZMF files are binary without documentation.

It is not particularly robust: many parameters are currently ignored and it could fail for files not from Thorlabs or Edmund (the only files tested).

designWavelengths()

Obtain the design wavelength(s) from the file. Thorlabs appears to leave many useless wavelengths (0.55 µm) so we remove them.

determineEncoding(filepath)

Zemax files can be in UTF-16 (e.g., Edmund Optics) We try to open it as UTF-16, we will get an error if it cannot.

lensSurfaces()

Make sense of surfaceInfo from the Zemax file to figure out what makes up a lens.

This will not be particularly robust: it assumes it is a compound lens but that is sufficient for now.

Returns:lensSurfaces
Return type:List of Surface elements that make up the lens.
matrixGroup()

Build and return a raytracing MatrixGroup with the interfaces and spacing as prescribed.

Returns:group – The created group that acts like a lens.
Return type:MatrixGroup
prescription()

A text-based prescription, mostly for information purposes.

Returns:prescription – A prescription in text-based form
Return type:multi-line string
rawSurfaceInfo(index)

Extract the raw information for surfaces from the file. All SURF elements from the file are extracted in order. No analysis is performed: making sense of the information in the context of a lens is the job of surfaceInfo.

surfaceInfo(index)

Make sense of rawSurfaceInfo from the Zemax file to put it together into a Surface-namedtuple that makes more sense.

  1. We figure out the material and replace it with Raytracing Material subclass.
  2. We convert CURV into a radius.
  3. We use DIAM as the diameter of the element. For some reason DIAM is half the diameter.
  4. The distance to the next interface is read as well.
Returns:
Return type:A Surface Named-tuple.
surfaces()

List of all surface elements from the Zemax file.

Returns:
Return type:List of Surfaces
value(key, index=0)

Convenience function to access the information in the file with the Zemax 4-letter parameters.

If an element has several items, element [index] is returned, defaults to zero.

Methods

__init__(filepath) Initialize self.
designWavelengths() Obtain the design wavelength(s) from the file.
determineEncoding(filepath) Zemax files can be in UTF-16 (e.g., Edmund Optics) We try to open it as UTF-16, we will get an error if it cannot.
lensSurfaces() Make sense of surfaceInfo from the Zemax file to figure out what makes up a lens.
matrixGroup() Build and return a raytracing MatrixGroup with the interfaces and spacing as prescribed.
prescription() A text-based prescription, mostly for information purposes.
rawSurfaceInfo(index) Extract the raw information for surfaces from the file.
surfaceInfo(index) Make sense of rawSurfaceInfo from the Zemax file to put it together into a Surface-namedtuple that makes more sense.
surfaces() List of all surface elements from the Zemax file.
value(key[, index]) Convenience function to access the information in the file with the Zemax 4-letter parameters.

Inherited Methods