trepr.utils module

General purpose functions and classes used in other modules.

To avoid circular dependencies, this module does not depend on any other modules of the trepr package, but it can be imported into every other module.

New in version 0.2.

trepr.utils.convert_g2mT(values, mw_freq=None)

Convert g values to millitesla (mT).

Important

Magnetic field values are assumed to be in millitesla (mT) and the microwave frequency to be in Gigahertz (GHz).

Parameters
  • values (np.asarray | float) – g values to be converted into millitesla (mT)

  • mw_freq (float) – Microwave frequency (in GHz)

Returns

values – converted values in millitesla (mT)

Return type

np.asarray | float

trepr.utils.convert_mT2g(values, mw_freq=None)

Convert magnetic field values (in millitesla, mT) to g values.

Important

Magnetic field values are assumed to be in millitesla (mT) and the microwave frequency to be in Gigahertz (GHz).

Parameters
  • values (np.asarray | float) – magnetic field values (in mT) to be converted to g values

  • mw_freq – Microwave frequency (in GHz)

Returns

values – converted values in g

Return type

np.asarray | float

trepr.utils.not_zero(value)

Return a value that is not zero to prevent DivisionByZero errors.

Dividing by zero results in NaN values and often hinders evaluating mathematical models. A solution adopted from the lmfit Python package (https://doi.org/10.5281/zenodo.598352) returns a value equivalent to the resolution of a numpy float.

Note

If you use this function excessively within a module, mostly within rather complicated mathematical equations, it might be a good idea to import this function explicitly, to shorten the code, such as: from trepr.utils import not_zero. As usual, readability is king.

Parameters

value (float) – Value that can become (too close to) zero to trigger NaN values

Returns

value – Value guaranteed not to be zero

Return type

float