Functions#
Note
For BLS-related functions, see documentation of the bls submodule.
General functions#
- SpinWaveToolkit.wavenumber2wavelength(wavenumber)#
Convert wavelength to wavenumber. lambda = 2*pi/k
- Parameters:
- wavenumber
floator array_like (rad/m) wavenumber of the wave.
- wavenumber
- Returns:
See also
- SpinWaveToolkit.wavelength2wavenumber(wavelength)#
Convert wavenumber to wavelength. k = 2*pi/lambda
- Parameters:
- wavelength
floator array_like (m ) wavelength of the wave.
- wavelength
- Returns:
See also
- SpinWaveToolkit.wrapAngle(angle, amin=0, amax=6.283185307179586)#
Wrap angle in radians to range
[amin, amax), by default[0, 2*np.pi).
- SpinWaveToolkit.roots(f, a, b, dx=0.001, eps=1e-09, args=())#
Find all roots of a continuous function
f(x, *args)within a given interval [a, b].Detects all roots spaced at least by dx with a precision given by eps.
For optimal performance, normalize dx and eps to the scale of your input. In case it didn’t find all expected roots, try decreasing dx, but note that it can extend the calculation time significantly.
- Parameters:
- f
callable() Function to evaluate with signature
f(x, *args).- a, b
float (x units) left and right boundaries of the interval to search.
- dx
float (x units) stepsize of evaluation points (coarse search).
- eps
float, optional (x units) tolerance of the to-be-found roots (fine search).
- args
list, optional List of arguments to be passed to f.
- f
- Returns:
See also
- SpinWaveToolkit.bisect(f, x1, x2, epsilon=1e-09, args=())#
Simple bisection method of root finding.
Must contain only one root in the given interval!
- Parameters:
- f
callable() Function to evaluate,
f(x, *args).- x1, x2
float (x units) left and right boundaries of the interval to search.
- epsilon
float, optional (x units) tolerance of the to-be-found root.
- args
list, optional List of arguments to be passed to f.
- f
- Returns:
See also
- SpinWaveToolkit.rootsearch(f, a, b, dx, args=())#
Search for a root of a continuous function within an interval [a, b].
This function is used as a preliminary search with coarse sampling. Precise position of the root can be found with a more efficient method, e.g. bisection.
Searches from a to b, stops on first identified root.
- Parameters:
- f
callable() Function to evaluate,
f(x, *args).- a, b
float (x units) left and right boundaries of the interval to search.
- dx
float (x units) stepsize of evaluation points.
- args
list, optional List of arguments to be passed to f.
- f
- Returns:
- SpinWaveToolkit.distBE(w, temp=300, mu=-6.6260701499999995e-22)#
Returns Bose-Einstein distribution for given chemical potential and temperature.
- SpinWaveToolkit.sphr2cart(theta, phi, r=1.0)#
Convert spherical coordinates to cartesian.
Inputs can be either floats or ndarrays of same shape.
- Parameters:
- Returns:
- xyz
ndarray (length unit) vector of shape
(3, ...)as for (x, y, z).
- xyz
See also
cart2sphrConvert cartesian coordinates to spherical.
- SpinWaveToolkit.cart2sphr(x, y, z)#
Convert cartesian coordinates to spherical.
Inputs can be either floats or ndarrays of same shape.
- Parameters:
- x, y, z
floator array_like (length unit) cartesian coordinates.
- x, y, z
- Returns:
See also
sphr2cartConvert spherical coordinates to cartesian.
- SpinWaveToolkit.rotate_field(Ei_fields, x, y, angle_deg)#
Rotate both the polarization vectors and the spatial distribution of an electric field in 2D plane.
The rotation is an active, counter-clockwise rotation of the field itself. It applies a 2D rotation matrix to the [Ex, Ey] polarization components, and applies an inverse rotation to the coordinate grid to sample the interpolated spatial distribution correctly.
Works best for angle_deg values that are multiples of 90 degrees, but should work for any angle. Note that for other angles, the interpolation step may introduce some irregularities.
Uses the
scipy.ndimage.map_coordinates()function withorder=1(linear interpolation).- Parameters:
- Ei_fields
list[ndarray] (V/m) List of the three spatial components [Ex, Ey, Ez] of the electric field. Each component must be a 2D complex array of shape
(Nx, Ny).- x
ndarray (m ) 1D array of length
Nxcontaining the spatial x-coordinates. Assumed to be strictly equidistant.- y
ndarray (m ) 1D array of length
Nycontaining the spatial y-coordinates. Assumed to be strictly equidistant.- angle_deg
float (deg) The counter-clockwise rotation angle in degrees.
- Ei_fields
- Returns:
See also
bls.ObjectiveLensClass for calculations of objective electric fields.