System Diagnostics Demo#
optiland.diagnostics.check_system inspects an Optic and reports the mistakes newcomers hit most often — a missing wavelength, an undefined aperture, a stop that was never marked — each with the offending object and a runnable fix. It never modifies the lens it inspects, so it is safe to call at any point while building a system.
See the Conventions page for the concepts these checks refer to.
[1]:
from optiland.diagnostics import check_system
from optiland.optic import Optic
A lens with a few surfaces, but nothing else defined yet#
[2]:
lens = Optic()
lens.surfaces.add(index=0, thickness=100)
lens.surfaces.add(index=1, radius=20, thickness=10, material="N-SF11")
lens.surfaces.add(index=2, thickness=40)
lens.surfaces.add(index=3)
report = check_system(lens)
report
[2]:
| Severity | Code | Where | Message | Fix |
|---|---|---|---|---|
| error | OPT001 | No wavelengths are defined on the optical system. | lens.wavelengths.add(value=0.55, is_primary=True) · docs | |
| error | OPT003 | No aperture is defined on the optical system. | lens.set_aperture(aperture_type="EPD", value=25) · docs | |
| error | OPT004 | No stop surface is defined. | lens.surfaces.add(..., is_stop=True) on the aperture surface · docs | |
| error | OPT006 | No fields are defined on the optical system. | lens.fields.add(y=0) · docs |
Each finding names the fix as a runnable line of code. report.ok is False while any error-severity finding remains:
[3]:
report.ok
[3]:
False
Applying the suggested fixes#
[4]:
lens.surfaces.surfaces[1].is_stop = True
lens.set_aperture(aperture_type="EPD", value=25)
lens.fields.add(y=0)
lens.wavelengths.add(value=0.55, is_primary=True)
report = check_system(lens)
report
[4]:
DiagnosticReport: no issues found.
[5]:
report.ok
[5]:
True