pyoptools.raytrace.surface package

Module contents

Module that defines all the classes that describe the optical surfaces

class pyoptools.raytrace.surface.Surface

Bases: pyoptools.misc.picklable.picklable.Picklable

Surface is an abstract superclass for all optical surface objects. This class defines an API that all subclasses must support.

All Surface subclasses share the attributes reflectivity, and shape, that are defined as follows:

reflectivity Float point number between 0 and 1. 0 indicates a completely transparent surface, 1 a completely reflective surface. A value between are beam spliters.
shape Instance of the Shape, that indicates the surface’s aperture shape.

Each surface stores a hit_list, so the ray impact information can be obtained. This list records the point of impact in the surface reference system, and a pointer to the hitting ray so intensity, wavelength, and other information about the ray can be retrieved. The reset method, clear this lists.

distance()

Distance propagated by a ray until intersection with a surface.

This method returns the distance propagated by a ray since its origin and its point of intersection with a surface.

Args:

iray
Incident ray, iray must be in the coordinate system of the surface

Returns:

A tuple (distance,point_of_intersection, surface), where:

distance
The distance from the ray origin to the point of intersection with the surface
point_of_intersection
The point of intersection using the coordinate system of the surface
surface
a pointer to the surface
distance_s()

Distance propagated by a ray until intersection with a surface.

This method returns the distance propagated by a ray since its origin and its point of intersection with a surface. This method returns positive and negative distances, and does not check for apertures.

Parameters:-- incident ray (iray) –

iray must be in the coordinate system of the surface

Return value:

A tuple with the distance, the point of intersection using the coordinate system of the surface, and a pointer to the surface (distance,point of intersection, surface)
hit_list
id
int_nor()

Point of intersection between a ray and a surface and the normal.

Method that returns the point of intersection between a surface and a ray, and the vector normal to this point. I must return a tuple of the form ((ix,iyi,z),(nx,ny,nz)), where ix,iy,iz are the coordinates of the intersection point, and nx,ny,nz are the components of the vector normal to the surface.

Arguments:

iray – incident ray in the coordinate system of the surface.

This method uses surface.intersection, surface.normal, and surface.shape.hit

intersection()

Point of intersection between a ray and a surface.

This method returns the point of intersection between the surface and the ray. This intersection point is calculated in the coordinate system of the surface.

If there is not a point of intersection ie: ray is outside of the element aperture, it must return (numpy.inf,numpy.inf,numpy.inf)

Arguments:

iray – incident ray

iray must be in the coordinate system of the surface

Returns:

A vector [x,y,z] containing the coordinates of the point of intersection between the ray and the surface. If there is no intersection returns [Inf, Inf, Inf].

Note

This method does not need to be overloaded. Overload surface._intersection() instead.

normal()

Normal vector at the point ip.

This method returns the normal vector at a specific intersection point, given by ip. The normal vector must be normalized.

This method must be overloaded in all Surface subclasses. It contains the geometric specific code.

Arguments:

iray – incident ray in the coordinate system of the surface.

Returns:

An array [dx,dy,dz] indicating the vector normal to the surface

polylist()
propagate()

Method to calculate the ray refracted on a surface.

This method calculates the ray refracted (or rays refracted and reflected)on a surface.

Parameters:
  • -- incident ray (ri) –
  • -- refraction index in the incident media n. (ni) –
  • -- refraction index in the refracted media (nr) –

ri must be in the coordinate system of the surface

pw_cohef()

Method to generate the taylor polinomial coheficients that can be used to obtain the phase and intensity for different plane wave inclinations.

Notes

  • The pupil is normalized to the radius of the lens
  • This method assumes a circular shaped pupil
  • The phase is returned as an optical path
  • The intensity is normalized to 1

Arguments:

ni,nr Refraction index from the incident and refracted sides
ilimit Inferior limit for incidence angle of the plane wave in radians
slimit Superior limit for incidence angle of the plane wave in radians
step Step to be used to generate the interpolation data
order Order of the Taylor interpolation used
rsamples Tuple containing the number of ray samples to be used in each direction
zb Z position of the plane where the measurementas are made. The origin is the vertex of the surface. If None, an estimate position is taken.
pw_propagate()

Method to calculate wavefront emerging from the surface

This method calculates the wavefront emerging from the optical surface when illuminated by an unity amplitude plane wave. The k vector of the incoming PW is given by the direction of ri. The wavelength of the PW is given by the wavelength of ri. The origin of ri is not used at all.

Parameters:
  • -- surface incident ray (ri) –
  • -- refraction index in the incident media n. (ni) –
  • -- refraction index in the refracted media (nr) –
  • -- number of rays used to sample the surface (rsamples) –
  • -- shape of the output wavefront (shape) –
  • -- order of the polynomial fit (order) –
  • -- Z position of the input and output plane. The origin is the surface vertex (z) –

ri must be in the coordinate system of the surface Note: The ray comes from the negative side. Need to change this

pw_propagate1()

Method to calculate wavefront emerging from the surface

Note

This method needs to be checked, because the incoming plane wave has not a constant intensity. The ray distribution is affected by the surface topography. it is better to use the slow version pw_propagate.

This method calculates the wavefront emerging from the optical surface when illuminated by an unity amplitude plane wave. The k vector of the incoming PW is given by the direction of ri. The wavelength of the PW is given by the wavelength of ri. The origin of ri is not used at all.

The input and output planes are located at z=0 in the surface coordinated system.

Note: this method needs to be checked, because the incoming plane wave has not a constant intensity. The ray distribution is affected by the surface topography. it is better to use the slow version pw_propagate1.

Note: The ray comes from the negative side. Need to change this

Parameters:
  • -- isurface.pyncident ray (ri) –
  • -- refraction index in the incident media n. (ni) –
  • -- refraction index in the refracted media (nr) –

ri must be in the coordinate system of the surface

pw_propagate_list()

Method to calculate wavefront emerging from the surface

This method calculates samples of the wavefront emerging from the optical surface when illuminated by an unity amplitude plane wave. The k vector of the incoming PW is given by the direction of ri. The wavelength of the PW is given by the wavelength of ri. The origin of ri is not used at all.

The returned value is a list containing the x,y coordinates of the ray list in the output surface, and the optical path at such point.

To create an output matrix, this values must be interpolated.

Parameters:
  • -- incident ray (ri) –
  • -- refraction index in the incident media n. (ni) –
  • -- refraction index in the refracted media (nr) –
  • -- number of rays used to sample the surface (rsamples) –
  • -- Z position of the input and output plane. The origin is the surface vertex (z) –

ri must be in the coordinate system of the surface Note: The ray comes from the negative side. Need to change this

reflectivity
reset()

Remove information from the hit_list

shape
topo()

Method that returns the topography of the surface

The matrix returned is z=f(x,y). This method mus be overloaded in all subclasses of Surface.

wf_propagate()

Method to calculate wavefront emerging from the surface

This method calculates the wavefront emerging from the optical surface when illuminated by an arbitrary wavefront.

The input and output planes are located at z=0 in the surface coordinated system.

Parameters:
  • -- Field instance containing the incoming wavefront (wf) –
  • -- refraction index in the incident media n. (ni) –
  • -- refraction index in the refracted media. (nr) –
  • -- Tuple containing the number of rays used to sample the field. (samples) –
  • -- Tuple containing the shape of the output field (shape) –
class pyoptools.raytrace.surface.Cylindrical

Bases: pyoptools.raytrace.surface.surface.Surface

Class to define cylindrical surfaces.

Cylindrical is a class to define cylindrical optical surfaces, with an aperture given by the shape attribute.

To define the cylindrical surface you should pass the size of the aperture, and the radius of curvature of the cylinder.

The vertex of the surface is located at the origin of coordinates (0, 0, 0).

Example

>>> cs=Cylindrical(shape=Rectangular(size=(10,20)),curvature=0.15)

See Surface documentation for other options

curvature
normal()

Normal vector at the point ip.

This method returns the normal vector at a specific intersection point.

This method is overloaded from the superclass Surface.

topo()

Method that returns the topography of the surface

The matrix returned is z=f(x,y). This method is overloaded from the superclass Surface.

class pyoptools.raytrace.surface.Plane

Bases: pyoptools.raytrace.surface.surface.Surface

Class to define a plane surface.

Description:

Plane is a class to define rectangular plane surfaces. The surface shape is given by the shape attribute

Example

>>> ps=Plane(shape=Rectangular(size=(25,15)))
normal()

Method that returns the normal to the surface

topo()

Method that returns the topography of the surface

The matrix returned is z=f(x,y). This method mus be overloaded in all subclasses of Surface.

class pyoptools.raytrace.surface.Spherical

Bases: pyoptools.raytrace.surface.surface.Surface

Class to define spherical surfaces.

Spherical is a class to define spherical optical surfaces.

To define the spherical surface you should pass the shape of the aperture, and the radius of curvature of the sphere.

The vertex of the surface is located at the origin of coordinates (0, 0, 0) and the aperture is centered also about the origin

Example

>>> cs=Spherical(shape=Circular(radius=60),curvature=0.15)

See Surface documentation for other options

curvature
normal()

Return the vector normal to the surface

This method returns the vector normal to the sphere at a point int_p=(x,y,z).

topo()

Returns the Z value for a given X and Y

This method returns the topography of the spherical surface to be used to plot the surface.

class pyoptools.raytrace.surface.ArrayDetector

Bases: pyoptools.raytrace.surface.plane.Plane

CCD like detector surface.

Description the ArrayDetector class acts similar as a real CCD device. It holds a list of the coordinates of the rays that hits it.

Example of a CCD:

>>> cs=ArrayDetector(size=(10,10))
get_color_histogram()

Method that returns the number of ray impacts per unit of area of the detector. It simulates a color image.

Parameter:

size
Size of the detector in pixels. The physical size of the detector is given at the surface creation.
get_histogram()

Method that returns the number of ray impacts per unit of area of the detector.

Parameter:

size
Size of the detector in pixels. The physical size of the detector is given at the surface creation.
size
class pyoptools.raytrace.surface.Aperture

Bases: pyoptools.raytrace.surface.plane.Plane

Class to define a surface with an aperture

This class is used to define stops in the optical system. It receives two parameters.

ARGUMENTS:

shape It is a subclass of Shape, and defines the external shape of the stop
ap_shape It is a subclass of Shape, and defines the internal shape of the stop (the aperture shape).

EXAMPLE

Creation of an aperture surface:

ap=Aperture(shape=Rectangular(size=(60,60)),ap_shape=Circular(radius=2.5))

Note: To create an stop component, use the Stop class from the comp_lib module. It creates the aperture surface and encapsulate it in an component that can be used in a System.

ap_shape
propagate()

The OptSurf.propagate is overloaded so it can be decided if the rays continue propagating or not.

Warning: This surface only checks if the ray continues or not. It does not calculate refraction or reflection. It must not be used to create lenses or mirrors.

class pyoptools.raytrace.surface.TaylorPoly

Bases: pyoptools.raytrace.surface.surface.Surface

Class that defines a high order polynomical surface

An aspherical surface is defined as:

Z= poly2d(x,y)
Example
>>> cs=TaylorPoly(shape=Rectangle(size=(5,5)), poly =poly2d((0,1,1)))
normal()

Return the vector normal to the surface

This method returns the vector normal to the asphere at a point int_p=(x,y,z).

Note: It uses x and y to calculate the z value and the normal.

poly
topo()

Returns the Z value for a given X and Y

This method returns the topography of the TaylorPoly surface to be used to plot the surface.

zmax
zmin
class pyoptools.raytrace.surface.Cylinder

Bases: pyoptools.raytrace.surface.surface.Surface

Class to define cylinder shaped surfaces.

Description:

Cylinder is a class to define a tube or a hollow cylinder surface.

To define the cylinder surface you should pass the radius of the cylinder, and its length

The center of the cylinder is located at the origin of coordinates (0, 0, 0) and its length is parallel to the Z axis.

Example

>>> cs=Cylinder(radius=5.,length=10.)

See Surface documentation for other options

intersection()

Point of intersection between a ray and the cylinder

This method returns the point of intersection between the surface and the ray. This intersection point is calculated in the coordinate system of the surface.

iray – incident ray

iray must be in the coordinate system of the surface

Note: Because of the way the cylinder is defined, it does not use shapes to define its boundary, for that reason, the intersection method and not the _intersection method was overloaded.

length
normal()

Normal vector at the point int_p.

This method returns the normal vector at a specific intersection point, given by int_p.

polylist()

Because this is a closed surface, the method had to be overloaded

radius
class pyoptools.raytrace.surface.Aspherical

Bases: pyoptools.raytrace.surface.surface.Surface

Class that defines a high order aspherical surface

An aspherical surface is defined as:

Z=(Ax*x**2+Ay*y**2)/(1+sqrt(1-(1+Kx)*Ax**2*x**2-(1+Ky)*Ay**2*y**2))+ poly2d()

The poly2d is defined by a array in the same way as it is defined in the TaylorPoly Class

Example
>>> cs=Aspherical(shape=Rectangle(size=(5,5)),Ax=.5,Ay=.3,Kx=.1, Ky=.1                            poly =poly2d((0,1,1)))
Ax
Ay
Kx
Ky
normal()

Return the vector normal to the surface

This method returns the vector normal to the asphere at a point int_p=(x,y,z).

Note: It uses x and y to calculate the z value and the normal.

poly
topo()

Returns the Z value for a given X and Y

This method returns the topography of the aspherical surface to be used to plot the surface.

zmax
zmin
class pyoptools.raytrace.surface.Powell

Bases: pyoptools.raytrace.surface.surface.Surface

Class that defines a Powell lens surface

A Powell lens surface is defined as:

Z=sqrt((1+K)*x**2- 2*R*x+y**2)

without an additional poly2d definition like in the aspherical surface case The values K and R correspond to the conicity and curvature respectively

Example
>>> cs=Powell(shape=Circular(radius=2.5), K=-4.302, R=3.00)
K
R
normal()

Return the vector normal to the surface

This method returns the vector normal to the asphere at a point int_p=(x,y,z).

Note: It uses x and y to calculate the z value and the normal.

poly
topo()

Returns the Z value for a given X and Y

This method returns the topography of the Powell lens surface to be used to plot the surface.

zmax
zmin
class pyoptools.raytrace.surface.RPPMask

Bases: pyoptools.raytrace.surface.surface.Surface

Class to define a reflective plane phase mask.

Description:

RPPMask is a class to define diffractive plane surfaces. If reflectivity is 1 the gratting is reflective, if it is 0 the gratting is transmissive. If it is between 0 and 1, both transmitted and reflected diffracted rays are shown.

The surface shape is given by the shape attribute

The phm attribute is a poly2d instance, that contains the polinomial describing the phase modulation of the gratting. The X and Y input values of the polynomial are in microns.

Example

>>> g=RPPMask(shape=Rectangular(size=(10,10)), phm=poly2d([0,2*pi/15.,0]),M=[1])

This is a 10 mm x 10 mm linear gratting that has a fringe each 15 microns

M
normal()

Method that returns the normal to the surface

phm
phx
phy
propagate()

Method that calculates the propagation of a ray through a diffraction gratting.

This method uses all the units in millimeters

topo()

Method that returns the topography of the surface

The matrix returned is z=f(x,y). This method mus be overloaded in all subclasses of Surface.

class pyoptools.raytrace.surface.IdealSurface

Bases: pyoptools.raytrace.surface.surface.Surface

Clase que representa una superficie ideal. Se utiliza para crear lentes ideales

f
normal()

Method that returns the normal to the surface

propagate()

Method to calculate the ray refracted on a surface.

This method calculates the ray refracted (or rays refracted and reflected)on a surface.

Parameters:
  • -- incident ray (ri) –
  • -- refraction index in the incident media n. (ni) –
  • -- refraction index in the refracted media (nr) –

ri must be in the coordinate system of the surface

topo()

Method that returns the topography of the surface

The matrix returned is z=f(x,y). This method mus be overloaded in all subclasses of Surface.

class pyoptools.raytrace.surface.IdealPPlanes

Bases: pyoptools.raytrace.surface.surface.Surface

Clase que representa un par de superficies principales ideales. Se utiliza para crear lentes ideales gruesas

normal

Method that returns the normal to the surface

propagate
topo