irradiapy.utils.math module
This module contains math utilities for the irradiapy package.
- irradiapy.utils.math.apply_boundary_conditions(data_atoms, x, y, z)[source]
Apply boundary conditions to atoms.
- Parameters:
data_atoms (
dict[str,Any]) – Atoms data containing atom positions and boundaries.x (
bool) – Whether to apply periodic boundary conditions in the x direction.y (
bool) – Whether to apply periodic boundary conditions in the y direction.z (
bool) – Whether to apply periodic boundary conditions in the z direction.
- Returns:
Updated atoms data with applied boundary conditions.
- Return type:
- irradiapy.utils.math.fit_gaussian(xs, ys, p0=None, asymmetry=1.0)[source]
Fit data to a Gaussian function.
- Parameters:
xs (
GenericAlias[double]) – X values where the function is evaluated.ys (
GenericAlias[double]) – Y values at the given xs.p0 (
GenericAlias[double] |None) – Initial guess of fit parameters. If None, a guess is generated.asymmetry (
float) – Bound for the asymmetry fit parameter. Fit will be done in (-asymmetry, asymmetry).
- Return type:
tuple[GenericAlias[double],GenericAlias[double],Callable[[GenericAlias[double]],GenericAlias[double]]]- Returns:
popt (npt.NDArray[np.float64]) – Optimal values for the parameters.
pcov (npt.NDArray[np.float64]) – Covariance of popt.
fit_function (Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]) – Function that evaluates the fitted Gaussian.
- irradiapy.utils.math.fit_linear(xs, ys, yerrs=None)[source]
Fit a linear function to the given data: y = a * x + b.
- Parameters:
- Return type:
tuple[GenericAlias[double],GenericAlias[double],Callable[[GenericAlias[double]],GenericAlias[double]]]- Returns:
popt (npt.NDArray[np.float64]) – Optimal values for the parameters.
pcov (npt.NDArray[np.float64]) – Covariance of popt.
fit_function (Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]) – Function that evaluates the fitted linear function.
- irradiapy.utils.math.fit_lorentzian(xs, ys, p0=None, asymmetry=1.0)[source]
Fit data to a Lorentzian function.
- Parameters:
xs (
GenericAlias[double]) – X values where the function is evaluated.ys (
GenericAlias[double]) – Y values at the given xs.p0 (
GenericAlias[double] |None) – Initial guess of fit parameters. If None, a guess is generated.asymmetry (
float) – Bound for the asymmetry fit parameter. Fit will be done in (-asymmetry, asymmetry).
- Return type:
tuple[GenericAlias[double],GenericAlias[double],Callable[[GenericAlias[double]],GenericAlias[double]]]- Returns:
popt (npt.NDArray[np.float64]) – Optimal values for the parameters.
pcov (npt.NDArray[np.float64]) – Covariance of popt.
fit_function (Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]) – Function that evaluates the fitted Lorentzian.
- irradiapy.utils.math.fit_offset_power_law(xs, ys, yerrs=None)[source]
Fit a power law with an offset to the given histogram data: y = a * x**k + b.
Note
The presence of the offset b prevents a log–log linearization. We therefore fit the model directly in linear space via nonlinear least squares.
- Parameters:
- Return type:
tuple[GenericAlias[double],GenericAlias[double],Callable[[GenericAlias[double]],GenericAlias[double]]]- Returns:
popt (npt.NDArray[np.float64]) – Optimal values for the parameters.
pcov (npt.NDArray[np.float64]) – Covariance of popt.
fit_function (Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]) – Function that evaluates the fitted power law with offset.
- irradiapy.utils.math.fit_power_law(xs, ys, yerrs=None)[source]
Fit a power law to the given histogram data: y = a * x**k.
Fitted in log-log space: log(y) = log(a) + k * log(x)
- Parameters:
- Return type:
tuple[GenericAlias[double],GenericAlias[double],Callable[[GenericAlias[double]],GenericAlias[double]]]- Returns:
popt (npt.NDArray[np.float64]) – Optimal values for the parameters.
pcov (npt.NDArray[np.float64]) – Covariance of popt.
fit_function (Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]) – Function that evaluates the fitted power law.
- irradiapy.utils.math.gaussian(xs, x_peak, linewidth, amplitude, asymmetry)[source]
Evaluate a Gaussian function.
- Parameters:
- Returns:
Evaluated Gaussian function.
- Return type:
References
- irradiapy.utils.math.lorentzian(xs, x_peak, linewidth, amplitude, asymmetry)[source]
Evaluate a Lorentzian function.
- Parameters:
- Returns:
Evaluated Lorentzian function.
- Return type:
References