finesse.gaussian module
Gaussian beam related tools and utilities.
- class finesse.gaussian.BeamParam(wavelength=None, nr=1, *args, **kwargs)[source]
Bases:
objectGaussian beam complex parameter.
This can be a symbolic beam parameter or numeric. For example, if
transform_beam_param()is called using a symbolic ABCD matrix then a symbolic BeamParam instance will be created automatically.The wavelength of the laser beam defaults to the current value for
lambda0in the config file being used, if it is not given as an argument during construction of a BeamParam.The index of refraction of the associated medium defaults to unity, if it is not given as an argument during construction of a BeamParam.
The following are legal initialisations of a BeamParam object:
q = BeamParam(w0=w0, z=z) q = BeamParam(z=z, zr=zr) q = BeamParam(w=w, rc=rc) q = BeamParam(w=w, S=S) q = BeamParam(q=c) # where c is a complex number or symbol
Descriptions of these variables are as follows:
\(z\) — distance to the waist position (in metres). Negative values indicate a beam converging to the waist, positive is a beam diverging from the waist.
\(w_0\) — radius of the beam at the waist (in metres).
\(zr\) — Rayleigh range of the beam (in metres).
\(w\) — radius of the beam at the current position (in metres).
\(rc\) — radius of curvature of the wavefront (in metres).
\(S\) — curvature (or defocus) of the wavefront (in metres).
\(q\) — the complex beam parameter itself.
The default wavelength and refractive index values can also be changed with (for example):
q = BeamParam(wavelength, nr, w0=w0, zr=zr)
Note that BeamParam objects can also be symbolic by passing any value in *args or **kwargs as a symbolic expression.
Parameters
- wavelengthfloat, optional
Wavelength of the beam light, defaults to the value given for
lambda0in the config file being used.- nrfloat, optional
Refractive index, defaults to unity.
- property Rc[source]
Radius of curvature, \(R_c\), of the beam, in metres.
Computed as,
\[R_c = z \left(1 + \left(\frac{z_R}{z}\right)^2\right),\]where \(z\) is the distance to the waist position (given by
BeamParam.z, orBeamParam.real) and \(z_R\) is the Rayleigh range (given byBeamParam.zr, orBeamParam.imag).Note that if \(z = 0\) then this will return
np.inf.Hint
Use
BeamParam.roc()to compute the radius of curvature as a function of any of the above dependent arguments.- Getter:
Returns the beams’ radius of curvature. Read-only.
- property S[source]
Defocus (wavefront curvature), \(S\), of the Gaussian beam, equivalent to the reciprocal of
BeamParam.Rc.Computed as,
\[S = \frac{z}{z^2 + z_R^2},\]where \(z\) is the distance to the waist position (given by
BeamParam.z, orBeamParam.real) and \(z_R\) is the Rayleigh range (given byBeamParam.zr, orBeamParam.imag).Hint
Use
BeamParam.curvature()to compute the curvature as a function of any of the above dependent arguments.- Getter:
Returns the defocus of the beam parameter. Read-only.
- beamsize(z=None, wavelength=None, nr=None, w0=None)[source]
Computes the radius of the beam as a function of any of the dependent arguments.
Calling this method with no arguments is equivalent to accessing
BeamParam.w.Parameters
- zfloat, optional
Distance along optical axis relative to waist, defaults to
BeamParam.zfor this beam parameter.- wavelengthfloat, optional
Wavelength of the beam to use, defaults to
BeamParam.wavelengthfor this beam parameter.- nrfloat, optional
Refractive index to use, defaults to
BeamParam.nrfor this beam parameter.- w0float, optional
Waist-size of the beam, defaults
BeamParam.w0for this beam parameter.
Returns
The radius of the beam using the specified properties.
- conjugate()[source]
Computes and returns the complex conjugate of the beam parameter.
Returns
- q_conj
BeamParam The complex conjugate of this BeamParam instance.
- q_conj
- curvature(z=None, wavelength=None, nr=None, w0=None)[source]
Curvature of the beam wavefront as a function of any of the dependent arguments.
Calling this method with no arguments is equivalent to accessing
BeamParam.S.Parameters
- zfloat, optional
Distance along optical axis relative to waist, defaults to
BeamParam.zfor this beam parameter.- wavelengthfloat, optional
Wavelength of the beam to use, defaults to
BeamParam.wavelengthfor this beam parameter.- nrfloat, optional
Refractive index to use, defaults to
BeamParam.nrfor this beam parameter.- w0float, optional
Waist-size of the beam, defaults
BeamParam.w0for this beam parameter.
Returns
Curvature of the beam using the specified properties.
- depends_on()[source]
A list of the model parameters that the symbolic beam parameter depends upon.
If this beam parameter is not symbolic, then an empty list is returned.
- property divergence[source]
Divergence of the beam.
The divergence is defined as,
\[d = \frac{\lambda}{w_0 \pi},\]where \(\lambda\) is the wavelength and \(w_0\) is the waist size of the beam.
- Getter:
Returns the beam divergence. Read-only.
- eval(as_bp=True, subs=None, keep=None)[source]
Evaluate the symbolic beam parameter. Parameter substitutions can be performed via the substitution dict subs.
Note that this simply returns
BeamParam.qif this is not symbolic.Parameters
- as_bpbool, optional; default: True
Flag indicating whether to return result as a
BeamParaminstance.- subsdict, optional; default: None
Dictionary of parameter substitutions.
- keepiterable, str
A collection of names of variables to keep as variables when evaluating.
- gouy(z=None, wavelength=None, nr=None, w0=None)[source]
Computes the Gouy-phase as a function of any of the dependent arguments.
Parameters
- zfloat, optional
Distance along optical axis relative to waist, defaults to
BeamParam.zfor this beam parameter.- wavelengthfloat, optional
Wavelength of the beam to use, defaults to
BeamParam.wavelengthfor this beam parameter.- nrfloat, optional
Refractive index to use, defaults to
BeamParam.nrfor this beam parameter.- w0float, optional
Waist-size of the beam, defaults
BeamParam.w0for this beam parameter.
Returns
The instantaneous Gouy phase (atan2(z/zr)) using the specified properties.
Hint
Use
tracing.tools.propagate_beam()to compute the accumulated Gouy phase over a path
- property imag[source]
The imaginary part of the complex beam parameter, equal to the Rayleigh range \(z_R\) of the beam (in metres).
- Getter:
Returns the imaginary part of the beam parameter.
- Setter:
Sets the imaginary part of the beam parameter.
- static mismatch(q1, q2)[source]
Computes the mode mismatch via an alternate form of \(1 - \mathcal{O}\), where \(\mathcal{O}\) is the overlap (see
BeamParam.overlap()).This method is less susceptible to floating point errors than simply \(1 - \mathcal{O}\) for very small mismatches. The exact form of the quantity computed is,
\[\mathcal{M} = \frac{|q_1 - q_2|^2}{|q_1 - q_2^*|^2}. \]The return value is \(\mathcal{M} \in [0, 1]\), where 0 implies full mode matching and 1 indicates complete mode mismatch.
Parameters
Returns
- mismatchfloat, array-like,
Symbol The mismatch between q1 and q2 as defined above.
- mismatchfloat, array-like,
- property nr[source]
The refractive index associated with the BeamParam.
- Getter:
Returns the index of refraction.
- Setter:
Sets the index of refraction.
- static overlap(q1, q2)[source]
Computes the projection from one beam parameter to another to give a measure of the overlap between the two beam parameters. The quantity computed is,
\[\mathcal{O} = \frac{4|\Im{\{q_1\}}\,\Im{\{q_2\}}|}{|q_1^* - q_2|^2}. \]The return values is \(\mathcal{O} \in [0, 1]\), where 0 implies complete mode mismatch and 1 indicates full mode matching.
This function was provided by Paul Fulda and Antonio Perreca, which came originally from Chris Mueller.
Parameters
- q1
BeamParam, complex, array-like First beam parameter. Note that this can be a numeric or symbolic beam parameter, a complex number or an array of complex values.
- q2
BeamParam Second beam parameter. Note that this can be a numeric or symbolic beam parameter, a complex number or an array of complex values.
Returns
- overlapfloat, array-like,
Symbol The overlap between q1 and q2 as defined above.
- q1
- static overlap_contour(q1, M, t)[source]
This function returns a set of beam parameters that are mismatched to q1 by an overlap M. There are multiple beam parameters that can be X% overlapped with one particular q value. This function is parameterised with t from 0 to 2pi, which can provide all the possible beam parameters that are M% mismatched.
Parameters
- q1
BeamParamor tuple reference beam parameter, can be a tuple of (qx,qy) beam parameters
- Mfloat
Mismatch factor (1-overlap) [0 -> 1]
- tfloat
Selection parameter [0 -> 2pi]
Examples
Plots the contours of mismatch for 0.1% and 1% from some initial q value:
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> import finesse >>> >>> qin = finesse.BeamParam(w0=1e-3, z=20) >>> t = np.linspace(0, 2*np.pi, 100) >>> >>> # use vectorised functions to select a cerain property of the beam paramters >>> vx = np.vectorize(lambda q: q.z) >>> vy = np.vectorize(lambda q: q.w/1e-3) >>> >>> for mm in [1e-3, 2e-2]: >>> mmc = finesse.BeamParam.overlap_contour(qin, mm, t) >>> plt.text(vx(mmc[20]), vy(mmc[20]), "%1.1f%%" % ((mm*100)),alpha=0.5, fontsize=8) >>> l, = plt.plot(vx(mmc), vy(mmc), ls='--', alpha=0.2, zorder=-10, c='k') >>> >>> plt.show()
- q1
- property psi[source]
Gouy phase, \(\psi\), of the Gaussian beam.
Computed as,
\[\psi = \arctan{\left(\frac{z}{z_R}\right)},\]where \(z\) is the distance to the waist position (given by
BeamParam.z, orBeamParam.real) and \(z_R\) is the Rayleigh range (given byBeamParam.zr, orBeamParam.imag).Hint
Use
BeamParam.gouy()to compute the Gouy phase as a function of any of the above dependent arguments.- Getter:
Returns the Gouy phase (in radians) of the beam parameter. Read-only.
- property q[source]
The complex beam parameter value (\(q\)).
- Getter:
Returns the complex beam parameter value.
- property real[source]
The real part of the complex beam parameter, equal to the relative distance to the beam waist (in metres).
- Getter:
Returns the real part of the beam parameter.
- Setter:
Sets the real part of the beam parameter.
- reverse()[source]
Returns the reversed beam parameter.
This is the beam parameter with the sign of the distance to waist flipped, i.e. \(q_r = -q^*\) where \(q_r\) is the reversed beam parameter.
Returns
- q_r
BeamParam The reverse of this beam parameter.
- q_r
- roc(z=None, wavelength=None, nr=None, w0=None)[source]
Radius of curvature of the beam as a function of any of the dependent arguments.
Calling this method with no arguments is equivalent to accessing
BeamParam.Rc.Parameters
- zfloat, optional
Distance along optical axis relative to waist, defaults to
BeamParam.zfor this beam parameter.- wavelengthfloat, optional
Wavelength of the beam to use, defaults to
BeamParam.wavelengthfor this beam parameter.- nrfloat, optional
Refractive index to use, defaults to
BeamParam.nrfor this beam parameter.- w0float, optional
Waist-size of the beam, defaults
BeamParam.w0for this beam parameter.
Returns
Radius of curvature of the beam using the specified properties.
- property symbolic[source]
Flag indicating whether the beam parameter is a symbolic object.
- Getter:
True if symbolic, false otherwise (read-only).
- transform(ABCD, nr1=1, nr2=1)[source]
Applies a Gaussian beam propagator ABCD matrix to this beam parameter and returns the transformed result.
Parameters
- ABCDarray_like
2x2 ABCD matrix
- nr1, nr2float
refractive index on input and output
Returns
Transformed
BeamParam
- property w[source]
The radius of the beam, \(w\), in metres.
Computed as,
\[w = |q|\,\sqrt{\frac{\lambda}{n_r \pi z_R}},\]where \(q\) is the complex beam parameter (given by
BeamParam.q), \(\lambda\) is the beam wavelength (given byBeamParam.wavelength), \(n_r\) is the refractive index of the associated medium (given byBeamParam.nr) and \(z_R\) is the Rayleigh range (given byBeamParam.zr, orBeamParam.imag).Hint
Use
BeamParam.beamsize()to compute the beam size as a function of any of the above dependent arguments.- Getter:
Returns the radius, often denoted as “beam-size”, of the beam. Read-only.
- property w0[source]
The radius of the waist, \(w_0\), of the beam, in metres.
Computed as,
\[w_0 = \sqrt{\frac{z_R \lambda}{n_r \pi}},\]where \(z_R\) is the Rayleigh range (given by
BeamParam.zr, orBeamParam.imag), \(\lambda\) is the beam wavelength (given byBeamParam.wavelength) and \(n_r\) is the refractive index of the associated medium (given byBeamParam.nr).- Getter:
Returns the beam waist-size.
- Setter:
Sets the beam waist-size.
- property wavelength[source]
The wavelength of the beam (in metres).
- Getter:
Returns the wavelength of the beam.
- Setter:
Sets the wavelength of the beam.
- class finesse.gaussian.HGMode(q, n=0, m=0)[source]
Bases:
objectAn object representation of a Hermite-Gauss mode.
Parameters
- q
BeamParamor complex, or length two sequence of The beam parameter. Specify a tuple of (qx, qy) as this argument for an astigmatic beam.
- nint, optional; default: 0
Tangential mode index.
- mint, optional; default: 0
Sagittal mode index.
- q
- finesse.gaussian.analytic_un(n: int, x: ndarray, qx: BeamParam) ndarray[source]
Direct translation of Equation (9.34) from:
‘Interferometer Techniques for Gravitational Wave Detection’
Mostly for comparison, for faster calculations use the
finesse.gaussian.HGModeclass above.Parameters
- nint
Hermite polynomials order
- xnp.ndarray
Spatial coordinates
- qxBeamParam
Beam parameter
Returns
- np.ndarray
Hermite-gauss mode
- finesse.gaussian.optimise_HG00_q(e, q, homs, max_iterations=100, accuracy=1e-09, return_field=False)[source]
Computes the optimal complex beam parameter to describe an optical field, described by a vector of HG modes. This optimisation assumes that the field to be optimised is approximately a HG00 beam shape.
Parameters
- earray_like
Array of complex HG mode amplitudes to be optimised
- q[complex |
finesse.gaussian.BeamParam] or tuple x and y complex beam parameter basis that e is in. If a singular value is given qx=qy, else (qx, qy) should be provided.
- homslist(tuple(n, m))
List of HG mode indices for each element in e
- max_iterationsint, optional
Maximum number of iterations to try before raising a RuntimeError
- accuracyfloat, optional
level to suppress HG20 and HG02 modes to
- return_fieldbool, optional
When True the optimised array of HG modes is returned
Returns
- qx, qy(
finesse.gaussian.BeamParam,finesse.gaussian.BeamParam) Optimised beam parameters
- endarray
optimised HG mode amplitude array, only when return_field == True
Raises
- ConvergenceException
If the maximum number of iterations is reached.
Notes
The algorithm is fairly simple: assuming an approximatly HG00 beam described by a vector of HG modes has the wrong basis, it will have less HG00 amplitude and more HG20 and HG02 modes. The optimal basis is then finding {qx, qy} which reduces the amount of HG20 and HG02.
This algorithm is iterative and takes linear steps towards the correct {qx, qy} using the amount of HG20 and HG02 present. The next q to try is given by:
\[\frac{-4 a Z_r}{i\sqrt{2}} + q \]Where \(a\) is the amplitude of the HG20 or HG02 for x and y optimisation in each direction. The above is reached by the coupling coefficient k_00->02 and determining how much amplitude is expected for a given mismatch, then reverting it.
When using a finite number of modes to describe some mismatched beam some level of information is lost and not retrievable with this method. For large mismatches it may not be possible to optimise back to the true beam parameters.
For example, consider describing a mismatched beam up to order 6 HG modes. A mismatched beam will scatter the 6th order modes into the 8th which are not included in the description of the beam, therefore the information is lost. When performing this inverse the 8th order mode information cannot be brought back to fix the 6th order mode. The result is that this method may not reduce higher order terms.
- finesse.gaussian.optimise_HG00_q_scipy(e, q, homs, accuracy=1e-06, fix_spot_size=False, astigmatic=False, full_output=False, method='nelder-mead')[source]
Computes the optimal complex beam parameter to describe an optical field, described by a vector of HG modes. This optimisation assumes that the field to be optimised is approximately a HG00 beam shape.
The algorithm maximises the amount of HG00 present in a beam by varying the x and y complex beam parameter.
Parameters
- earray_like
Array of complex HG mode amplitudes to be optimised
- q[complex |
finesse.gaussian.BeamParam] or tuple x and y complex beam parameter basis that e is in. If a singular value is given qx=qy, else (qx, qy) should be provided.
- homslist(tuple(n, m))
List of HG mode indices for each element in e
- accuracyfloat, optional
level to suppress HG20 and HG02 modes to
- fix_spot_sizebool, optional
When True a non-linear optimiser is used and keeps the spot sized fixed to its current value. Useful for when you expect just the curvature of a beam to be changing. Default, False.
- astigmaticbool, optional
When True the x and y beam parameters will be optimised separately. If you know they should be equal then set this to False. Default False.
- full_outputbool, optional
When True, a dictionary with the optimized array of HG modes and the result returned by the scipy minimize function is returned. Default False.
- methodstr, optional
Optimization method used by scipy, Default ‘nelder-mead’
Returns
- qx, qy(
finesse.gaussian.BeamParam,finesse.gaussian.BeamParam) Optimised beam parameters
- retdict
When full_output is True, a dictionary with entries
‘field’: optimized GH mode amplitude array
‘res’: Scipy fit result
- finesse.gaussian.transform_beam_param(ABCD, q1, nr1=1, nr2=1)[source]
Transforms a beam parameter q1 by the matrix ABCD.
The value of the new beam parameter returned is given by the Kogelnik transformation,
\[q_2 = n_{r,2} \frac{A \frac{q_1}{n_{r,1}} + B}{ C \frac{q_1}{n_{r_1}} + D}, \]where \(A\), \(B\), \(C\), \(D\) are the corresponding elements of the ABCD matrix, and \(n_{r,1}\), \(n_{r,2}\) are the refractive indices of the source and target media respectively.
Note
The method
Model.propagate_beam()should be preferred over this in most cases, as it will automatically take into account refractive indices of spaces. With that method, you can simply specify the input and output nodes associated with the component you want to transform over and get back aPropagationSolutioninstance on which you can find the resulting beam parameter withPropagationSolution.q().This function is more intended for array-calculations (i.e. where q1 is an array of beam parameters or complex values) and cases where ABCD is a manually defined matrix.
Parameters
- ABCD
numpy.ndarray A 2D numpy array of shape
(2, 2)containing the ABCD matrix elements. Note that this can be a matrix of symbolic elements or a matrix of numbers.- q1complex,
BeamParam, symbolic, array-like A complex number,
BeamParaminstance or complex symbolic expression, representing the beam parameter to be transformed by ABCD. This can also be an array of beam parameters (which in turn can be symbolic or numeric again).- nr1float, symbolic
The index of refraction of the source medium.
- nr2float, symbolic
The index of refraction of the target medium.
Returns
- outcomplex,
BeamParam, symbolic,numpy.ndarray The transformed beam parameter. If ABCD is symbolic then a symbolic expression is returned. If q1 is a
BeamParaminstance then a newBeamParaminstance is returned. Note that these two conditions couple such that aBeamParamwith a symbolic q attribute may be returned.If q1 is an array of beam parameters then an array of the above types will be returned (dependent upon whether q1 contains symbolic or numeric beam parameters).
- ABCD
- finesse.gaussian.ws_overlap(W, S, Wp, Sp, wavelength=None)[source]
Calculates the WS phase space overlap.
This overlap function is computed by,
\[O(W,S) = \frac{4}{W^2 W_P^2} \frac{1}{\left(\frac{1}{W^2} + \frac{1}{W_p^2}\right)^2 + \frac{k^2}{4}\left(S - S_P\right)^2},\]Note
The equation above was derived from the work in [44].
where \(W\) and \(S\) are the beam size and defocus, respectively, of a gaussian beam propagated to the same plane as the primary mode (which has \(W_p\), \(S_p\)).
Parameters
- Wnumber, array-like
Beam size of mode [metres].
- Snumber, array-like
Defocus of mode [1/metres].
- Wpnumber, array-like
Beam size of primary mode [metres].
- Spnumber, array-like
Defocus of primary mode [1/metres].
- wavelengthfloat, optional
Wavelength of the beam. Defaults to the value in the loaded config file.
Returns
- Onumber, array-like
The overlap between the mode \((W,S)\) and the primary mode \((W_p,S_p)\).
- finesse.gaussian.ws_overlap_grid(qp, woffset, soffset, wpts=200, spts=200)[source]
Computes the WS phase space overlap with the primary beam parameter qp over a grid of W, S data.
See
ws_overlap()for a definition of the overlap quantity.The \(W\) and \(S\) spaces are formed by creating arrays around the
BeamParam.wandBeamParam.Svalues of qp, according to the offsets given in woffset and soffset, respectively.Parameters
- qp
BeamParam The primary “mode” which overlapping modes are calculated against.
- woffsetfloat, sequence
A single number, or size 2 sequence. Defines the offsets (lower, upper) from the primary mode beamsize to use for the W space.
- soffsetfloat, sequence
A single number, or size 2 sequence. Defines the offsets (lower, upper) from the primary mode beamsize to use for the S space.
- wptsint, optional; default: 200
Number of points for the W space array.
- sptsint, optional; default: 200
Number of points for the S space array.
Returns
- W
numpy.ndarray The W space (as a 2D grid).
- S
numpy.ndarray The S space (as a 2D grid).
- OL
numpy.ndarray The overlap as a function of the WS phase space (as a 2D grid).
Examples
In the following example, we compute the overlap to a primary mode which has a 6 mm beam size and a defocus of 0 m (i.e. at the waist).
import finesse finesse.configure(plotting=True) import finesse.gaussian as gaussian from finesse.plotting.plot import ws_phase_space import matplotlib.pyplot as plt # Make a beam parameter with w = 6 mm, S = 0 m qp = gaussian.BeamParam(w=6e-3, S=0) # Compute the WS phase space overlap with qp, using # maximum offset of 1 mm in beam size and 1 cm in defocus W, S, OL = gaussian.ws_overlap_grid(qp, woffset=1e-3, soffset=1e-2) # Now plot this as contours of overlap with custom levels fig, ax = ws_phase_space( W, S, OL, levels=[0.6, 0.8, 0.84, 0.88, 0.92, 0.94, 0.96, 0.98, 0.995, 0.999], )
- qp