Storage

class lys_instr.DataStorage.DataStorage(**kwargs)[source]

Bases: QObject

Threaded, asynchronous storage and file management for multi-dimensional data.

This class reserves disk-backed arrays for incoming frames, buffers updates, and saves buffered data to disk using a background worker thread so the application remains responsive. It emits Qt signals to report saving state and to request metadata tags for saved files.

property base

Base directory for saving data files.

Returns:

Base directory.

Return type:

str

connect(detector)[source]

Connect this data storage instance to a detector.

Parameters:

detector (MultiDetectorInterface) – Detector that emits dataAcquired and busyStateChanged signals.

property enabled

Whether the data storage instance is enabled.

Returns:

True if enabled, False otherwise.

Return type:

bool

property folder

Data folder name under the base directory.

Returns:

Data folder name.

Return type:

str

getNumber()[source]

Return the next available file number for saving.

If automatic numbering is enabled the returned number will be appended to the base file name (for example: <name>_<number>.npz). If numbering is disabled this method returns None.

Returns:

Next available file number, or None if numbering is disabled.

Return type:

int | None

property name

Base file name used when saving data files.

Returns:

File name.

Return type:

str

numberChanged

Signal emitted when the next available file number changes.

property numbered

Whether automatic file numbering is enabled.

Returns:

True if automatic file numbering is enabled, False otherwise.

Return type:

bool

reserve(shape, fillValue=None)[source]

Reserve storage for a new data array with the specified shape.

Allocate and initialize an internal NumPy array with the given shape, record a file path and tag for the upcoming save, emit tagRequest to request metadata, and update saving state via the savingStateChanged signal.

Parameters:
  • shape (tuple, optional) – Shape of the data array to reserve.

  • fillValue (float | None, optional) – Value to initialize the array with. If None the array is initialized with NaNs. Defaults to None.

Returns:

None

save(axes)[source]

Save the buffered data array asynchronously to disk.

This method constructs a lys.Wave from the buffered array and provided coordinate arrays, attaches the queued metadata tag to lys.Wave.note, and enqueues the Wave for export on a background worker thread. Actual file write occurs in a _SaveThread.

Parameters:

axes (Sequence[np.ndarray]) – Coordinate arrays for each data axis used to construct the Wave.

property saving

Whether a save operation is in progress.

Returns:

True if a save operation is in progress, False otherwise.

Return type:

bool

savingStateChanged

Signal (bool) emitted when saving state changes.

tagRequest

Signal (dict) emitted to request metadata tags.

update(data)[source]

Update the buffered data array with new values.

Each entry in data maps an index tuple to a frame array; the buffer is updated in-place at those indices.

Parameters:

data (dict[tuple, np.ndarray]) – Mapping from index tuples to frame arrays used to update the buffer.

class lys_instr.gui.DataStorage.DataStorageGUI(obj)[source]

Bases: QWidget

GUI widget for configuring data storage options.

Provide controls to select base folder, data folder, file name, numbering, and enable/disable saving. Update the storage backend and show a saving-status indicator.