Data Handling#
Data recorded using spvctrl can be easily analysed using python or be imported into other software, since it uses the hdf5 data format (with .tspv extension).
When spvctrl is installed, you can also load directly into a TspvData object and use the included plotting and transformation functions.
Hierarchy.
Transient SPV data follows devctrl’s hierarchical data structure:
Series: Required. The name of the overall measurement (series). Should start with the data in ISO-format. May include information like the sample name and the reason for the measurement.
Version: Automatic. Either
"raw"when the complete oscilloscope traced is stored, or"log-sub"for logarithmically subsampled data. Omitted when raw data is not stored.Variant: Optional. Logical categorization of a measurement within the series, e.g.
"wl=<wavelength>nm"for wavelength scans.Mode: Optional. Not used.
Part: Automatic. Each part is a single transient from a single pulse:
"pulseXXXXX". The special name"+"is the average of all pulses.
Loading Transients#
Spvctrl comes with a synthetic dataset generator that lets you create a demo-dataset for testing analysis scripts.
Here is an example script that showcases how to load and plot a dataset in multiple ways. The dataset contains multiple variants for different pump wavelengths and multiple pulses for each wavelength. For each pulse, the raw log-subsampled version is stored.
"""Example analysis script for spvctrl data.
The script stores a synthetic Transient SPV dataset at SERIES_DIR and showcases various ways to load and plot the data.
"""
import re
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
from spvctrl.data import TspvData
from spvctrl.scripts.test_data import write_demo_dataset
from devctrl.data.hdf5 import list_all_hierarchies
from devctrl.data.hdf5 import find_tld_datafile
# Optional color utilities
from mqutil.color import rainbow_color, wavelength_nm_to_hex
# Directory into which the demo dataset will be saved.
SERIES_DIR = Path("~/Downloads/spv-data-test").expanduser()
if __name__ == "__main__":
# If it does not exist, write the demo dataset to SERIES_DIR path
if not SERIES_DIR.exists():
write_demo_dataset(SERIES_DIR)
# Resolve the .tspv (hdf5) file that contains the actual data.
SERIES_FILE, _ = find_tld_datafile(SERIES_DIR, TspvData.HDF5_FULL_DATA_PATTERN)
# List all contained data in a file/dataset
hrs = list_all_hierarchies(SERIES_FILE)
print(f"Hierarchies in '{SERIES_FILE}':\n{hrs}")
# Filter out individual pulses
hrs = [h for h in hrs if h.part == "+"]
print(hrs)
# Load the averaged log-subsampled data object for the 350nm
# Since "part" is not given, the default value '+' is used, which represents the average of all pulses.
data350 = TspvData(SERIES_DIR, version="log-sub", variant="wl=350.0nm")
print(data350)
# Alternative ways to load the same data:
# a) Give part explicitly
data350 = TspvData(SERIES_DIR, version="log-sub", variant="wl=350.0nm", part="+")
# b) Sub-path
data350 = TspvData(SERIES_DIR / "log-sub/wl=350.0nm")
# c) Use path to .tspv file instead of series directory.
data350 = TspvData(SERIES_FILE, version="log-sub", variant="wl=350.0nm")
# Load subsampled data as numpy array and column list
tdata, cols = data350.get_time_data()
print(f"Log-subsampled data shape: {tdata.shape}. Columns = {cols}")
print(f"Time range: {tdata[0, cols.index('t_s')]} - {tdata[-1, cols.index('t_s')]}")
# Include pre-trigger data
ts_pre_trig = (-np.inf, np.inf)
tdata, cols = data350.get_time_data(ts=ts_pre_trig)
print(f"Log-subsampled data with pretrigger shape: {tdata.shape}. Columns = {cols}")
print(f"Time range: {tdata[0, cols.index('t_s')]} - {tdata[-1, cols.index('t_s')]}")
# Load raw data
data350_raw = TspvData(SERIES_DIR, version="raw", variant="wl=350.0nm")
tdata_raw, cols_raw = data350_raw.get_time_data()
print(f"Raw data shape: {tdata_raw.shape}. Columns = {cols_raw}")
# Plot individual pulses from one measurement
# Here, we plot data including pre-trigger on a symlog scale
fig, axs = plt.subplots(layout="constrained")
axs.set_title("TSPV Demo Dataset - Pulses for 350 nm")
axs.set_xscale("symlog", linthresh=1e-5)
pulse_datas_350 = TspvData.load_multiple(SERIES_DIR, variant="wl=350.0nm", part="*")
for i, (pulse, pdata) in enumerate(sorted(pulse_datas_350.items())):
if pulse == "+":
line_kw = dict(color="black", linestyle="dashed", label="Average", zorder=5)
else:
line_kw = dict(color=rainbow_color(0.2*i/len(pulse_datas_350)), label=pulse)
tdata, cols = pdata.get_time_data(ts=ts_pre_trig)
axs.plot(tdata[:,cols.index("t_s")], tdata[:,cols.index("U_spv_V")], **line_kw)
axs.legend()
plt.show()
# Plot individual pulses from one measurement
# Again, including pre-trigger on a symlog scale
fig, axs = plt.subplots(layout="constrained")
axs.set_title("TSPV Demo Dataset - Averaged pulses")
axs.set_xscale("symlog", linthresh=1e-5)
avg_datas = TspvData.load_multiple(SERIES_DIR, variant="*", part="+")
for i, (variant, wldata) in enumerate(sorted(avg_datas.items())):
print(f"Plotting {wldata.hierarchy}")
m = re.fullmatch(r"wl=(\d+)\.0nm", variant)
wl = int(m.groups()[0])
color = wavelength_nm_to_hex(wl)
tdata, cols = wldata.get_time_data(ts=ts_pre_trig)
axs.plot(tdata[:,cols.index("t_s")], tdata[:,cols.index("U_spv_V")], color=color, label=f"$\\lambda={wl:g}\\,$nm")
axs.legend()
plt.show()
See devctrl.doc-hierarchical-data and devctrl.doc-column-data