Source code for gtrace.optics.gaussian

"""
gaussian - Gaussian Optics Module

This module contains several utility functions for gaussian optics.
"""

#{{{ Import modules
import numpy as np
pi = np.pi
sqrt = np.lib.scimath.sqrt
from unit import *
import scipy.special as spf

#}}}

#{{{ modeSpacing

[docs]def modeSpacing(g1, g2): return np.arccos(np.sqrt(g1*g2))/pi #}}} #{{{ q-parameter related functions
[docs]def q2zr(q): ''' Convert a q-parameter to Rayleigh range. ''' zr = np.float(np.imag(q)) return zr
[docs]def q2w(q, wl=1064*nm): ''' Convert a q-parameter to the beam size ''' S = -1.0/np.imag(1.0/q) w = np.sqrt(wl*S/pi) return w
[docs]def q2R(q): ''' Convert a q-parameter to the ROC ''' return 1.0/np.real(1.0/q)
[docs]def Rw2q(ROC=1.0, w=1.0, wl=1064e-9): ''' Get the q-parameter from the ROC and w. ''' k = 2.0*pi/wl S = w**2 * k/2 return 1.0/(1.0/ROC + 1.0/(1j*S))
[docs]def zr2w0(zr, wl=1064*nm): ''' Convert Rayleigh range to the waist size ''' return np.sqrt(2*zr*wl/(2*pi))
[docs]def w02zr(w0, wl=1064*nm): ''' Convert Rayleigh range to the waist size ''' return (2*pi/wl)*(w0**2)/2
[docs]def modeMatching(q1, q2x, q2y=False): ''' Mode matching between two beams with different q-parameters. The axes of the two beams are assumed to be matched. q1: q-parameter of the first beam. This beam is assumed to be circular. q2x: q-parameter of the second beam in x-direction. If the second beam is also circular, omit the next argument. q2y: q-parameter of the second beam in y-direction. Specify this parameter if the second beam is eliptic. ''' zr1 = np.imag(q1) d1 = np.real(q1) if q2y: #Eliptic beam zrx = np.imag(q2x) dx = np.real(q2x) zry = np.imag(q2y) dy = np.real(q2y) return np.abs(2*sqrt(zr1*sqrt(zrx*zry)/((zr1+zrx+1j*(dx-d1))*(zr1+zry+1j*(dy-d1)))))**2 else: #Circular beam zr2 = np.imag(q2x) d2 = np.real(q2x) ec = zr2 - zr1 az = d2 -d1 return np.abs(2*zr1*sqrt(1+ec/zr1)/(2*zr1+ec+1j*az))**2
[docs]def optimalMatching(q1, q2): ''' Returns a mode (q-parameter) which best matches the given two q-parameters, q1 and q2. Returned values: (q, match) q: The best matching q-parameter match: Mode matching rate ''' zr1 = np.imag(q1) d1 = np.real(q1) zr2 = np.imag(q2) d2 = np.real(q2) zr = np.sqrt(zr1*zr2)*np.sqrt(1+((d2-d1)/(zr1+zr2))**2) d = (zr1*d2 + zr2*d1)/(zr1+zr2) q = d +1j*zr match = modeMatching(q, q1, q2) return (q, match) #{{{ For compatibility
[docs]def qToRadius(q, wl=1064e-9): k = 2*pi/wl return sqrt(-2.0/(k*np.imag(1.0/q)))
[docs]def qToROC(q): return 1.0/np.real(1.0/q)
[docs]def ROCandWtoQ(ROC=1.0, w=1.0, wl=1064e-9): k = 2.0*pi/wl S = w**2 * k/2 return 1.0/(1.0/ROC + 1.0/(1j*S)) #}}} #}}} #{{{ Beam clip
[docs]def beamClip(a = 1.0, w = 3.0): return (1+spf.erf(np.sqrt(2)*a/w))/2
[docs]def appertureCut(r = 1.0, w = 3.0): return 1-np.exp(-2*(r/w)**2) #}}}