daxs.scans: Scans#
The module provides classes for the representation of scans in measurements.
- class daxs.scans.Scan(x: ndarray[tuple[int, ...], dtype[float64]], signal: ndarray[tuple[int, ...], dtype[float64]], *, data: dict[Any, Any] | None = None)[source]#
Bases:
object- __init__(x: ndarray[tuple[int, ...], dtype[float64]], signal: ndarray[tuple[int, ...], dtype[float64]], *, data: dict[Any, Any] | None = None) None[source]#
Define the base representation of scans in measurements.
- Parameters:
x – X-axis values (1D array).
signal – Signal values (1D or 2D array). For a 2D array, the components are stored as rows. A 1D array will be converted to a 2D array.
y – Y-axis values (1D array).
monitor – Monitor values (1D array).
data – Storage for the raw scan data and metadata.
- classmethod from_data(data: dict[Any, Any]) Scan[source]#
Create a scan from a data dictionary.
- Parameters:
data – Dictionary containing at least the keys “x” and “signal”.
- Returns:
A new Scan instance.
- Raises:
ValueError – If required keys are missing from the provided dictionary.
- classmethod from_hdf5(filename: str, index: int, data_mappings: dict[str, Any]) Scan[source]#
Create a scan by reading data from an HDF5 file.
- Parameters:
filename – Path to the HDF5 file.
index – Scan index in the file.
data_mappings – Dictionary mapping scan attributes to file paths. Must contain entries for ‘x’ and ‘signal’.
- Returns:
A new Scan instance loaded from the file.
- Raises:
ValueError – If required keys are missing from data_mappings.
- classmethod from_txt(filename: str, data_mappings: dict[str, int], **kwargs: Any) Scan[source]#
Create a scan by reading data from a text file.
- Parameters:
filename – Path to the text file.
data_mappings – Dictionary mapping scan attributes to column indices. Must contain entries for “x” and “signal”. Column indices are 0-based.
**kwargs – Additional keyword arguments passed to np.loadtxt, e.g., delimiter, skiprows, etc.
- Returns:
A new Scan instance loaded from the text file.
- Raises:
ValueError – If required keys are missing from data_mappings or if there are issues reading data from the file.
- property x#
- property y#
- property signal#
- property monitor#
- property indices#
- property data#
- property label: str#
- property filename: str | None#
The filename associated with this scan.
- property index: int | None#
The index of this scan within its file.
- property aggregation: str#
The aggregation method used for signal processing.
- reset() None[source]#
Reset the scan data to the values stored in the data dictionary.
- Raises:
KeyError – If required data is missing from the internal dictionary.
- static read_data_at_paths(filename: str, index: int, data_paths: str | list[str]) ndarray[tuple[int, ...], dtype[float64]][source]#
Read and return data from the file.
- Parameters:
filename – Path to the HDF5 file.
index – Scan index in the file.
data_paths – Single path or list of paths to read.
- Returns:
The data read from the file.
- Return type:
numpy.ndarray
- static trim_data(data: dict[Any, Any]) dict[Any, Any][source]#
Trim all arrays in the data dictionary to have the same size.
Uses the smallest size among all arrays as the reference. Ignores keys that are not arrays or 0-dimensional arrays (scalars). Handles 2D arrays correctly by trimming along the last axis.
- Parameters:
data – Dictionary containing arrays to trim.
- Returns:
Dictionary with trimmed arrays.
- find_outliers(method: str = 'hampel', **kwargs: Any)[source]#
Find outliers in the signal.
See the docstring in the
daxs.filters.
- remove_outliers(method: str = 'hampel', **kwargs: Any)[source]#
Remove outliers from the signal.
See the docstring of
daxs.scans.Scan.find_outliers().
- dead_time_correction(tau: Iterable[float], detection_time: float | npt.NDArray[np.float64] | None = None)[source]#
Perform a dead time correction using a non-paralyzable model.
- Parameters:
tau – The detector dead time in seconds.
detection_time – The time spent on a point of the scan in seconds.
- interpolate(a: ndarray[tuple[int, ...], dtype[float64]])[source]#
Interpolate the signal and monitor data to new X-axis values.
- Parameters:
a – Array used to interpolate the signal and monitor.
- divide_by_scalars(signal_divisor: int | float, monitor_divisor: int | float | None = None) Scan[source]#
Divide the scan by scalar values.
- plot(axes: Axes | None = None, shift: float = 0.0, **kwargs: Any) Axes[source]#
Plot the scan data and outliers if available.
- Parameters:
axes – The axes to plot the scan data on.
shift – Shift the signal by the given value.
**kwargs – Additional keyword arguments passed to the plot function.
- Returns:
The axes with the plotted scan data.
- Raises:
ValueError – If the signal is empty.