optrace
  • Examples
  • Installation
  • User Guide
  • GitHub Repo
/
  • 1. Example Gallery
  • 2. Installation
  • 3. Quickstart
  • 4. User Guide
    • 4.1. Overview
    • 4.2. Base Shapes (Surface, Line, Point)
    • 4.3. Elements (Lens, Ray Source, …)
    • 4.4. Geometry Groups
    • 4.5. Raytracer
    • 4.6. Refractive Indices
    • 4.7. Spectrum Classes
    • 4.8. Image Classes
    • 4.9. Focus Search
    • 4.10. Paraxial Analysis
    • 4.11. PSF Convolution
    • 4.12. Plotting Functions
    • 4.13. GUI Interaction
    • 4.14. GUI Automation
    • 4.15. Advanced Topics
  • 5. Implementation Details
    • 5.1. Property Sampling
    • 5.2. Tracing Procedure
    • 5.3. Heisenberg Uncertainty Ray Bending
    • 5.4. Image and Spectrum Rendering
    • 5.5. Ray Transfer Matrix Analysis
    • 5.6. PSF Convolution
    • 5.7. Focus Methods
    • 5.8. Color Management
    • 5.9. Miscellaneous
  • 6. API Reference
    • 6.1. Library Structure
    • 6.2. Global Module
    • 6.3. tracer Submodule
    • 6.4. tracer.color Submodule
    • 6.5. tracer.geometry Submodule
    • 6.6. tracer.geometry.surface Submodule
    • 6.7. tracer.image Submodule
    • 6.8. tracer.spectrum Submodule
    • 6.9. tracer.presets Submodule
    • 6.10. plots Submodule
    • 6.11. gui Submodule
  • 7. Development
    • 7.1. Testing
    • 7.2. Documentation
    • 7.3. Packaging
    • 7.4. Notes
    • 7.5. Changelog

On this page

  • 1.1. Achromat
  • 1.2. Arizona Eye Model
  • 1.3. Astigmatism
  • 1.4. Brewster Polarizer
  • 1.5. Cosine Surfaces
  • 1.6. Double Gauss
  • 1.7. GUI Automation
  • 1.8. LeGrand Eye Model
  • 1.9. HURB Apertures
  • 1.10. Image Render
  • 1.11. Image Render Many Rays
  • 1.12. IOL Pinhole Imaging
  • 1.13. IOL Target Imaging
  • 1.14. Keratoconus
  • 1.15. Microscope
  • 1.16. Prism
  • 1.17. PSF Imaging
  • 1.18. Refraction Index Presets
  • 1.19. Spectrum Presets
  • 1.20. Sphere Projections
  • 1.21. Spherical Aberration
  1. optrace /
  2. 1. Example Gallery

1. Example Gallery¶

This gallery showcases all optrace examples.
You can download the full examples.zip archive here.

1.1. Achromat¶

File: examples/achromat.py

This example demonstrates the effect of an achromatic doublet on the dispersion. Ray sources consist of different monochromatic spectral lines to show the different focal lengths. The “Use achromatic doublet” option in the “Custom” GUI tab toggles the use of this doublet. In the unchecked case a standard doublet with same optical power of 30 D is simulated, showing significant longitudinal chromatic aberration (LCA).

_images/example_achromat1.png

Fig. 1.1 Overview of the scene¶

_images/example_achromat2.png

Fig. 1.2 Uncorrected case with 1.06 D difference in optical power between blue and red.¶

_images/example_achromat3.png

Fig. 1.3 The achromatic doublet reduces the LCA to just 0.03 D.¶

1.2. Arizona Eye Model¶

File: examples/arizona_eye_model.py

This example is a demonstration of human eye vision with adaptation at a distance of 66 cm. The Arizona eye model is employed to simulate a resolution chart. This eye model accurately matches on- and off-axis aberration levels from clinical data and accounts for wavelength and adaptation dependencies.

In the “Custom” tab of the GUI there are options available to change the pupil diameter and adaptation of the eye.

_images/example_arizona_eye_scene.png

Fig. 1.4 The Arizona eye model inside the raytracer.¶

Table 1.1 Original resolution chart (left) at 66cm distance imaged with the correctly adapted eye with 1.67 D and a pupil of 4mm diameter (right).¶
_images/example_arizona_render1.webp
_images/example_arizona_render2.webp
Table 1.2 Eye adapted with 0.0 D and a 2 mm pupil (left) and a 6 mm pupil (right)¶
_images/example_arizona_render3.webp
_images/example_arizona_render4.webp

1.3. Astigmatism¶

File: examples/astigmatism.py

This script showcases astigmatism by simulating sagittal and meridional off-axis rays. You can control their angle by changing their setting in the “Custom” Tab in the GUI. Sagittal (blue) and meridional (red) rays are highlighted in different colors, making their focal positions easier to visualize.

_images/example_astigmatism0.png

Fig. 1.5 On-axis case¶

_images/example_astigmatism1.png

Fig. 1.6 Off-axis case¶

_images/example_astigmatism2.png

Fig. 1.7 Off-axis case, zoomed in¶

1.4. Brewster Polarizer¶

File: examples/brewster_polarizer.py

A setup with three different light rays impinging on multiple planar surfaces with an incident angle equal to the Brewster angle. Depending on the polarization direction we can see a huge difference in the light’s transmission.

_images/example_brewster.png

Fig. 1.8 Brewster angle demonstration.¶

1.5. Cosine Surfaces¶

File: examples/cosine_surfaces.py

An example with two lenses with orthogonal cosine modulations on each side. Creates rectangular, kaleidoscope-like images inside the beam path.

_images/example_cosine_surfaces1.png

Fig. 1.9 Scene overview.¶

_images/example_cosine_surfaces2.webp

Fig. 1.10 First detector image¶

_images/example_cosine_surfaces3.webp

Fig. 1.11 Second detector image¶

1.6. Double Gauss¶

File: examples/double_gauss.py

Example simulation of the double gauss Nikkor Wakamiya, 100mm, f1.4 objective. The simulation traces point sources from a distance of -50m and renders their PSF. Each point source is shown in a different color.

Table 1.3 Elements of the objective, see here¶

#

T

Distance

Rad Curv

Diameter

Material

n

nd

Vd

0

S

20

inf

100

basic/air

1.000

1.000

89.30

1

S

5

78.36

76

1.797

1.797

45.50

2

S

9.8837

469.5

76

basic/air

1.000

1.000

89.30

3

S

0.1938

50.3

64

1.773

1.773

49.40

4

S

9.1085

74.38

62

basic/air

1.000

1.000

89.30

5

S

2.9457

138.1

60

1.673

1.673

32.20

6

S

2.3256

34.33

51

basic/air

1.000

1.000

89.30

7

S

16.07

inf

49.6

basic/air

1.000

1.000

89.30

8

S

13

-34.41

48.8

1.740

1.740

28.30

9

S

1.938

-2907

57

1.773

1.773

49.40

10

S

12.403

-59.05

60

basic/air

1.000

1.000

89.30

11

S

0.3876

-150.9

66.8

1.788

1.788

47.50

12

S

8.333

-57.89

67.8

basic/air

1.000

1.000

89.30

13

S

0.1938

284.6

66

1.788

1.788

47.50

14

S

5.0388

-253.2

66

basic/air

1.000

1.000

89.30

15

S

73.839

inf

86.53

basic/air

1.000

1.000

89.30

_images/example_double_gauss.png

Fig. 1.12 Side view of the objective.¶

_images/example_double_gauss2.webp

Fig. 1.13 PSF of point source with 10° to the optical axis.¶

_images/example_double_gauss3.webp

Fig. 1.14 PSF of point source with 20° to the optical axis.¶

1.7. GUI Automation¶

File: examples/gui_automation.py

An example of GUI automation. Position and size of a line source that illuminates a sphere lens are varied at runtime. There is a clearly visible spherical aberration of the lens. The automation function can be rerun by pressing the button in the “Custom” GUI tab.

_images/example_gui_automation_1.png

Fig. 1.15 Spherical aberration of a shift ray beam.¶

_images/example_gui_automation_2.png

Fig. 1.16 Combined spherical aberration.¶

1.8. LeGrand Eye Model¶

File: examples/legrand_eye_model.py

A geometry with the paraxial LeGrand eye model. Cardinal points, exit and entrance pupils are calculated and marked inside the scene.

_images/example_legrand1.png

Fig. 1.17 Eye model side view.¶

_images/example_legrand2.png

Fig. 1.18 Tilted view with visible pupil.¶

1.9. HURB Apertures¶

File: examples/hurb_apertures.py

This example demonstrates the diffraction approximation through Heisenberg uncertainty ray bending (HURB) of multiple aperture shapes. You can read more about HURB in section Section 5.3.

Different apertures can be selected in the “custom” tab of the GUI.

_images/example_hurb_scene.png
_images/example_hurb_square.webp

Fig. 1.19 Approximated diffraction pattern of a square aperture.¶

_images/example_hurb_slit.webp

Fig. 1.20 Approximated diffraction pattern of a slit aperture.¶

_images/example_hurb_pinhole.webp

Fig. 1.21 Approximated diffraction pattern of a pinhole aperture.¶

_images/example_hurb_edge.webp

Fig. 1.22 Approximated diffraction pattern of an edge.¶

1.10. Image Render¶

File: examples/image_render.py

A simple imaging system consisting of a single lens. Spherical aberration and distortion are apparent. By using the aperture stop the aberrations can be limited, approximating the paraxial case for a very small diameter. The size of the stop and the test image are parameterizable through the “Custom” GUI tab.

_images/example_image_render_1.png

Fig. 1.23 Scene overview for a aperture radius o 3.0 mm.¶

_images/example_image_render_2.webp

Fig. 1.24 Source Image¶

_images/example_image_render_3.webp

Fig. 1.25 Detector image with a 1.5 mm stop radius.¶

_images/example_image_render_4.webp

Fig. 1.26 Detector image with a 3.0 mm stop radius.¶

_images/example_image_render_5.webp

Fig. 1.27 Grid source image.¶

_images/example_image_render_6.webp

Fig. 1.28 Detector image with a 1.5 mm stop radius.¶

Note that the paraxial image distance and the best fitting image distance for a high aberration setup differ. This is why you should move the detector to larger z-positions when decreasing the stop size.

1.11. Image Render Many Rays¶

File: examples/image_render_many_rays.py

Comparable to the Image Render example. Same lens setup, but it is traced with many more rays by using the iterative render functionality. This is done for multiple image distances and without needing to start a GUI.

_images/example_rgb_render1.webp

Fig. 1.29 Detector image at z = 15 mm.¶

_images/example_rgb_render2.webp

Fig. 1.30 Detector image at z = 20 mm.¶

_images/example_rgb_render3.webp

Fig. 1.31 Detector image at z = 25 mm.¶

_images/example_rgb_render4.webp

Fig. 1.32 Detector image at z = 29 mm.¶

_images/example_rgb_render5.webp

Fig. 1.33 Detector image at z = 31 mm.¶

_images/example_rgb_render6.webp

Fig. 1.34 Detector image at z = 36 mm.¶

1.12. IOL Pinhole Imaging¶

File: examples/IOL_pinhole_imaging.py

Simulation of an Alcon IQ intraocular lens (IOL) in the Arizona Eye Model. A pinhole is rendered for three different viewing distances.

_images/example_IOL_pinhole_0D.webp

Fig. 1.35 0.01 D defocus.¶

_images/example_IOL_pinhole_075D.webp

Fig. 1.36 0.75 D defocus.¶

_images/example_IOL_pinhole_150D.webp

Fig. 1.37 1.50 D defocus.¶

1.13. IOL Target Imaging¶

File: examples/IOL_target_imaging.py

Simulation of an Alcon IQ intraocular lens (IOL) in the Arizona Eye Model. An ETDRS chart is rendered for three different viewing distances. You can change distance, angle, pupil and image parameters from within the script.

_images/example_IOL_target_0D.webp

Fig. 1.38 0.01 D defocus.¶

_images/example_IOL_target_075D.webp

Fig. 1.39 0.75 D defocus.¶

_images/example_IOL_target_150D.webp

Fig. 1.40 1.50 D defocus.¶

1.14. Keratoconus¶

File: examples/keratoconus.py

A simulation of vision through a patient’s eye with progressing levels of keratoconus. Parameters are taken from the work of Tan et al. (2008).

Table 1.4 Simulated images for different keratoconus stages.¶
_images/example_keratoconus_1.webp

Fig. 1.41 Healthy eye.¶

_images/example_keratoconus_2.webp

Fig. 1.42 Mild keratoconus.¶

_images/example_keratoconus_3.webp

Fig. 1.43 Advanced keratoconus.¶

_images/example_keratoconus_4.webp

Fig. 1.44 Severe keratoconus.¶

Inside the python script you can set the option show_psf=True to also plot die PSF for each case.

Table 1.5 PSFs for each case. Note the different scale.¶
_images/example_keratoconus_5.webp

Fig. 1.45 PSF for the healthy eye.¶

_images/example_keratoconus_6.webp

Fig. 1.46 PSF for mild keratoconus.¶

_images/example_keratoconus_7.webp

Fig. 1.47 PSF for advanced keratoconus.¶

_images/example_keratoconus_8.webp

Fig. 1.48 PSF for severe keratoconus.¶

1.15. Microscope¶

File: examples/microscope.py

A more complex microscope setup with a objective, tube and eyepiece group as well as the human eye as imaging system. The infinity corrected microscope is loaded in multiple parts from ZEMAX (.zmx) files that are were built from patent data.

_images/example_microscope0.png

Fig. 1.49 Overview of the imaging system.¶

_images/example_microscope1.webp

Fig. 1.50 Intermediate image.¶

_images/example_microscope2.webp

Fig. 1.51 Human visible image.¶

1.16. Prism¶

File: examples/prism.py

A prism example where light is split into its spectral components. Light spectrum and materials are parameterizable through the “Custom” GUI tab.

_images/example_prism.png

Fig. 1.52 Light propagation side view.¶

_images/example_prism_5.webp

Fig. 1.53 D65 daylight spectrum.¶

_images/example_prism_6.webp

Fig. 1.54 F11 flourescent light spectrum.¶

_images/example_prism_2.webp

Fig. 1.55 Detector image for a D65 light spectrum and LAK8 (Abbe number 53.83).¶

_images/example_prism_3.webp

Fig. 1.56 Detector image for a F11 light spectrum and LAK8 (Abbe number 53.83).¶

_images/example_prism_4.webp

Fig. 1.57 Detector image for a F11 light spectrum and LAK8 (Abbe number 28.53).¶

1.17. PSF Imaging¶

File: examples/psf_imaging.py

Demonstrates image formation by convolution of a resolution chart and a halo PSF.

_images/example_psf1.webp

Fig. 1.58 Resolution chart.¶

_images/example_psf2.webp

Fig. 1.59 PSF, plotted in linear intensity.¶

_images/example_psf3.webp

Fig. 1.60 Resulting image. Displayed linear to human perception.¶

1.18. Refraction Index Presets¶

File: examples/refraction_index_presets.py

This example displays different plots for the refraction index presets.

_images/glass_presets_n.svg

Fig. 1.61 Refractive index curve for glasses.¶

_images/glass_presets_V.svg

Fig. 1.62 Abbe number diagram for glasses.¶

_images/plastics_presets_n.svg

Fig. 1.63 Refractive index curve for plastics.¶

_images/plastics_presets_V.svg

Fig. 1.64 Abbe number diagram for plastics.¶

_images/misc_presets_n.svg

Fig. 1.65 Refractive index curve for miscellaneous materials.¶

_images/misc_presets_V.svg

Fig. 1.66 Abbe number diagram for miscellaneous materials.¶

1.19. Spectrum Presets¶

File: examples/spectrum_presets.py

An example loading multiple light spectrum plots, including the sRGB primaries and standard illuminants.

_images/Standard_illuminants.svg

Fig. 1.67 CIE standard illuminants.¶

_images/LED_illuminants.svg

Fig. 1.68 CIE LED standard illuminants.¶

_images/Fluor_illuminants.svg

Fig. 1.69 Selected CIE flourescent lamp illuminants.¶

_images/srgb_spectrum.svg

Fig. 1.70 Exemplary spectral curves for the sRGB color space primaries.¶

_images/cie_cmf.svg

Fig. 1.71 Color matching functions for the CIE 1931 XYZ 2° standard observer.¶

1.20. Sphere Projections¶

File: examples/sphere_projections.py

This script demonstrates the effect of different projections methods for a spherical surface detector. Multiple point sources emit an angular cone spectrum from the spherical center of a spherical detector. The detector view then displays an equivalent of a Tissot’s indicatrix.

_images/example_sphere_projections.png

Fig. 1.72 Scene overview.¶

_images/indicatrix_equidistant.webp

Fig. 1.73 Equidistant map projection.¶

_images/indicatrix_equal_area.webp

Fig. 1.74 Equal-Area map projection.¶

_images/indicatrix_stereographic.webp

Fig. 1.75 Stereographic map projection.¶

_images/indicatrix_orthographic.webp

Fig. 1.76 Orthographic map projection.¶

1.21. Spherical Aberration¶

File: examples/spherical_aberration.py

The example demonstrates the refractive error of a spherical sources by tracing a paraxial and a non-paraxial light beam for comparison. This is the Quickstart example with many explanations in the code’s comments.

_images/example_spherical_aberration1.png

Fig. 1.77 Side view of the setup.¶

_images/example_spherical_aberration2.png

Fig. 1.78 Zoomed-in focal region.¶

Previous
Home
Next
2. Installation
© 2025, Damian Mendroch     Impressum     Legal Notice

Made with Sphinx and Shibuya theme.