optiland.fileio
File input/output operations for Optiland.
This package handles loading and saving Optiland’s native JSON format and importing/exporting Zemax (.zmx) and CODE V Sequential (.seq) files.
Functions
|
Load a CODE V Sequential file and return an Optic object. |
|
Load a Zemax file and return an Optic object. |
- class ZemaxToOpticConverter(zemax_data: dict[str, Any] | ZemaxDataModel)[source]
Converts a ZemaxDataModel into an Optic object.
Also implements BaseOpticReader so that the full pipeline (source resolution -> parsing -> conversion) can be triggered via
read().- Parameters:
zemax_data – A plain dict (legacy) or ZemaxDataModel containing the Zemax optical system data.
- data
The Zemax data as a plain dict.
- current_cs
Running cumulative CoordinateSystem used when processing coordinate-break surfaces.
- load_codev_file(source: str)[source]
Load a CODE V Sequential file and return an Optic object.
- Parameters:
source – The path to a local .seq file.
- Returns:
An Optic object created from the CODE V file data.
- load_obj_from_json(cls, filepath)[source]
Load an object from a JSON file.
Note that this function can be used to load any object that has a class method from_dict that can be used to create an instance of the class from a dictionary. In Optiland, this includes most core classes, such as Optic, BaseGeometry, BaseCoating, BaseMaterial, Aperture, FieldGroup, WavelengthGroup, etc.
- Parameters:
cls – The class of the object to load.
filepath – The path to the JSON file.
- Returns:
An instance of the class
- load_optiland_file(filepath)[source]
Load an Optiland Optic from a JSON file.
- Parameters:
filepath – The path to the JSON file.
- Returns:
An Optic instance.
- load_oslo_file(source: str)[source]
Load an OSLO .len file and return an Optic object.
- Parameters:
source – The path to a local .len file.
- Returns:
An Optic object created from the OSLO file data.
- load_zemax_file(source: str)[source]
Load a Zemax file and return an Optic object.
- Parameters:
source – The path to a local .zmx file or a URL pointing to a .zmx file.
- Returns:
An Optic object created from the Zemax file data.
- save_codev_file(optic: Optic, filepath: str) None[source]
Export an Optic to a CODE V Sequential .seq file.
The file is written in UTF-8 encoding. Warnings are issued via Python’s
warningsmodule for:Glasses with no CODE V catalog entry (written as fictitious Nd:Vd glass).
Pickups or solves that cannot be represented (resolved values exported).
Unsupported surface types (raises NotImplementedError).
- Parameters:
optic – The optic to export.
filepath – Destination path (should end in
.seq).
- Raises:
NotImplementedError – If the optic contains a surface type not yet supported by the CODE V writer.
- save_obj_to_json(obj, filepath)[source]
Save an object to a JSON file.
Note that this function can be used to save any object that has a method to_dict that returns a dictionary representation of the object. In Optiland, this includes most core classes, such as Optic, BaseGeometry, BaseCoating, BaseMaterial, Aperture, FieldGroup, WavelengthGroup, etc.
- Parameters:
obj – The object to save.
filepath – The path to the JSON file.
- save_optiland_file(obj, filepath)[source]
Save an Optiland Optic to a JSON file.
- Parameters:
obj – The Optic to save.
filepath – The path to the JSON file.
- save_oslo_file(optic: Optic, filepath: str) list[str][source]
Save an Optic to an OSLO .len file.
- Parameters:
optic – The optic to save.
filepath – The destination path.
- Returns:
A list of warnings.
- save_zemax_file(optic: Optic, filepath: str) None[source]
Export an Optic to a Zemax OpticStudio .zmx file.
The file is written in UTF-16 LE encoding to match OpticStudio’s default. Warnings are issued via Python’s
warningsmodule for:Glasses with no Zemax catalog entry (written as MODEL glass).
Pickups or solves that cannot be represented (resolved values exported).
- Parameters:
optic – The optic to export.
filepath – Destination path (should end in
.zmx).
- Raises:
NotImplementedError – If the optic contains a surface type not yet supported by the writer.
ValueError – If a coordinate system cannot be decomposed into COORDBRK surfaces.