pulsesuite.libpulsesuite.helpers¶
Helper functions module.
Mostly useful functions that did not fit anywhere else.
This module provides utility functions for mathematical operations, interpolation, and field conversions.
Author: Rahul R. Sah
Attributes¶
Functions¶
|
Hyperbolic secant function. |
|
Returns the angle of a complex number. |
|
Gaussian function. |
|
Magnitude squared of a complex number. |
|
Constrains values between limits. |
|
Linear interpolation. |
|
Bilinear interpolation. |
|
Trilinear interpolation. |
|
First derivative with respect to t. |
|
Converts a real amplitude into the intensity. |
|
Converts a complex amplitude into the intensity. |
|
Converts the medium intensity to a real amplitude. |
|
Returns the angle of a complex number wrt the real axis. |
|
Returns the angle of a complex number wrt the real axis. |
|
Single precision sech. |
|
Double precision sech. |
|
The Gaussian function. |
|
The Gaussian function. |
|
Computes the magnitude squared of a complex number. |
|
Computes the magnitude squared of a complex number. |
|
Implements the Lax method in finite differencing. |
|
Function with the same signature as LAX for a direct replacement. |
|
Constrains a number between a high and a low value. |
|
Constrains a number between a high and a low value. |
|
Converts a wavelength into its corresponding frequency. |
|
Converts a wavelength into its corresponding angular frequency. |
|
Converts an angular frequency into its corresponding wavelength. |
|
Helper function to calculate the spatial array. |
|
Calculates the wavevector array for the FFT. |
|
Reconstructs a smooth phase from one that has been wrapped by modulo 2π. |
|
Computes the factorial of an integer. |
|
Computes a linear interpolation of a complex 1D array at a specified position. |
|
Computes a linear interpolation of a real 1D array at a specified position. |
|
Computes a linear interpolation of a complex 2D array at a specified position. |
|
Computes a linear interpolation of a real 2D array at a specified position. |
|
Computes a linear interpolation of a complex 3D array at a specified position. |
|
Computes a linear interpolation of a real 3D array at a specified position. |
|
Returns the first derivative value of the array f(:) with respect to t |
|
Returns the first derivative value of the array f(:) with respect to t |
|
Returns the first derivative of the array f(:) with respect to t |
|
Returns the first derivative of the array f(:) with respect to t |
|
A double precision isnan. |
|
A single precision isnan. |
Module Contents¶
- pulsesuite.libpulsesuite.helpers.pi¶
- pulsesuite.libpulsesuite.helpers.eps0¶
- pulsesuite.libpulsesuite.helpers.c0¶
- pulsesuite.libpulsesuite.helpers.ec2¶
- pulsesuite.libpulsesuite.helpers.sech(t: float | numpy.ndarray) float | numpy.ndarray¶
Hyperbolic secant function.
Single and double precision sech function.
- pulsesuite.libpulsesuite.helpers.arg(Z: complex | numpy.ndarray) float | numpy.ndarray¶
Returns the angle of a complex number.
Returns the angle of a complex number with respect to the real axis.
- pulsesuite.libpulsesuite.helpers.gauss(x: float | numpy.ndarray) float | numpy.ndarray¶
Gaussian function.
Returns exp(-x^2).
- pulsesuite.libpulsesuite.helpers.magsq(Z: complex | numpy.ndarray) float | numpy.ndarray¶
Magnitude squared of a complex number.
Provides a faster abs(Z)**2 by computing real(Z)^2 + imag(Z)^2.
- pulsesuite.libpulsesuite.helpers.constrain(x: float | int | numpy.ndarray, H: float | int, L: float | int) float | int | numpy.ndarray¶
Constrains values between limits.
Constrains a number between a high and a low value.
- pulsesuite.libpulsesuite.helpers.LinearInterp(f: numpy.ndarray, x: numpy.ndarray, x0: float) float | complex¶
Linear interpolation.
Returns the linearly interpolated value of the array f(:) at the position x0.
- pulsesuite.libpulsesuite.helpers.BilinearInterp(f: numpy.ndarray, x: numpy.ndarray, y: numpy.ndarray, x0: float, y0: float) float | complex¶
Bilinear interpolation.
Returns the linearly interpolated value of the array f(:,:) at the position (x0,y0).
- Parameters:
- Returns:
Interpolated value at (x0, y0)
- Return type:
- pulsesuite.libpulsesuite.helpers.TrilinearInterp(f: numpy.ndarray, x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, x0: float, y0: float, z0: float) float | complex¶
Trilinear interpolation.
Returns the linearly interpolated value of the array f(:,:,:) at the position (x0,y0,z0).
- Parameters:
f (ndarray) – 3D array to be interpolated
x (ndarray) – 1D X position array corresponding to ‘f’
y (ndarray) – 1D Y position array corresponding to ‘f’
z (ndarray) – 1D Z position array corresponding to ‘f’
x0 (float) – X position at which ‘f’ is to be interpolated
y0 (float) – Y position at which ‘f’ is to be interpolated
z0 (float) – Z position at which ‘f’ is to be interpolated
- Returns:
Interpolated value at (x0, y0, z0)
- Return type:
- pulsesuite.libpulsesuite.helpers.dfdt(f: numpy.ndarray, dt: float, k: int | None = None) float | complex | numpy.ndarray¶
First derivative with respect to t.
Returns the first derivative value of the array f(:) with respect to t at the index k with a five-point stencil method.
- pulsesuite.libpulsesuite.helpers.AmpToInten(e: float, n0: float | None = None) float¶
Converts a real amplitude into the intensity.
Converts a real amplitude into the intensity in a medium with refractive index n0. Default n0 = 1.0.
Uses the formula: I = n0 * 2 * eps0 * c0 * E^2
- pulsesuite.libpulsesuite.helpers.FldToInten(e: complex, n0: float | None = None) float¶
Converts a complex amplitude into the intensity.
Converts a complex amplitude into the intensity in a medium with refractive index n0. Default n0 = 1.0.
Uses the formula: I = n0 * 2 * eps0 * c0 * |E|^2
- pulsesuite.libpulsesuite.helpers.IntenToAmp(inten: float, n0: float | None = None) float¶
Converts the medium intensity to a real amplitude.
Converts the medium intensity to a real amplitude. Default n0 = 1.0.
Uses the formula: E = sqrt(I / (n0 * 2 * eps0 * c0))
- pulsesuite.libpulsesuite.helpers.arg_dp(Z: complex | numpy.ndarray) float | numpy.ndarray¶
Returns the angle of a complex number wrt the real axis.
- pulsesuite.libpulsesuite.helpers.arg_sp(Z: complex | numpy.ndarray) float | numpy.ndarray¶
Returns the angle of a complex number wrt the real axis.
- pulsesuite.libpulsesuite.helpers.sech_sp(t: float | numpy.ndarray) float | numpy.ndarray¶
Single precision sech.
- pulsesuite.libpulsesuite.helpers.sech_dp(t: float | numpy.ndarray) float | numpy.ndarray¶
Double precision sech.
- pulsesuite.libpulsesuite.helpers.gauss_dp(x: float | numpy.ndarray) float | numpy.ndarray¶
The Gaussian function.
Returns exp(-x^2).
- pulsesuite.libpulsesuite.helpers.gauss_sp(x: float | numpy.ndarray) float | numpy.ndarray¶
The Gaussian function.
Returns exp(-x^2).
- pulsesuite.libpulsesuite.helpers.magsq_dp(Z: complex | numpy.ndarray) float | numpy.ndarray¶
Computes the magnitude squared of a complex number.
Computes real(Z)^2 + imag(Z)^2.
- pulsesuite.libpulsesuite.helpers.magsq_sp(Z: complex | numpy.ndarray) float | numpy.ndarray¶
Computes the magnitude squared of a complex number.
Computes real(Z)^2 + imag(Z)^2.
- pulsesuite.libpulsesuite.helpers.LAX(u: numpy.ndarray, i: int, j: int, k: int) complex¶
Implements the Lax method in finite differencing.
Improves the stability of explicit methods.
- pulsesuite.libpulsesuite.helpers.noLAX(u: numpy.ndarray, i: int, j: int, k: int) complex¶
Function with the same signature as LAX for a direct replacement.
Does not implement the Lax method.
- pulsesuite.libpulsesuite.helpers.constrain_dp(x: float | numpy.ndarray, H: float, L: float) float | numpy.ndarray¶
Constrains a number between a high and a low value.
- pulsesuite.libpulsesuite.helpers.constrain_int(x: int | numpy.ndarray, H: int, L: int) int | numpy.ndarray¶
Constrains a number between a high and a low value.
- pulsesuite.libpulsesuite.helpers.l2f(lam: float) float¶
Converts a wavelength into its corresponding frequency.
Uses the formula: f = c0 / λ
- pulsesuite.libpulsesuite.helpers.l2w(lam: float) float¶
Converts a wavelength into its corresponding angular frequency.
Uses the formula: ω = 2π * c0 / λ
- pulsesuite.libpulsesuite.helpers.w2l(w: float) float¶
Converts an angular frequency into its corresponding wavelength.
Uses the formula: λ = 2π * c0 / ω
- pulsesuite.libpulsesuite.helpers.GetSpaceArray(N: int, length: float) numpy.ndarray¶
Helper function to calculate the spatial array.
Change this function to change the centering of the field.
- pulsesuite.libpulsesuite.helpers.GetKArray(N: int, length: float) numpy.ndarray¶
Calculates the wavevector array for the FFT.
- pulsesuite.libpulsesuite.helpers.unwrap(phase: numpy.ndarray) numpy.ndarray¶
Reconstructs a smooth phase from one that has been wrapped by modulo 2π.
- Parameters:
phase (ndarray) – Wrapped phase array
- Returns:
Unwrapped phase array
- Return type:
ndarray
- pulsesuite.libpulsesuite.helpers.LinearInterp_dpc(f: numpy.ndarray, x: numpy.ndarray, x0: float) complex¶
Computes a linear interpolation of a complex 1D array at a specified position.
- pulsesuite.libpulsesuite.helpers.LinearInterp_dp(f: numpy.ndarray, x: numpy.ndarray, x0: float) float¶
Computes a linear interpolation of a real 1D array at a specified position.
- pulsesuite.libpulsesuite.helpers.BilinearInterp_dpc(f: numpy.ndarray, x: numpy.ndarray, y: numpy.ndarray, x0: float, y0: float) complex¶
Computes a linear interpolation of a complex 2D array at a specified position.
- Parameters:
- Returns:
Interpolated value at (x0, y0)
- Return type:
- pulsesuite.libpulsesuite.helpers.BilinearInterp_dp(f: numpy.ndarray, x: numpy.ndarray, y: numpy.ndarray, x0: float, y0: float) float¶
Computes a linear interpolation of a real 2D array at a specified position.
- Parameters:
- Returns:
Interpolated value at (x0, y0)
- Return type:
- pulsesuite.libpulsesuite.helpers.TrilinearInterp_dpc(f: numpy.ndarray, x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, x0: float, y0: float, z0: float) complex¶
Computes a linear interpolation of a complex 3D array at a specified position.
- Parameters:
f (ndarray) – 3D complex array to be interpolated
x (ndarray) – 1D X position array corresponding to ‘f’
y (ndarray) – 1D Y position array corresponding to ‘f’
z (ndarray) – 1D Z position array corresponding to ‘f’
x0 (float) – X position at which ‘f’ is to be interpolated
y0 (float) – Y position at which ‘f’ is to be interpolated
z0 (float) – Z position at which ‘f’ is to be interpolated
- Returns:
Interpolated value at (x0, y0, z0)
- Return type:
- pulsesuite.libpulsesuite.helpers.TrilinearInterp_dp(f: numpy.ndarray, x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, x0: float, y0: float, z0: float) float¶
Computes a linear interpolation of a real 3D array at a specified position.
- Parameters:
f (ndarray) – 3D real array to be interpolated
x (ndarray) – 1D X position array corresponding to ‘f’
y (ndarray) – 1D Y position array corresponding to ‘f’
z (ndarray) – 1D Z position array corresponding to ‘f’
x0 (float) – X position at which ‘f’ is to be interpolated
y0 (float) – Y position at which ‘f’ is to be interpolated
z0 (float) – Z position at which ‘f’ is to be interpolated
- Returns:
Interpolated value at (x0, y0, z0)
- Return type:
- pulsesuite.libpulsesuite.helpers.dfdt_dp(f: numpy.ndarray, dt: float, k: int) float¶
Returns the first derivative value of the array f(:) with respect to t at the index k with a five-point stencil method.
- pulsesuite.libpulsesuite.helpers.dfdt_dpc(f: numpy.ndarray, dt: float, k: int) complex¶
Returns the first derivative value of the array f(:) with respect to t at the index k with a five-point stencil method.
- pulsesuite.libpulsesuite.helpers.dfdt_1D_dp(f: numpy.ndarray, dt: float) numpy.ndarray¶
Returns the first derivative of the array f(:) with respect to t for all points using a five-point stencil method.
- Parameters:
f (ndarray) – Function of t, 1D real array
dt (float) – t differential
- Returns:
Derivative array
- Return type:
ndarray
- pulsesuite.libpulsesuite.helpers.dfdt_1D_dpc(f: numpy.ndarray, dt: float) numpy.ndarray¶
Returns the first derivative of the array f(:) with respect to t for all points using a five-point stencil method.
- Parameters:
f (ndarray) – Function of t, 1D complex array
dt (float) – t differential
- Returns:
Derivative array
- Return type:
ndarray
- pulsesuite.libpulsesuite.helpers.isnan_dp(X: float | numpy.ndarray) bool | numpy.ndarray¶
A double precision isnan.
Wraps numpy’s isnan for double precision.
- pulsesuite.libpulsesuite.helpers.isnan_sp(X: float | numpy.ndarray) bool | numpy.ndarray¶
A single precision isnan.
Wraps numpy’s isnan for single precision.