optiland.fileio.codev#
CODE V Sequential file I/O for Optiland.
Provides reader and writer for CODE V Sequential (.seq) files.
- Reader pipeline: .seq file -> CodeVDataParser -> CodeVDataModel
-> CodeVToOpticConverter -> Optic
- Writer pipeline: Optic -> OpticToCodeVConverter -> CodeVDataModel
-> CodeVFileEncoder -> .seq file
- class BaseSurfaceHandler[source]#
Handles serialisation and deserialisation for one CODE V surface type.
Subclasses must declare class-level
codev_typeandoptiland_typestrings and implementparse()andformat().
- class CodeVDataModel(name: str | None = None, aperture: dict[str, ~typing.Any] = <factory>, fields: dict[str, ~typing.Any] = <factory>, wavelengths: dict[str, ~typing.Any] = <factory>, surfaces: dict[int, dict[str, ~typing.Any]] = <factory>, radius_mode: bool = True, units: str = 'MM', sto_surface_index: int | None = None)[source]#
Intermediate representation of a CODE V Sequential optical system.
This dataclass is the stable lingua franca shared between the read and write paths. The reader populates it from a parsed .seq file; the writer produces it from an Optic object.
- Variables:
name (str | None) – Optional system name (from the TITLE operand).
aperture (dict[str, Any]) – Aperture information keyed by CODE V aperture command (e.g.
{"EPD": 10.0}or{"FNO": 2.8}).fields (dict[str, Any]) – Field configuration including type, x/y coordinates and optional weights.
wavelengths (dict[str, Any]) – Wavelength data in microns, optional weights, and the 0-based primary wavelength index.
surfaces (dict[int, dict[str, Any]]) – Mapping from surface index to a raw operand dict used by the encoder / converter.
radius_mode (bool) – If True, surface values are radii (RDM Y); if False, values are curvatures (RDM N). Defaults to True.
units (str) – Length units string; always
"MM"for v1.
- class CodeVToOpticConverter(codev_data: dict[str, Any] | CodeVDataModel)[source]#
Converts a CodeVDataModel into an Optic object.
Also implements BaseOpticReader so that the full pipeline (file load -> parsing -> conversion) can be triggered via
read().- Parameters:
codev_data – A plain dict or CodeVDataModel containing the CODE V optical system data.
- Variables:
data – The CODE V data as a plain dict.
optic – The Optic instance built by
convert().
- class CodeVWriter[source]#
BaseOpticWriter implementation for CODE V .seq files.
This thin wrapper around
save_codev_file()allows the CODE V writer to be used polymorphically via the BaseOpticWriter interface.
- get_handler(codev_type: str) BaseSurfaceHandler[source]#
Look up a registered handler by CODE V surface type string.
- Parameters:
codev_type – The CODE V surface profile identifier (e.g.
"SPH").- Returns:
The registered handler instance.
- Raises:
NotImplementedError – If
codev_typeis not in the registry.
- get_handler_for_optiland_type(optiland_type: str) BaseSurfaceHandler[source]#
Look up a registered handler by Optiland surface type string.
- Parameters:
optiland_type – The Optiland surface type string (e.g.
"standard").- Returns:
The registered handler instance.
- Raises:
NotImplementedError – If no handler matches
optiland_type.
- 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.