Introduction to pyOpTools

What is pyOpTools

The pyOpTools package is composed by a set of python modules that allow to simulate the behavior of optical systems. Initially it was only oriented to the ray tracing, but currently in the development version it has some tools which can be used to simulate optical fields and their propagation.

This tutorial will introduce the simulation of optical systems by ray tracing in a Jupiter notebook.

In the following video there is a small demo of an old version of pyOpTools

[1]:
from IPython.lib.display import YouTubeVideo
YouTubeVideo("DB8sfm7pVPI",width=640,height=480)
[1]:

Some basic characteristics of pyOpTools

  1. It is an open source development
  2. It is being developed by the technological development group of Combustión Ingenieros S.A.S, and the applied optics group of the Universidad Nacional de Colombia.
  3. It is written in python y cython.
  4. It is written using the object oriented programming paradigm
  5. It can perform non-sequential ray-tracing of complex 3D systems.
  6. It can be used as a module to develop programs to simulate optical systems.
  7. It can be used in a Jupyter Notebook to perform interactive simulation tasks
  8. There is a FreeCAD workbench under development, to simplify its applications to optical design tasks. This development is being hosted in https://github.com/cihologramas/freecad-pyoptools

A basic introduction

Importing pyoptools

The fist step to simulate an optical system in pyOpTools, is to import the package. The most simple way to perform this task is to import the pyoptools.all subpackage:

[2]:
from pyoptools.all import *

After the module is imported, a simulation can be performed. In the following example we will create a simple system composer by a lens, a detector, and a light source.

As a first step we will create a lens from the Edmund Scientific catalog (reference 32475), we will create a CCD-like sensor with 20 mm X 20 mm size, and a parallel ray source with cartesian beam distribution.

Note: In pyOpTools (unless noted) the units are in millimeters.
[3]:
L=library.Edmund.get("32475")
SEN=CCD(size=(20,20))
R=parallel_beam_c(origin=(0.0, 0.0, 0.0), direction=(0.0, 0.0, 0.0),
                  size=(10, 10), num_rays=(5, 5), wavelength=0.58929)
/home/docs/checkouts/readthedocs.org/user_builds/pyoptools/envs/latest/lib/python3.7/site-packages/pyoptools-0.1.1-py3.7-linux-x86_64.egg/pyoptools/raytrace/library/library.py:159: DeprecationWarning: This method is deprecated, you can use dictionary-style accessinstead
  DeprecationWarning,

with this components created, we will create a system, where the lens is placed at the position (0,0,50) , and the CCD is placed at the position (0,0,150). At the end the Plot3D command will be used to show the resulting system.

Note: The plot obtained with the Plot3D command is interactive. Meaning you can rotate it (left click), zoom it (scroll wheel), and drag it (right click), by clicking on it and moving the mouse.

[4]:
S=System(complist=[(L,(0,0,50),(0,0,0)),(SEN,(0,0,150),(0,0,0))],n=1)
Plot3D(S)
/home/docs/checkouts/readthedocs.org/user_builds/pyoptools/envs/latest/lib/python3.7/site-packages/ipywidgets/widgets/widget.py:502: DeprecationWarning: Passing unrecognized arguments to super(MeshPhongMaterial).__init__(ambient='#050505').
object.__init__() takes exactly one argument (the instance to initialize)
This is deprecated in traitlets 4.2.This error will be raised in a future release of traitlets.
  super().__init__(**kwargs)
[4]:

After the system is created, we can add the raysource and propagate the system.

[5]:
S.ray_add(R)
S.propagate()
Plot3D(S)
[5]: