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>, private_glasses: dict[str, list[float]] = <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.
private_glasses (dict[str, list[float]]) – Private glass catalog written as a
PRVblock, mapping a glass name ("OPT1") to its refractive index at each wavelength, in the order the wavelengths are written.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. Everything that cannot be written faithfully is refused before the destination file is opened, so an existing file is left untouched. Features that are dropped or changed are reported with a
UserWarning.The optic name becomes the
TITLE; a'in it is written as"and a line break as a space.STOis written once, on the stop surface Optiland reports (optic.surfaces.stop_index).- Parameters:
optic – The optic to export.
filepath – Destination path (should end in
.seq).
- Raises:
NotImplementedError – If the optic has a material with a custom propagation model, a non-air medium in object space, a curved object surface, the aperture stop on the object or image surface, a negative first spacing before any mirror (a system authored backwards, with the light starting out towards
-z; a negative object distance alone is written), a decentered, tilted or chained surface, a surface geometry other than planar, spherical, conic or even-asphere, an even-asphere with a non-zero r^2 term or a non-zero term above r^20, a non-refractive interaction model (thin-lens, diffractive, phase), an aspheric or conic image surface, ideal-material absorption, aDataMaterial, or a field definition with no CODE V equivalent.ValueError – If any number to be written is not finite (
infornan; an infinite object distance and an infiniter_maxare allowed), the object thickness is-inf, a surface aperture has an invalid radius (r_max <= r_min, negative ornan), the wavelength weights do not match the wavelengths, the optic has more than 21 wavelengths or more than 25 fields (the most CODE V loads), a material needing a private glass has no positive index at one of the system wavelengths, a wavelength is zero or negative, no wavelength is primary, an optic with a real surface has no stop surface, no aperture, no fields or no wavelengths, the aperture isobjectNAof 1 or more, or the object distance is exactly 0.
- Warns:
UserWarning – For a material with no verified CODE V catalog name, or a catalog glass with a system wavelength outside its data range (both written as a private glass with its index at the system wavelengths); for extinction
kof such a glass (not exported); for pickups or solves (their resolved values are exported); for a surface aperture other than a plainRadialAperture, or any aperture on the object or image surface (not exported); for field vignetting factorsvx/vy(not exported); for afloat_by_stop_sizeaperture, or animageFNOaperture with the object at a finite distance (both written as a fixedEPD); and for an unknown aperture type (aperture skipped).