daxs.scans: Scans#

The module provides classes for the representation of scans in measurements.

class daxs.scans.Scan(x: npt.NDArray[np.float64], signal: npt.NDArray[np.float64], *, data: dict[Any, Any] | None = None)[source]#

Bases: object

__init__(x: npt.NDArray[np.float64], signal: npt.NDArray[np.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.

reindex()[source]#

Reindex the scan data.

static read_data_at_paths(filename: str, index: int, data_paths: str | list[str]) npt.NDArray[np.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

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[Any, 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.

divide_by_scan(other: Scan) Scan[source]#
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.

class daxs.scans.Scans(scans: Scan | list[Scan] | None = None)[source]#

Bases: object

A collection of scans.

__init__(scans: Scan | list[Scan] | None = None) None[source]#

Initialize the collection of scans.

check_sizes() None[source]#

Sanity check for the number of points in the scans.

get_common_axis(label: str = 'x', mode: str = 'intersection') ndarray[Any, dtype[float64]][source]#

Return the common axis for the scans.

reset() None[source]#

Reset the scans to their original values.

extend(scans: Scans) None[source]#

Extend the collection of scans.

remove(item: Scan) None[source]#

Remove the scan at the given index.

append(item: Scan) None[source]#

Append a scan to the collection.