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_type and optiland_type strings and implement parse() and format().

codev_type: ClassVar[str]#
abstractmethod format(surface: Surface) dict[str, Any][source]#

Convert an Optiland Surface to a raw operand dict for CodeVFileEncoder.

Parameters:

surface – The Optiland Surface to serialise.

Returns:

A dict of raw CODE V operand values keyed by operand name (e.g. {"radius": 50.0, "conic": -1.0}).

optiland_type: ClassVar[str]#
abstractmethod parse(raw: dict[str, Any]) dict[str, Any][source]#

Convert a raw CodeVDataParser surface dict to optiland surface kwargs.

Parameters:

raw – The raw surface dictionary produced by CodeVDataParser for one surface.

Returns:

A dict of keyword arguments suitable for optic.surfaces.add().

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.

aperture: dict[str, Any]#
fields: dict[str, Any]#
name: str | None = None#
radius_mode: bool = True#
sto_surface_index: int | None = None#
surfaces: dict[int, dict[str, Any]]#
to_dict() dict[str, Any][source]#

Return the data model as a plain dictionary.

Returns:

A plain dict representation suitable for use with CodeVToOpticConverter.

units: str = 'MM'#
wavelengths: dict[str, Any]#
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().

convert() Optic[source]#

Convert the stored CODE V data dict into an Optic object.

Returns:

The fully-configured Optic instance.

read(source: str) Optic[source]#

Read a CODE V .seq file and return a fully-configured Optic.

Parameters:

source – Local file path to a .seq file.

Returns:

A configured Optic instance.

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.

write(optic: Optic, filepath: str) list[str][source]#

Write optic to a .seq file at filepath.

Parameters:
  • optic – The optic to export.

  • filepath – Destination path.

Returns:

An empty list (warnings are issued via the warnings module).

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_type is 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 warnings module 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.