spvctrl.data.util#

Pulse file format utilities: saving, loading and converting per-pulse hdf5 files.

The per-pulse (PART_*.h5) and averaged (data.h5) files written by the measurement share one plain hdf5 format, described here. The time axis of full-resolution data is linear, so it is recalculated on load from attributes instead of being stored; downsampled data has a non-uniform (log-spaced) time axis, which is stored as a t_s dataset.

File layout:

  • Unified root attributes written by stamp_data_attrs(): data_type="tspv-pulse", data_version="0.1", writer, writer_version, time_created/time_modified, and the storage sub-format as data_encoding: DATA_TYPE_FULL_RAW, DATA_TYPE_FULL_VOLTS or DATA_TYPE_DOWNSAMPLED. Legacy files written before the attributes existed store float64 volt datasets U_spv_V/U_diode_V (equivalent to "full-volts"); files of the intermediate scheme carry the sub-format in the data_type attribute instead of data_encoding and are loaded transparently as well.

  • "full-raw": datasets U_spv_raw and optionally U_diode_raw (absent in single-channel data) with the raw ADC counts as acquired from the oscilloscope (int16 for the Gage CompuScope), plus the attributes needed to load the data in volt and to recover the time axis: - spv_gain_V_per_count/spv_offset_V and diode_gain_V_per_count/diode_offset_V: U = raw * gain_V_per_count + offset_V - sample_rate_Hz and n_pre_trigger: t_s = (np.arange(n) - n_pre_trigger) / sample_rate_Hz

  • "full-volts": datasets U_spv_V and optionally U_diode_V (float64 volts), attributes sample_rate_Hz and n_pre_trigger.

  • "downsampled": datasets U_spv_V, optionally U_diode_V, and the non-uniform time axis t_s (float64, log-downsampled); sample_rate_Hz and n_pre_trigger are recorded for reference.

  • Common attributes: pulse_idx (0-based, -1 for averaged data), timestamp (time of day string, optional).

Module attributes

WRITER_NAME

Value of the root writer attribute of pulse files.

DATA_TYPE_PULSE

Root data_type attribute value of per-pulse and averaged pulse hdf5 files.

DATA_VERSION_PULSE

Root data_version attribute value of pulse files: 0.1 is the format since the storage sub-format is recorded in the data_encoding attribute (the unified labelling scheme).

DATA_TYPE_FULL_RAW

Storage sub-format (data_encoding attribute) of files storing raw ADC counts.

DATA_TYPE_FULL_VOLTS

Storage sub-format (data_encoding attribute) of files storing float64 volt datasets.

DATA_TYPE_DOWNSAMPLED

Storage sub-format (data_encoding attribute) of files storing log-downsampled data with a non-uniform time axis.

DOWNSAMPLE_N

Default target number of points of log-downsampled data

GZIP_COMPRESSION_LEVEL

gzip compression level of the per-pulse files: the shuffle filter does the heavy lifting, a high level compresses the remaining noise-dominated bytes only marginally but much slower (measured: level 9 with shuffle is ~20x slower than level 1 for ~1.5% smaller files)

GZIP_COMPRESSION_LEVEL_AVERAGE

gzip compression level of the averaged data.h5, which is only written once per measurement

Functions

adc_conversion_from_raw_config

Compute the ADC-to-volt conversion parameters from a raw Gage CompuScope configuration dump.

convert_pulse_cache_dir

Convert a measurement cache directory from the legacy float64 volt format to the new format with raw ADC counts and gzip compression.

downsample_transient

Log-downsample a transient for plotting.

load_pulse_hdf5

Load a pulse file saved with save_pulse_hdf5(), including the time axis.

log_downsample_indices

Indices for log-downsampling a transient of length n to N points, or None to use all points if n <= N.

log_downsample_split_indices

Indices for log-downsampling a recorded transient with a pre-trigger, splitting the record at the trigger.

raw_to_volts

Convert raw ADC counts to voltages: U = raw * gain_V_per_count + offset_V.

save_downsampled_pulse_hdf5

Save a log-downsampled pulse transient to a plain hdf5 file.

save_pulse_hdf5

Save a full-resolution pulse transient to a plain hdf5 file.

volts_to_raw

Convert voltages to raw ADC counts, the inverse of raw_to_volts().