spvctrl.data.upgrade.TspvPulseDataFormatAdapter#

class TspvPulseDataFormatAdapter[source]#

Bases: DataFormatAdapter

Data format adapter for spvctrl pulse files (see save_pulse_hdf5()).

Methods

detect_version

Detect the data format version of a pulse measurement directory.

load

Pulse data is converted on the directory level; the loaded payload is the directory itself.

mark_conversion

Record the conversion provenance in the data before it is saved.

save

No separate save step: the conversion writes the converted files itself.

upgrade

Convert a legacy pulse cache directory in place, keeping the original as backup.

Attributes

data_type

Canonical data type this adapter handles.

latest_version

Latest format version this adapter can write.

__annotations__ = {}#
__dict__ = mappingproxy({'__module__': 'spvctrl.data.upgrade', '__firstlineno__': 37, '__doc__': 'Data format adapter for spvctrl pulse files (see :py:func:`~spvctrl.data.util.save_pulse_hdf5`).', 'data_type': 'tspv-pulse', 'latest_version': '0.1', 'detect_version': <function TspvPulseDataFormatAdapter.detect_version>, 'load': <function TspvPulseDataFormatAdapter.load>, 'save': <function TspvPulseDataFormatAdapter.save>, 'upgrade': <function TspvPulseDataFormatAdapter.upgrade>, '__static_attributes__': (), '__annotations__': {}})#
__firstlineno__ = 37#
__module__ = 'spvctrl.data.upgrade'#
__static_attributes__ = ()#
__weakref__#

list of weak references to the object

data_type: str = 'tspv-pulse'#

Canonical data type this adapter handles.

detect_version(path: Path) → str | None[source]#

Detect the data format version of a pulse measurement directory.

The directory must contain per-pulse PART_*.h5 files and/or the averaged data.h5. The version is read from the first file carrying a root data_version attribute; a directory with only legacy files (no attributes) is version "0.0".

Parameters:

path – Measurement directory.

Returns:

The data format version, or None if not recognized.

latest_version: str = '0.1'#

Latest format version this adapter can write.

load(path: Path) → Path[source]#

Pulse data is converted on the directory level; the loaded payload is the directory itself.

Parameters:

path – Measurement directory.

mark_conversion(data: Any, from_version: str, to_version: str) → None#

Record the conversion provenance in the data before it is saved.

The default implementation does nothing.

Parameters:
  • data – Upgraded data, about to be saved.

  • from_version – Format version the upgrade chain started at.

  • to_version – Format version the upgrade chain ended at.

save(data: Path, path: Path, *, write_partials: bool = False) → None[source]#

No separate save step: the conversion writes the converted files itself.

Parameters:
  • data – The loaded payload (unused).

  • path – Target directory (unused).

  • write_partials – Unused.

upgrade(path: Path, steps: list[UpgradeStep], *, strategy: str = 'backup', backup_suffix: str = '-original', out_dir: Path | str | None = None, write_partials: bool = False, progress_cb: object | None = None) → Path[source]#

Convert a legacy pulse cache directory in place, keeping the original as backup.

Delegates to convert_pulse_cache_dir(), which renames the original directory to <name>-original and writes the converted data to the original location.

Parameters:
  • path – Measurement directory.

  • steps – The resolved upgrade steps.

  • strategy – Only "backup" is supported.

  • backup_suffix – Only the default "-original" is supported (used by convert_pulse_cache_dir()).

  • out_dir – Ignored (backup strategy).

  • write_partials – Ignored.

  • progress_cb – Optional callback cb(step, index, total) invoked after the conversion.

Returns:

The path of the converted directory.