pyresiflex.misc.utils#

Library of useful helper functions.

Attributes#

Functions#

gaussian_sigma_from_fwhm(→ float)

Return the Gaussian width sigma for a given FWHM.

gaussian_fwhm_from_sigma(→ float)

Return the FWHM for a given Gaussian width sigma.

get_root(→ pathlib.Path)

Return the full path of the pyresiflex folder.

get_path_to_data(→ pathlib.Path)

Return the absolute path to the data folder, or file inside.

Module Contents#

pyresiflex.misc.utils.ROOT_FOLDER_PATH: pathlib.Path#
pyresiflex.misc.utils.gaussian_sigma_from_fwhm(fwhm: float) float#

Return the Gaussian width sigma for a given FWHM.

The pulse is parametrised as \(\exp(-((t - \mu) / \sigma)^2)\) (note: no factor of two in the exponent denominator), for which the full width at half maximum is \(2 \sqrt{\ln 2}\, \sigma\).

Parameters:

fwhm (float) – Full width at half maximum of the Gaussian pulse.

Returns:

The corresponding standard-deviation-like width sigma.

Return type:

float

Examples

>>> import numpy as np
>>> from pyresiflex.misc.utils import gaussian_sigma_from_fwhm
>>> bool(np.isclose(gaussian_sigma_from_fwhm(5.0), 3.0028, atol=1e-4))
True
pyresiflex.misc.utils.gaussian_fwhm_from_sigma(sigma: float) float#

Return the FWHM for a given Gaussian width sigma.

Inverse of gaussian_sigma_from_fwhm().

Parameters:

sigma (float) – Standard-deviation-like width of the Gaussian pulse.

Returns:

The corresponding full width at half maximum.

Return type:

float

Examples

>>> import numpy as np
>>> from pyresiflex.misc.utils import (
...     gaussian_fwhm_from_sigma,
...     gaussian_sigma_from_fwhm,
... )
>>> sigma = gaussian_sigma_from_fwhm(5.0)
>>> bool(np.isclose(gaussian_fwhm_from_sigma(sigma), 5.0))
True
pyresiflex.misc.utils.get_root() pathlib.Path#

Return the full path of the pyresiflex folder.

Used not to worry about the project architecture.

Returns:

the abspath to root folder (should end with ‘pyresiflex’)

Return type:

pathlib.Path

Examples

>>> from pyresiflex.misc.utils import get_root
>>> path = get_root() / "data"
pyresiflex.misc.utils.get_path_to_data(*paths: str, force_return: bool = False) pathlib.Path#

Return the absolute path to the data folder, or file inside.

Parameters:
  • *paths (str) – You can add a path to precise the folder inside.

  • force_return (bool, optional) – If True, return path even if does not exists, by default False.

Returns:

The abspath to the data (or file).

Return type:

pathlib.Path

Examples

>>> from pyresiflex.misc.utils import get_path_to_data
>>> path = get_path_to_data()
>>> path = get_path_to_data("Minesi2022")
Raises:

FileNotFoundError – If the file or folder is not found.