helpers
#
Functions:
|
|
|
Recursive calls to elements of tuples, lists, dicts, set, and frozensets. |
|
Apply |
|
Matrix multiplication of last 2 dimensions for two 4-dimensional input matrices. |
|
Binary search algorithm for sorted array. |
|
Multiple gauss functions with width |
|
Convert a vector or field from cartesian coordinates \((x, y, z)\) to polar coordinates \((r, \phi, \gamma)\): |
|
Convert a vector or field from polar coordinates \((r, \phi, \gamma)\) to cartesian coordinates \((x, y, z)\): |
- udkm1Dsim.helpers.make_hash_md5(obj)[source]#
- Parameters:
obj (any) – anything that can be hashed.
- Returns:
hash (str) – hash from object.
- udkm1Dsim.helpers.make_hashable(obj)[source]#
Recursive calls to elements of tuples, lists, dicts, set, and frozensets.
- Parameters:
obj (any) – anything that can be hashed..
- Returns:
obj (tuple) – hashable object.
- udkm1Dsim.helpers.m_power_x(m, x)[source]#
Apply
numpy.linalg.matrix_power
to last 2 dimensions of 4-dimensional input matrix.- Parameters:
m (ndarray[float, complex]) – 4-dimensional input matrix.
x (float) – exponent.
- Returns:
m (ndarray[float, complex]) – resulting matrix.
- udkm1Dsim.helpers.m_times_n(m, n)[source]#
Matrix multiplication of last 2 dimensions for two 4-dimensional input matrices.
- Parameters:
m (ndarray[float, complex]) – 4-dimensional input matrix.
n (ndarray[float, complex]) – 4-dimensional input matrix.
- Returns:
res (ndarray[float, complex]) – 4-dimensional multiplication result.
- udkm1Dsim.helpers.finderb(key, array)[source]#
Binary search algorithm for sorted array. Searches for the first index
i
of array wherekey
>=array[i]
.key
can be a scalar or a np.ndarray of keys.array
must be a sorted np.ndarray.Author: André Bojahr. Licence: BSD.
- Parameters:
key (float, ndarray[float]) – single or multiple sorted keys.
array (ndarray[float]) – sorted array.
- Returns:
i (ndarray[float]) – position indices for each key in the array.
- udkm1Dsim.helpers.multi_gauss(x, s=[1], x0=[0], A=[1])[source]#
Multiple gauss functions with width
s
given as FWHM and area normalized to inputA
and maximum of gauss atx0
.- Parameters:
x (ndarray[float]) – argument of multi_gauss.
s (ndarray[float], optional) – FWHM of Gaussians. Defaults to 1.
x0 (ndarray[float], optional) – centers of Gaussians. Defaults to 0.
A (ndarray[float], optional) – amplitudes of Gaussians. Defaults to 1.
- Returns:
y (ndarray[float]) – multiple Gaussians.
- udkm1Dsim.helpers.convert_cartesian_to_polar(cartesian)[source]#
Convert a vector or field from cartesian coordinates \((x, y, z)\) to polar coordinates \((r, \phi, \gamma)\):
\[\begin{split}F_r & = \sqrt{F_x^2 + F_y^2+F_z^2}\\ F_{\phi} & = \begin{cases}\\ \arctan\left(\frac{F_y}{F_x} \right) & \mathrm{for}\ F_x > 0 \\ \pi + \arctan\left(\frac{F_y}{F_x}\right) & \mathrm{for}\ F_x < 0 \ \mathrm{and}\ F_y \geq 0 \\ \arctan\left(\frac{F_y}{F_x}\right) - \pi & \mathrm{for}\ F_x < 0 \ \mathrm{and}\ F_y < 0 \\ 0 & \mathrm{for}\ F_x = F_y = 0 \end{cases} \\ F_{\gamma} & = \arccos\left(\frac{F_z}{F_r} \right)\end{split}\]where \(F_r\), \(F_{\phi}\), \(F_{\gamma}\) are the radial (amplitude), azimuthal, and polar component of vector field \(\mathbf{F}\), respectively.
- Parameters:
cartesian (ndarray[float]) – vector of field to convert.
- Returns:
polar (ndarray[float]) – converted vector or field.
- udkm1Dsim.helpers.convert_polar_to_cartesian(polar)[source]#
Convert a vector or field from polar coordinates \((r, \phi, \gamma)\) to cartesian coordinates \((x, y, z)\):
\[\begin{split}F_x & = r \sin(\phi)\cos(\gamma) \\ F_y & = r \sin(\phi)\sin(\gamma) \\ F_z & = r \cos(\phi)\end{split}\]where \(r\), \(\phi\), \(\gamma\) are the radius (amplitude), azimuthal, and polar angles of vector field \(\mathbf{F}\), respectively.
- Parameters:
polar (ndarray[float]) – vector of field to convert.
- Returns:
cartesian (ndarray[float]) – converted vector or field.