gtrace package

Submodules

gtrace.beam module

gtrace.beam

A module to define GaussianBeam class.

class gtrace.beam.GaussianBeam(q0=2.952624674426497j, q0x=False, q0y=False, pos=[0.0, 0.0], length=1.0, dirAngle=0.0, dirVect=None, wl=1.064e-06, P=1.0, n=1.0, name='Beam', layer='main_beam')

Bases: traits.has_traits.HasTraits

This is a class to represent a Gaussian beam. A GaussianBeam object has its origin (pos) and a propagation direction (dirVect or dirAngle). A GaussianBeam is characterized by q-parameter(s) at its origin. The beam can be either circular or elliptic. In order to deal with elliptic beams, some parameters are stored in pairs like (q0x, q0y). x and y denote the axes of the cross section of the beam. x-axis is parallel to the paper and the y-axis is perpendicular to the paper.

A beam object can be propagated through a free space or made to interact with an optics.

As a beam propagate through optical system, optical distance and Gouy phase are accumerated.

q

q-parameter of the beam. If the beam is eliptic, q is the q-parameter of the best matching circular mode.

Type

complex

qx

q-parameter of the beam in the x-direction.

Type

complex

qy

q-parameter of the beam in the y-direction.

Type

complex

pos

Position of the beam origin (x, y).

Type

array

dirVect

Propagation direction vector.

Type

array

dirAngle

Propagation direction angle measured from the positive x-axis.

Type

float

length

Length of the beam (used for DXF export)

Type

float

layer

Layer name of the beam when exported to a DXF file.

Type

str

name

Name of the beam

Type

str

wl

Wavelength in vacuum. Not the wavelength in the medium.

Type

float

n

Index of refraction of the medium the beam is passing through.

Type

float

P

Power.

Type

float

wx

Beamwidth in x-direction.

Type

float

wy

Beamwidth in y-direction.

Type

float

optDist

Accumulated optical distance.

Type

float

Gouyx

Accumulated Gouy phase in x-direction.

Type

float

Gouyy

Accumulated Gouy phase in y-direction.

Type

float

Mx

ABCD matrix in x-direction. This is a 2x2 matrix representing the product of ABCD transformations applied to this beam. It defaults to an identity matrix. Whenever a beam experience an ABCD matrix transformation, such as propagation in the space or reflection by a curved mirror, the applied ABCD matrix is multiplied to this matrix, so that we can keep track of what kind of transformations were made during beam propagation.

Type

array

My

ABCD matrix in y-direction. The meaning is the same as Mx.

Type

array

departSurfAngle

The angle formed by x-axis and the normal vector of the surface from which the beam is departing. Default is None. Used by the drawing routine.

Type

None

departSurfInvROC

Inverse of the ROC of the surface from which the beam is departing. The ROC is positive for a concave surface seen from the beam side. Default is None. Used by the drawing routine.

Type

None

incSurfAngle

The angle formed by the x-arm and the normal vector of the surface to which the beam is incident. Default is None. Used by the drawing routine.

Type

None

incSurfInvROC

Inverse of the ROC of the surface to which the beam is incident. The ROC is positive for a concave surface seen from the beam side. Default is None. Used by the drawing routine.

Type

None

stray_order

An integer indicating if this beam is a stray light or not. The default value is 0. Every time a beam is reflected by an AR surface or transmits an HR surface, this couter is increased by 1.

Type

int

ABCDTrans(ABCDx, ABCDy=None)

Apply ABCD transformation to the beam.

Parameters
  • ABCDx (array) – ABCD matrix for x-direction.

  • ABCDy (array or None, optional.) – ABCD matrix for y-direction. Defaults None. If None, set to ABCDx.

R(dist=0.0)

Returns the beam ROC at a distance dist from the origin of the beam.

Parameters

dist (float, optional) – Distance.

Returns

Beam ROC.

Return type

(float, float)

copy()

Make a deep copy.

draw(cv, sigma=3.0, mode='x', drawWidth=True, fontSize=False, drawPower=False, drawROC=False, drawGouy=False, drawOptDist=False, drawName=False, debug=False)

Draw the beam into a DXF object.

Parameters
  • cv (gtrace.draw.draw.Canvas) – gtrace canvas.

  • sigma (float, optional) – The width of the beam drawn is sigma * (1/e^2 radius of the beam). The default is sigma = 3. sigma = 2.7 gives 1ppm diffraction loss. Defaults 3.

  • mode (str, optional) – ‘avg’, ‘x’, or ‘y’. A beam can have different widths for x- and y- directions. If ‘avg’ is specified, the average of them are drawn. ‘x’ and ‘y’ specifies to show the width of the respective directions. Defaults ‘x’.

  • fontSize (float, optional) – Size of the font used to show supplemental informations. Defaults False.

  • drawWidth (boolean, optional) – Whether to draw width or not. Defaults True.

  • drawPower (boolean, optional) – Whether to show the beam power. Defaults False.

  • drawROC (boolean, optional) – Whether to show the ROC or not. Defaults False.

  • drawGouy (boolean, optional) – Whether to show the Gouy phase or not. Defaults False.

  • drawOptDist (boolean, optional) – Whether to show the accumulated optical distance or not. Defaults False.

  • drawName (boolean, optional) – Whether draw the name of the beam or not. Defaults False.

  • debug (boolean, optional) – Debug.

drawWidth(cv, sigma, mode)

Draw width on canvas.

Parameters
  • cv (gtrace.draw.draw.Canvas) – The canvas.

  • sigma (float) – The width of the beam drawn is sigma * (1/e^2 radius of the beam). The default is sigma = 3. sigma = 2.7 gives 1ppm diffraction loss.

  • mode (str) – ‘avg’, ‘x’, or ‘y’. A beam can have different widths for x- and y- directions. If ‘avg’ is specified, the average of them are drawn. ‘x’ and ‘y’ specifies to show the width of the respective directions.

flip(flipDirVect=True)

Change the propagation direction of the beam by 180 degrees. This is equivalent to the reflection of the beam by a spherical mirror with the same ROC as the beam.

If optional argument flipDirVect is set to False, the propagation direction of the beam is not changed.

Parameters

flipDirVect (boolean, optional) – Flip propagation direction. Defaults True.

propagate(d)

Propagate the beam by a distance d from the current position. self.n is used as the index of refraction. During this process, the optical distance traveled is added to self.optDist. self.Goux and self.Gouyy are also updated to record the Gouy phase change.

Parameters

d (float) – Distance.

rotate(angle, center=False)

Rotate the beam around ‘center’. If center is not given, the beam is rotated around self.pos.

Parameters
  • angle (float) – Rotation angle in radians.

  • center (array or boolean.) – Center of rotation. Should be an array of shape(2,). Defaults False.

translate(trVect)

Translate the beam by the direction and the distance specified by a vector.

Parameters

trVect (array) – A vector to specify the translation direction and distance. Should be an array of shape(2,)

waist()

Return the tuples of waist size and distance

Returns

{“Waist Size”: (float, float), “Waist Position”: (float, float)}

Return type

dict

width(dist)

Returns the beam width at a distance dist from the origin of the beam. The width is the radius where the light power becomes 1/e^2.

Parameters

dist (float) – Distance.

Returns

The width of the beam in x and y direction.

Return type

(float, float)

gtrace.beam.optFunForEndPointR(phi, Mrot, R, q0, k, sigma, side)

A function to return the distance between the point on the spherical surface at an angle phi and the beam width at the same z.

Parameters
  • phi (float) – phi

  • Mrot (array) – Rotational transformation.

  • R (float) – R

  • q0 (complex) – Beam parameter.

  • k (float) – k

  • sigma (float) – Beam width

  • side – side

Returns

Distance between the point on the spherical surface at an angle phi and the beam width at the same z.

Return type

float

gtrace.beam.optFunForFlat(a, Mrot, q0, k, sigma, side)

A function to return the distance between the point on the spherical surface (flat?) at an angle phi and the beam width at the same z.

Parameters
  • a (float) – a

  • Mrot (array) – Rotational transformation.

  • q0 (complex) – Beam parameter.

  • k (float) – k

  • sigma (float) – Beam width

  • side – side

Returns

Distance between the point on the spherical surface at an angle phi and the beam width at the same z.

Return type

float

gtrace.beam.optFunForStartPointR(phi, Mrot, R, q0, k, sigma, side)

A function to return the distance between the point on the spherical surface at an angle phi and the beam width at the same z.

Parameters
  • phi (float) – phi

  • Mrot (array) – Rotational transformation.

  • R (float) – R

  • q0 (complex) – Beam parameter.

  • k (float) – k

  • sigma (float) – Beam width

  • side – side

Returns

Distance between the point on the spherical surface at an angle phi and the beam width at the same z.

Return type

float

gtrace.beam.optimCrossPointFlat(theta, q0, k, sigma)

Caltulate optimal cross point.

thetafloat

theta

Rfloat

R

q0complex

Beam parameter.

kfloat

k

sigmafloat

Beam width.

Returns

Optimal end point.

Return type

(float, float)

gtrace.beam.optimEndPointR(theta, R, q0, k, sigma)

Caltulate optimal end point.

thetafloat

theta

Rfloat

R

q0complex

Beam parameter.

kfloat

k

sigmafloat

Beam width.

Returns

Optimal end point.

Return type

(float, float)

gtrace.beam.optimStartPointR(theta, R, q0, k, sigma)

Caltulate optimal starting point.

thetafloat

theta

Rfloat

R

q0complex

Beam parameter.

kfloat

k

sigmafloat

Beam width.

Returns

Optimal starting point.

Return type

(float, float)

gtrace.hello module

gtrace.nonsequential module

gtrace.nonsequential

A module to perform non-sequential trace of a beam in an optical system.

gtrace.nonsequential.non_seq_trace(optList, src_beam, order=10, power_threshold=0.1, open_beam_length=1.0)

Perform non-sequential trace of the source beam, src_beam, through the optical system represented by a collection of optics, optList.

Parameters
  • optList (list of gtrace.optcomp.Optics) – List of optical components.

  • src_beam (gtrace.beam.GaussianBeam) – The source beam object.

  • order (int, optional) – An integer to specify how many times the internal reflections are computed. Defaults to 10.

  • power_threshold (float, optional) – The power threshold for internal reflection calculation. If the power of an auxiliary beam falls below this threshold, further propagation of this beam will not be performed. Defaults to 0.1.

  • open_beam_length (float, optional) – The default length for beams that are not hitting anything. Defaults to 1.0.

Returns

terminated_beam_list – A list of beams.

Return type

list of gtrace.beam.GaussianBeam

gtrace.optcomp module

Define optical components for gtrace.

class gtrace.optcomp.CyMirror(HRcenter=[0.0, 0.0], normAngleHR=0.0, normVectHR=None, diameter=0.25, thickness=0.15, wedgeAngle=0.004363323129985824, inv_ROC_HR=0.00014285714285714287, inv_ROC_AR=0.0, Refl_HR=0.99, Trans_HR=0.01, Refl_AR=0.01, Trans_AR=0.99, n=1.45, name='Mirror', HRtransmissive=False, term_on_HR=False, curve_direction='h')

Bases: gtrace.optcomp.Mirror

Representing a partial reflective cylindrical mirror. Note that both HR and AR surfaces are treated as cylindrical if you specify non-zero ROC for them. The curve directions of the two surfaces must be the same.

curve_direction

Either ‘h’ or ‘v’. If it is ‘h’ the mirror is curved in horizontal plane. If ‘v’, it is vertical.

Type

str

HRcenter

The position of the center of the arc of the HR surface. shape(2,).

Type

array

HRcenterC

The position of the center of the chord of the HR surface. shape(2,).

Type

array

normVectHR

Normal vector of the HR surface. shape(2,)

Type

array

normAngleHR

Angle of the HR normal vector. In radians.

Type

float

ARcenter

The position of the center of the AR surface. shape(2,)

Type

array

normVectAR

Normal vector of the HR surface. shape(2,)

Type

array

normAngleAR

Angle of the HR normal vector. In radians.

Type

float

HRtransmissive

A boolean value defaults to False. If True, this mirror is supposed to transmit beams on the HR surface. Therefore, for the first encounter of a beam on the HR surface of this mirror will not increase the stray_order. This flag should be set to True for beam splitters and input test masses.

Type

boolean

term_on_HR

If this is True, a beam with stray_order <= self.term_on_HR_order will be terminated when it hits on HR. This is to avoid the inifinite loop of non-sequencial trace by forming a cavity.

Type

boolean

term_on_HR_order

Integer to specify the upper limit of the stray order used to judge whether to terminate the non sequential trace or not on HR reflection.

Type

int

copy()
draw(cv, drawName=False)

Draw itself

get_side_info()

Return information on the sides of the mirror. Returned value is a list of two tuples like [(center1, normVect1, length1), (center2, normVect2, length2)] Each tuple corresponds to a side. center1 is the coordinates of the center of the side line. normVect1 is the normal vector of the side line. length1 is the length of the side line.

Returns

Return type

[(float, float, float), (float, float, float)]

hitFromAR(beam, order=0, threshold=0.0, verbose=False)

Compute the reflected and deflected beams when an input beam hit the AR surface.

The internal reflections are computed as long as the number of internal reflections are below the order and the power of the reflected beams is over the threshold.

Parameters
  • beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

  • order (int, optional) – An integer to specify how many times the internal reflections are computed. Defaults 0.

  • threshold (float, optional) – The power threshold for internal reflection calculation. If the power of an auxiliary beam falls below this threshold, further propagation of this beam will not be performed. Defaults 0.0.

  • verbose (boolean, optional) – Print useful information.

Returns

beams – Dictionary of reflected and deflected beams.

Return type

dict

hitFromHR(beam, order=0, threshold=0.0, verbose=False)

Compute the reflected and deflected beams when an input beam hit the HR surface.

The internal reflections are computed as long as the number of internal reflections are below the order and the power of the reflected beams is over the threshold.

Parameters
  • beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

  • order (int, optional) – An integer to specify how many times the internal reflections are computed. Defaults 0.

  • threshold (float, optional) – The power threshold for internal reflection calculation. If the power of an auxiliary beam falls below this threshold, further propagation of this beam will not be performed. Defaults 0.0.

  • verbose (boolean, optional) – Print useful information.

Returns

beams – Dictionary of reflected and deflected beams.

Return type

dict

isHit(beam)

A function to see if a beam hits this optics or not.

Parameters

beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

Returns

The return value is a dictionary with the following keys: isHit, position, distance, face

isHit: This is a boolean to answer whether the beam hit the optics or not.

position: A numpy array containing the coordinate values of the intersection point between the beam and the optics. If isHit is False, this parameter does not mean anything.

distance The distance between the beam origin and the intersection point.

face: An optional string identifying which face of the optics was hit. For example, face can be either “HR” or “AR” for a mirror. face can also be “side”, meaning that the beam hits a side of the optics, which is not meant to be used, e.g. the side of a mirror. In this case, the beam have reached a dead end.

Return type

Dict

class gtrace.optcomp.Mirror(HRcenter=[0.0, 0.0], normAngleHR=0.0, normVectHR=None, diameter=0.25, thickness=0.15, wedgeAngle=0.004363323129985824, inv_ROC_HR=0.00014285714285714287, inv_ROC_AR=0.0, Refl_HR=0.99, Trans_HR=0.01, Refl_AR=0.01, Trans_AR=0.99, n=1.45, name='Mirror', HRtransmissive=False, term_on_HR=False)

Bases: gtrace.optcomp.Optics

Representing a partial reflective mirror.

curve_direction

Either ‘h’ or ‘v’. If it is ‘h’ the mirror is curved in horizontal plane. If ‘v’, it is vertical.

Type

str

HRcenter

The position of the center of the arc of the HR surface. shape(2,).

Type

array

HRcenterC

The position of the center of the chord of the HR surface. shape(2,).

Type

array

normVectHR

Normal vector of the HR surface. shape(2,)

Type

array

normAngleHR

Angle of the HR normal vector. In radians.

Type

float

ARcenter

The position of the center of the AR surface. shape(2,)

Type

array

normVectAR

Normal vector of the HR surface. shape(2,)

Type

array

normAngleAR

Angle of the HR normal vector. In radians.

Type

float

HRtransmissive

A boolean value defaults to False. If True, this mirror is supposed to transmit beams on the HR surface. Therefore, for the first encounter of a beam on the HR surface of this mirror will not increase the stray_order. This flag should be set to True for beam splitters and input test masses.

Type

boolean

term_on_HR

If this is True, a beam with stray_order <= self.term_on_HR_order will be terminated when it hits on HR. This is to avoid the inifinite loop of non-sequencial trace by forming a cavity.

Type

boolean

term_on_HR_order

Integer to specify the upper limit of the stray order used to judge whether to terminate the non sequential trace or not on HR reflection.

Type

int

copy()
draw(cv, drawName=False)

Draw itself

get_side_info()

Return information on the sides of the mirror. Returned value is a list of two tuples like [(center1, normVect1, length1), (center2, normVect2, length2)] Each tuple corresponds to a side. center1 is the coordinates of the center of the side line. normVect1 is the normal vector of the side line. length1 is the length of the side line.

Returns

Return type

[(float, float, float), (float, float, float)]

hit(beam, order=0, threshold=0.0, face=False)

A function to hit the optics with a beam.

This function attempts to hit the optics with the source beam, beam.

Parameters
  • beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

  • order (int, optional) – An integer to specify how many times the internal reflections are computed. Defaults 0.

  • threshold (float, optional) – The power threshold for internal reflection calculation. If the power of an auxiliary beam falls below this threshold, further propagation of this beam will not be performed. Defaults 0.0.

Returns

(isHit, beamDict, face)

isHit This is a boolean to answer whether the beam hit the optics or not.

beamDict A dictionary containing resultant beams.

face:

An optional string identifying which face of the optics was hit. For a mirror, face is any of “HR”, “AR” or “side”.

Return type

{boolean, dict, str}

hitFromAR(beam, order=0, threshold=0.0, verbose=False)

Compute the reflected and deflected beams when an input beam hit the AR surface.

The internal reflections are computed as long as the number of internal reflections are below the order and the power of the reflected beams is over the threshold.

Parameters
  • beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

  • order (int, optional) – An integer to specify how many times the internal reflections are computed. Defaults 0.

  • threshold (float, optional) – The power threshold for internal reflection calculation. If the power of an auxiliary beam falls below this threshold, further propagation of this beam will not be performed. Defaults 0.0.

  • verbose (boolean, optional) – Print useful information.

Returns

beams – Dictionary of reflected and deflected beams.

Return type

dict

hitFromHR(beam, order=0, threshold=0.0, verbose=False)

Compute the reflected and deflected beams when an input beam hit the HR surface.

The internal reflections are computed as long as the number of internal reflections are below the order and the power of the reflected beams is over the threshold.

Parameters
  • beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

  • order (int, optional) – An integer to specify how many times the internal reflections are computed. Defaults 0.

  • threshold (float, optional) – The power threshold for internal reflection calculation. If the power of an auxiliary beam falls below this threshold, further propagation of this beam will not be performed. Defaults 0.0.

  • verbose (boolean, optional) – Print useful information.

Returns

beams – Dictionary of reflected and deflected beams.

Return type

dict

isHit(beam)

A function to see if a beam hits this optics or not.

Parameters

beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

Returns

The return value is a dictionary with the following keys: isHit, position, distance, face

isHit: This is a boolean to answer whether the beam hit the optics or not.

position: A numpy array containing the coordinate values of the intersection point between the beam and the optics. If isHit is False, this parameter does not mean anything.

distance The distance between the beam origin and the intersection point.

face: An optional string identifying which face of the optics was hit. For example, face can be either “HR” or “AR” for a mirror. face can also be “side”, meaning that the beam hits a side of the optics, which is not meant to be used, e.g. the side of a mirror. In this case, the beam have reached a dead end.

Return type

Dict

rotate(angle, center=False)

Rotate the mirror. If center is not specified, the center of rotation is HRcenter. If center is given (as a vector), the center of rotation is center. center is a position vector in the global coordinates.

Parameters
  • angle (float) – Angle of rotation.

  • center (array or boolean, optional) – Center of rotation, or False.

translate(trVect)
class gtrace.optcomp.Optics

Bases: traits.has_traits.HasTraits

A general optics class from which other specific optics classes are derived.

name

Name of the optics.

Type

str

center

Center position of the optics. array of shape(2,).

Type

array

rotationAngle

This angle defines the orientation of the optics.

Type

float

hit(order=0, threshold=0.0)

A function to hit the optics with a beam.

This function attempts to hit the optics with the source beam, beam.

Parameters
  • beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

  • order (int, optional) – An integer to specify how many times the internal reflections are computed. Defaults 0.

  • threshold (float, optional) – The power threshold for internal reflection calculation. If the power of an auxiliary beam falls below this threshold, further propagation of this beam will not be performed. Defaults 0.0.

Returns

(isHit, beamDict, face)

isHit This is a boolean to answer whether the beam hit the optics or not.

beamDict A dictionary containing resultant beams.

face:

An optional string identifying which face of the optics was hit. For a mirror, face is any of “HR”, “AR” or “side”.

Return type

{boolean, dict, str}

isHit()

A function to see if a beam hits this optics or not.

Parameters

beam (gtrace.beam.GaussianBeam) – A GaussianBeam object to be interacted by the optics.

Returns

The return value is a dictionary with the following keys: isHit, position, distance, face

isHit: This is a boolean to answer whether the beam hit the optics or not.

position: A numpy array containing the coordinate values of the intersection point between the beam and the optics. If isHit is False, this parameter does not mean anything.

distance The distance between the beam origin and the intersection point.

face: An optional string identifying which face of the optics was hit. For example, face can be either “HR” or “AR” for a mirror. face can also be “side”, meaning that the beam hits a side of the optics, which is not meant to be used, e.g. the side of a mirror. In this case, the beam have reached a dead end.

Return type

Dict

gtrace.unit module

gtrace.unit.deg2rad(deg)
gtrace.unit.rad2deg(rad)

Module contents

This package provides necessary classes and functions for tracing the propagation of Gaussian beams among mirrors and lenses.