Loading Data
SpinLab can import data from a wide range of spectrometer formats. The universal entry point is the sl.load() function — in most cases it detects the file format automatically from the file extension or directory contents.
import spinlab as sl
data = sl.load("path/to/my/data")
The result is always a The SpinData Object ready for processing.
Automatic Format Detection
SpinLab inspects the file extension (or the contents of a directory) to determine the format. The table below shows which formats are detected automatically:
Spectrometer / Software |
Extension / Indicator |
Format string |
|---|---|---|
Bruker Xepr / Elexsys (BES3T) |
|
|
Bruker WinEPR / ESP |
|
|
Bruker TopSpin (raw) |
directory with |
|
Bruker TopSpin (processed) |
directory with |
|
Varian / Agilent VnmrJ |
|
|
JEOL Delta |
|
|
Magritek Prospa |
|
|
FeMi SpecMan4EPR |
|
|
Tecmag TNMR |
|
|
RS2D |
|
|
VNA (S-parameters) |
|
|
SpinLab HDF5 |
|
|
CSV |
(use |
— |
If autodetection fails, pass the format explicitly:
data = sl.load("path/to/data", data_format="topspin")
Format-by-Format Examples
Bruker Xepr / Elexsys (BES3T)
Point sl.load() at the .DTA or .DSC file. Axis files (.XGF, .YGF, .ZGF) are loaded automatically if present:
data = sl.load("experiment/1D_CW.DTA")
print(data)
Bruker WinEPR / ESP
Pass the .par or .spc file:
data = sl.load("spectrum.par")
Bruker TopSpin (raw FID / SER)
Pass the experiment directory (the folder containing acqus). SpinLab reads the fid or ser binary file and applies the acquisition parameters automatically:
data = sl.load("path/to/topspin/1/")
Bruker TopSpin (processed pdata)
Pass the pdata/1 subdirectory (the folder containing procs):
data = sl.load("path/to/topspin/1/pdata/1/")
Varian / Agilent VnmrJ
Pass the .fid directory:
data = sl.load("experiment.fid/")
JEOL Delta
Pass the .jdf file:
data = sl.load("spectrum.jdf")
Magritek Prospa
Pass the .1d (or .2d, .3d, .4d) file:
data = sl.load("experiment.1d")
FeMi SpecMan4EPR
Pass the .d01 or .exp file:
data = sl.load("experiment.d01")
CSV Files
CSV files are not handled by sl.load() — use sl.load_csv() directly. By default it expects columns: time (col 0), real (col 1), imaginary (col 2):
data = sl.load_csv(
"data.csv",
tcol=0, # column index for the time/x axis
real=1, # column index for real part
imag=2, # column index for imaginary part
skiprows=1, # skip one header row
delimiter=","
)
SpinLab HDF5 (.h5)
HDF5 is SpinLab's own storage format (see Saving Data). Load it exactly like any other file:
data = sl.load("experiment.h5")
If the .h5 file contains multiple datasets (saved as a dictionary), a Python dictionary of SpinData objects is returned:
workspace = sl.load("workspace.h5")
data_nmr = workspace["nmr"]
data_epr = workspace["epr"]
Loading Multiple Files
Pass a list of paths together with a dim name and a coord array to concatenate several files along a new dimension in one step. This is useful for, e.g., a power series or a time series:
import numpy as np
paths = ["power_1mW.DTA", "power_5mW.DTA", "power_10mW.DTA"]
powers = np.array([1e-3, 5e-3, 10e-3]) # in Watts
data = sl.load(paths, dim="power", coord=powers)
print(data.dims) # ['B0', 'power']
print(data.shape) # (2250, 3)
The individual spectra are stacked along the new "power" dimension. The coord array must have the same length as the list of paths.
Saving Data
Use sl.save() to write a SpinData object to an HDF5 file. HDF5 preserves the full object — values, axes, all attributes, and the processing audit log:
sl.save(data, "processed_data.h5")
To save multiple datasets in a single file, pass a dictionary:
workspace = {"nmr": data_nmr, "epr": data_epr}
sl.save(workspace, "workspace.h5")
Note
By default sl.save() will raise an error if the file already exists.
Pass overwrite=True to allow overwriting:
sl.save(data, "processed_data.h5", overwrite=True)
Further Reading
The SpinData Object — understand the object that
sl.load()returnsProcessing Data — process the data after loading
IO — full API reference for all I/O functions