trspectrometer.utils module¶
Module for storing miscellaneous utility functions etc.
- exception trspectrometer.utils.AcquisitionAbortedWarning(message='Acquisition interrupted by user.')[source]¶
Bases:
UserWarning
An exception to indicate the acquisition process was stopped manually.
Since the stop was manually triggered, this is a warning rather than an error, but may still want to be acted upon by the listeners to the completion callback.
- Parameters:
message – String describing the warning.
- exception trspectrometer.utils.AcquisitionError(message='Unknown acquisition error.')[source]¶
Bases:
RuntimeError
An exception to identify some error which occurred during the acquisition process.
- Parameters:
message – String describing the error.
- trspectrometer.utils.clean_filename(filename, allowed_symbols=['-', '_', '+', '.'])[source]¶
Clean up a filename by removing symbols and replacing spaces with underscores.
The list of
allowed_symbols
will not be removed.- Parameters:
filename – Input filename to clean up.
- Returns:
The cleaned filename.
- trspectrometer.utils.mask_outliers(data, axis: int = 0, sensitivity: float = 0.1, copy: bool = True)[source]¶
Convert outlying points in a numpy array to NaNs.
The
axis
parameter determines the array axis in which to compute the median values and detect the outliers. Thesensitivity
parameter would typically range between 0.0 and 1.0, where 0.0 will return the original data unmodified, and larger values will remove a greater number of outliers. Values greater than 1.0 are permitted. By default the operation is performed on a copy of the original data. To modify the original data in-place, thecopy
parameter can be set toFalse
.- Parameters:
data – Numpy array containing data to process.
axis – Index of array axis in which to detect outliers.
sensitivity – Sensitivity of outlier detection.
copy – Operate on a copy of the input data.
- Returns:
Numpy array containing the processed data.
- trspectrometer.utils.no_infs(x, copy=True)[source]¶
Convenience function to convert all
+inf
and-inf
in a numpy array tonan
.- Parameters:
x – Numpy array.
copy – Create a copy of
x
(default,True
), or convert in-place (False
).
- Returns:
The array
x
, with all infinite values converted tonan
.
- trspectrometer.utils.now_string()[source]¶
Get the current local time as an ISO8601 formatted string.
This format is useful for embedding into the metadata of data files. To convert the string back into a python
datetime
object, usedatetime.fromisoformat()
.- Returns:
String representation of current time.
- trspectrometer.utils.si_unit_factor(unit: str)[source]¶
Get the scaling factor for a given SI unit prefix.
The current implementation works for time-based units (in seconds, s), and wavelength units (in metres, m) for ranges applicable for this application. For example, the scaling factor for
"ps"
is 1e-12.- Parameters:
unit – String of the SI unit.
- Returns:
Scaling factor of the SI prefix.