pyoptools.raytrace.calc package

Module contents

Method collection to make calculation for optical systems

This function uses a random search algorithm to find the chief_ray for a given optical system and object point.

Parameters:
  • opsys (pyoptools.raytrace.system.System) – Optical system that will be used to find the chief ray
  • ccds (pyoptools.raytrace.comp_lib.CCD) – Detector placed in the aperture plane. Must be centred in the optical axis
  • o (tuple(float, flo0at, float)) – coordinates of the object point used to find the chief ray
  • rt (tuple(float, float, float)) – rotations made to a ray propagating in the z direction to obtain the first test ray
  • er (float) – Maximum acceptable distance between the ray and the center of the aperture
  • w (float) – Gaussian width in radians
  • wavelength (float) – Wavelength of the ray used to find the principal ray given in micrometers (.58929 by default).
Returns:

Chief ray found. (Ray instance)

Return type:

Ray

Notes

The algorithm starts using a given ray, propagating it in the optical system, and finding the intersection point of this test ray and the aperture plane. The distance from this point and the optical axis is recorded.

Using a gaussian random generator, two rotation angles are calculated, to generate a new test ray that is propagated in the optical system, and its distance to the optical axis is found at the aperture plane. If this distance is less than the distance found for the previous ray, this ray is taken as the new chief ray candidate, and the algorithm is repeated until the number of iterations reaches maxiter, or until the distance is less than er.

the rt parameter gives the rotations made to a ray originating in o, and propagating in the Z direction, to find the first test ray.

A detector object ccds should be placed at the aperture plane. It is used to find the point where the ray intersects the aperture. To increase the convergense speed of the algorithm, it is better to make sure that the first test ray intersects the detector.

Todo

Implement a function similar to this one, using a minimization algorithm

pyoptools.raytrace.calc.find_aperture(ccd, size=(50, 50))

Function to find a mask representing the aperture

This function returns a array containing 1’s and 0’s representing the aperture shape. The aperture shape will be approximated from the CCD hit_list

Parameters:
  • ccd (CCD) – CCD object that will be used to get the shape information from
  • size (tuple(int, int)) – Array shape
Returns:

Array with the image of the aperture

Return type:

array

Todo

please describe better

Notes

Right now only works for round apertures.

Todo

please be more specific

pyoptools.raytrace.calc.find_ppp(opsys, opaxis)

Function to find the primary principal plane location of a lens or an optical component

Parameters:
  • opsys (System) – Optical system or optical component whose principal planes are to be found
  • opaxis (Ray) – Ray defining the optical axis of the system

For this function to operate, the system should have a rotational symmetry around the optical axis.

Notes

This function is returns the intersection point of the optical axis and the principal plane.

pyoptools.raytrace.calc.find_reference_sphere_radius(ip, pl)

Find the radius os the reference sphere that best fits the input data.

This method assumes that the optical axis coincides with the z axis. This means that the center of the sphere, has coordinates (0,0,r).

Parameters:
  • ip (list) – list of the points where the optical path is measured, that are being fitted. Each point is (XYZ) tuple. It can be also an array with a shape n,3 where n is the number of points.
  • pl (list) – List of path lengths. pl[i] corresponds to the point ip[i].
Returns:

Reference sphere radius

Return type:

float

pyoptools.raytrace.calc.get_optical_path_ep(opsys, opaxis, raylist, stop=None, r=None)

Returns the optical path traveled by a ray up to the exit pupil

The optical path is measured from the ray origin until it crosses the exit pupil of the system. If a stop (aperture) is not given, the measurement is made up to the primary principal plane.

Parameters:
  • opsys (System) – Optical system under analysis
  • opaxis (pyoptools.raytrace.ray.Ray) – Ray indicating the optical axis. The origin of the optical axis must be the position of the object used in the image formation. This is needed to be able to calculate the radius of the reference sphere.
  • raylist (list(pyoptools.raytrace.ray.Ray)) – List of rays that will be used to sample the optical path
  • stop (Stop) – Stop aperture of the system. It must belong to opsys. In not given it will be assumed that the exit pupil is at the primary principal plane.
  • r

    If None, measure up to the exit pupil plane. If given, use a reference sphere with a vertex coinciding with the optical vertex. .. todo:

    Need to check the function and fix this documentation
    
Returns:

  • hcl (list) – List containing the coordinates of the hits in the pupil coordinate system.
  • opl (list) – list containing the optical paths measured
  • pc (tuple(float, float, float)) – intersection point between the optical axis, and the pupil plane.

hcl[i] corresponds to opl[i]

Note: This method only works if the optical axis coincides with the Z axis. This must be corrected.

pyoptools.raytrace.calc.intersection(ray1, ray2, atol=1e-08)

Return the point of intersection between the rays ray1 and ray2.

Parameters:
  • ray2 (ray1,) – Rays to test for intersection.
  • atol (absolute tolerance (maximum distance between ray lines)) –
Returns:

  • ip (tuple(float, float, float)) – Intersection point coordinates. If the rays do not intersect ip=(nan,nan,nan)
  • rv (bool) – Indicates if the intersection point represent a real image (rv=true), or a virtual image (rv=false). In this case virtual has the same meaning as in virtual image i.e. intersection point is not in the actual path, or is behind the ray’s origin.

pyoptools.raytrace.calc.nearest_points(ray1, ray2)

Return the nearest points between 2 rays.

The image point locations in optical systems are usually found by calculating the intersection between rays coming from a single object point, but in aberrated systems, the 2 rays will not really intersect. This function is used to find the point in space where the rays are closest to each other. If the rays intersect the values returned will be the intersection point.

The solution was taken from:

Parameters:r1,r2 (Ray) – Rays to test for intersection.
Returns:
  • c1 (tuple(float, float, float)) – Coordinates of the point living on ray 1 closest to ray 2
  • c2 (tuple(float, float, float)) – Coordinates of the point living on ray 2 closest to ray 1
  • d (float) – The distance between p1 and p2
  • rv (bool) – Indicates if the intersection is real or virtual. rv=True for real, rv=False for virtual. In this case virtual has the same meaning as in virtual image i.e. c1 and c2 are not in the actual path, or are behind the ray’s origin.
pyoptools.raytrace.calc.parallel_propagate(os, r, np=None)

Perform a propagation of the rays in the system using all cores present on a computer

os gets reset before beginning the propagation, so the only rays used in the simulation are the rays given in r

Parameters:
  • os (System) – Optical system used in the simulation
  • r (list(pyoptools.raytrace.ray.Ray)) – List containing the rays to propagate
  • np (int or None) – Number of processes used in the simulation. If not given use one process per cpu
pyoptools.raytrace.calc.parallel_propagate_ns(os, rg, dp, r, np=None)

Perform a propagation of the rays in the system using all cores present on a computer

os gets reset before beginning the propagation, so the only rays used in the simulation are the rays given in r

Parameters:
  • os – Optical system used in the simulation
  • rg – Guide ray
  • dp – Destination path
  • r – List containing the rays to propagate
  • np (int or None) – Number if processes used in the simulation. If not given use one process per cpu
pyoptools.raytrace.calc.paraxial_location(opsys, opaxis)

Function to find the paraxial image location

This function finds the paraxial image location of a point located in the optical axis, and a boolean indicating if the image is real or virtual (image_location, real_virtual). The origin of the opaxis location is taken as the object location

Parameters:
  • opsys (System) – Optical system to use.
  • opaxis (Ray) – Ray representing the optical axis
Returns:

  • image_location (tuple(float, float, float)) – Image location coordinates
  • real (bool) – Indicates if the intersection point represent a real image (real=True), or a virtual image (real=False).

Note

For this function to operate, the system should have a rotational symmetry around the optical axis.

pyoptools.raytrace.calc.pupil_location(opsys, ccds, opaxis)

Function to find the optical system pupils position

Note

For this function to operate, the system should have a rotational symmetry around the optical axis.

Parameters:
Returns:

  • enpl (tuple(float, float, float)) – (xen,yen,zen) containing the entrance pupil coordinates
  • expl (tuple(float, float, float)) – (xex,yex,zex) containing the exit pupil coordinates

pyoptools.raytrace.calc.ray_paths(r)

Return lists with all the possible paths traveled by the ray r.

r must be previously propagated in an optical system

When there are beam splitters, there is more than one path

Parameters:r (pyoptools.raytrace.ray.Ray) –

Todo

Finish documentation