attoworld.attoworld_rs

Functions written in Rust for improved performance and correctness.

def find_maximum_location(y, neighbors=3, /):

Find the location and value of the maximum of a smooth, uniformly sampled signal, interpolating to find the sub-pixel location

Arguments:
  • y (np.ndarray): The signal whose maximum should be located
  • neighbors (int): the number of neighboring points to consider in the optimization (default 3)
Returns:

(float, float): location, interpolated maximum

def find_first_intercept(y, intercept_value, neighbors):

Find the first intercept with a value

Arguments:
  • y (np.ndarray): the distribution data
  • intercept_value (float): The value at which to take the intercept
  • neighbors (int): The number of neighboring points in each direction to use when constructing interpolants. Higher values are more accurate, but only for smooth data.
Returns:

float: "index" of the intercept, a float with non-integer value, indicating where between the pixels the intercept is

def find_last_intercept(y, intercept_value, neighbors):

Find the last intercept with a value

Arguments:
  • y (np.ndarray): the distribution data
  • intercept_value (float): The value at which to take the intercept
  • neighbors (int): The number of neighboring points in each direction to use when constructing interpolants. Higher values are more accurate, but only for smooth data.
Returns:

float: "index" of the intercept, a float with non-integer value, indicating where between the pixels the intercept is

def fwhm(y, dx=1.0, intercept_value=0.5, neighbors=2):

Find the full-width-at-half-maximum value of a continuously-spaced distribution.

Arguments:
  • y (np.ndarray): the distribution data
  • dx (float): the x step size of the data
  • intercept_value (float): The value at which to take the intercepts (i.e. only full-width-at-HALF-max for 0.5)
  • neighbors (int): The number of neighboring points in each direction to use when constructing interpolants. Higher values are more accurate, but only for smooth data.
Returns:

float: The full width at intercept_value maximum

def fornberg_stencil(order, positions, position_out=0.0, /):

Generate a finite difference stencil using the algorithm described by B. Fornberg in Mathematics of Computation 51, 699-706 (1988).

Arguments:
  • order (int): the order of the derivative
  • positions (np.ndarray): the positions at which the functions will be evaluated in the stencil. Must be larger than 2 elements in size.
  • position_out (float): the position at which using the stencil will evaluate the derivative, default 0.0.
Returns:

np.ndarray: the finite difference stencil with weights corresponding to the positions in the positions input array

Examples:
>>> stencil = fornberg_stencil(1, np.array([-1.0, 0.0, 1.0]))
>>> print(stencil)
[-0.5  0.   0.5]
def interpolate( x_out, x_in, y_in, /, inputs_are_sorted=True, neighbors=2, extrapolate=False, derivative_order=0):

Interpolate sorted data, given a list of intersection locations

Arguments:
  • x_out (np.ndarray): array of output x values, the array onto which y_in will be interpolated
  • x_in (np.ndarray): array of input x values
  • y_in (np.ndarray): array of input y values
  • inputs_are_sorted (bool): true is x_in values are in ascending order (default). Set to false for unsorted data.
  • neighbors (int): number of nearest neighbors to include in the interpolation
  • extrapolate (bool): unless set to true, values outside of the range of x_in will be zero
  • derivative_order(int): order of derivative to take. 0 (default) is plain interpolation, 1 takes first derivative, and so on.
Returns:

np.ndarray: the interpolated y_out

def derivative(y, order, /, neighbors=3):

Use a Fornberg stencil to take a derivative of arbitrary order and accuracy, handling the edge by using modified stencils that only use internal points.

Arguments:
  • data (np.ndarray): the data whose derivative should be taken
  • order (int): the order of the derivative
  • neighbors (int): the number of nearest neighbors to consider in each direction.
Returns:

np.ndarray: the derivative

def derivative_periodic(y, order, /, neighbors=3):

Use a Fornberg stencil to take a derivative of arbitrary order and accuracy, handling the edge by treating it as a periodic boundary

Arguments:
  • data (np.ndarray): the data whose derivative should be taken
  • order (int): the order of the derivative
  • neighbors (int): the number of nearest neighbors to consider in each direction.
Returns:

np.ndarray: the derivative