IO
Load & Save
- spinlab.io.load.autodetect(test_path, verbose=False)
Automatically detect data format
- Parameters:
test_path (str) -- Test directory
verbose (bool) -- If true, print output for debugging
- Returns:
Data format as string
- Return type:
str
- spinlab.io.load.load(path, data_format=None, dim=None, coord=[], verbose=False, *args, **kwargs)
Import data from different spectrometer formats
- Parameters:
path (str, list) -- Path to data directory or list of directories
data_format (str) -- format of spectrometer data to import (optional). Allowed values: "prospa", "topspin", "delta", "vnmrj", "tnmr", "specman", "xenon", "xepr", "winepr", "esp", "h5", "power", "vna", "cnsi_powers", "rs2d"
dim (str) -- If giving directories as list, name of dimension to concatenate data along
coord (numpy.ndarray) -- If giving directories as list, coordinates of new dimension
verbose (bool) -- If true, print debugging output
*args -- Additional positional arguments passed to the format-specific import function.
**kwargs -- Additional keyword arguments passed to the format-specific import function.
- Returns:
Data object
- Return type:
data (slData)
Examples
Load a data file
>>> data = sl.load('Path/To/File')
Load a list of files and concatenate down a new dimension called 't1' with coordinates
>>> data = sl.load(['1/data.1d','2/data.1d','3/data.1d'], dim = 't1', coord = np.r_[0.1,0.2,0.3])
- spinlab.io.load.load_file(path, data_format=None, verbose=False, *args, **kwargs)
Import data from different spectrometer formats
- Parameters:
path (str) -- Path to data directory or file
data_format (str) -- Format of spectrometer data to import (optional). Allowed values: "prospa", "topspin", "delta", "vnmrj", "tnmr", "specman", "xenon", "xepr", "winepr", "esp", "h5", "power", "vna", "cnsi_powers"
verbose (bool) -- If true, print additional debug outputs
*args -- Additional positional arguments passed to the format-specific import function.
**kwargs -- Additional keyword arguments passed to the format-specific import function.
- Returns:
Data object
- Return type:
data (slData)
- spinlab.io.save.autodetect(test_name)
Detect the save format from the file extension.
- Parameters:
test_name (str) -- File path or name including extension.
- Returns:
Detected format string —
"h5"for HDF5 or"mat"for MATLAB.- Return type:
str
- Raises:
TypeError -- If the extension is not recognized.
- spinlab.io.save.save(data_object, filename, save_type=None, *args, **kwargs)
Save data to h5 format
- Parameters:
data_object (SpinData) -- sldata object to save
filename (str) -- name of file, must include extension .h5
save_type (str) -- Type of file to save (optional). Allowed values: "h5"
- Returns:
none
- spinlab.io.h5.load_h5(path, *args, **kwargs)
Returns Dictionary of slDataObjects
- Parameters:
path (str) -- Path to h5 file
- Returns:
workspace object with data
- Return type:
sldata_collection
- spinlab.io.h5.read_dict(sldata_group)
Read a plain Python dictionary from an HDF5 group.
- Parameters:
sldata_group (h5py.Group) -- HDF5 group containing a serialized dictionary.
- Returns:
Dictionary of attributes stored in the HDF5 group.
- Return type:
dict
- spinlab.io.h5.read_sldata(sldata_group)
Read a SpinData object from an HDF5 group.
Reconstructs a complete
SpinDataobject including values, dimension labels, axis coordinates, experiment attributes, SpinLab attributes, and the processing audit log.- Parameters:
sldata_group (h5py.Group) -- HDF5 group containing a serialized SpinData object.
- Returns:
Reconstructed data object.
- Return type:
- spinlab.io.h5.save_h5(dataDict, path, overwrite=False)
Save workspace in .h5 format
- Parameters:
dataDict (dict) -- sldata_collection object to save.
path (str) -- Path to save data
overwrite (bool) -- If True, h5 file can be overwritten. Otherwise, h5 file cannot be overwritten
- spinlab.io.h5.write_dict(slDataGroup, slDataObject)
Writes dictionary to h5 file
- Parameters:
slDataGroup (h5py.Group) -- h5 group to write attrs dictionary
slDataObject (SpinData) -- SpinData object to write
- spinlab.io.h5.write_sldata(slDataGroup, slDataObject)
Takes file/group and writes slData object to it
- Parameters:
slDataGroup -- h5 group to save data to
slDataObject -- sldata object to save in h5 format
- spinlab.io.load_csv.load_csv(filename, tcol=0, real=1, imag=2, skiprows=0, maxrows=-1, convert_time=<function <lambda>>, convert_data=<function <lambda>>, **kwargs)
Load data from a CSV file
- Parameters:
filename (str) -- String or path like file that is read
tcol (int) -- column index for time data (default=0), None = not applicable, will count from 0 to npoints and then apply covert_time!
real (int) -- column index for real part (default=1), None = not applicable, will be set to zero
imag (int) -- column index for imaginary part (default=2), None = not applicable, will be set to zero
skiprows (int) -- number of rows to skip at beginning (default=0)
maxrows (int) -- if this is larger than zero, read at most maxrows rows. (default: -1)
convert_time (callable) -- callable that converts the time strings to a number (default: replaces , with .)
convert_data (callable) -- callable that converts data to a number (default: replaces , with .)
delimiter (str) -- optional, sets the delimiter in the csv file (default ; )
dims (str,list) -- optional, sets name for dimension (default: ["t2"])
object (**kwargs are forwarded to csv.reader)
- Returns:
Data object with values,coords and dim
- Return type:
data (slData)
Examples
data=load_csv('csv_arrLNA_data.csv',imag=2,skiprows=1)
Bruker
Functions to import Bruker EPR data
- spinlab.io.bes3t.import_bes3t(path)
Import Bruker BES3T data and return sldata object
- Parameters:
path (str) -- Path to either .DSC or .DTA file
- Returns:
SpinData object containing Bruker BES3T data
- Return type:
bes3t_data (object)
- spinlab.io.bes3t.load_dsc(path)
Import contents of .DSC file
- Parameters:
path (str) -- Path to .DSC file
- Returns:
dictionary of parameters
- Return type:
attrs (dict)
- spinlab.io.bes3t.load_dta(path_dta, path_xgf=None, path_ygf=None, path_zgf=None, attrs={})
Import data from .DTA file. Uses .DSC and .XGF, .YGF, or .ZGF files if they exist
- Parameters:
path_dta (str) -- Path to .DTA file
path_xgf (str) -- path to .XGF file for 1D data with nonlinear axis, "none" otherwise
path_ygf (str) -- path to .YGF file for 2D data, "none" if 1D or linear y axis
path_zgf (str) -- path to .ZGF file for 3D data, "none" if 1D/2D or linear z axis
attrs (dict) -- dictionary of parameters
- Returns:
Spectrum for 1D or spectra for 2D dims (list) : dimensions coords (ndarray) : coordinates for spectrum or spectra attrs (dict) : updated dictionary of parameters
- Return type:
values (ndarray)
- spinlab.io.bes3t.load_gf_files(path, axis_type='', axis_format='', axis_points=1, axis_min=1, axis_width=1, endian='')
Import data from .XGF, .YGF, or .ZGF files
- Parameters:
path (str) -- Path to ._GF file
axis_type (str) -- linear or nonlinear
axis_format (str) -- format of file data
axis_points (int) -- number of points in axis
axis_min (float) -- minimum value of axis
axis_width (float) -- total width of axis
endian (float) -- endian of data
- Returns:
axis coordinates
- Return type:
coords (ndarray)
- spinlab.io.winepr.import_winepr(path)
Import Bruker par/spc data and return SpinData object
- Parameters:
path (str) -- Path to either .par or .spc file
- Returns:
SpinData object containing Bruker par/spc data
- Return type:
parspc_data (object)
- spinlab.io.winepr.load_par(path)
Import contents of .par file
- Parameters:
path (str) -- Path to .par file
- Returns:
dictionary of parameters
- Return type:
attrs (dict)
- spinlab.io.winepr.load_spc(path, attrs)
Import data and axes of .spc file
- Parameters:
path (str) -- Path to .spc file
- Returns:
coordinates for spectrum or spectra values (ndarray) : data values attrs (dict) : updated dictionary of parameters dims (list) : dimension labels
- Return type:
coords (ndarray)
- spinlab.io.topspin.find_group_delay(attrs_dict)
Determine group delay from tables
- Parameters:
attrs_dict (dict) -- dictionary of topspin acquisition parameters
- Returns:
Group delay. Number of points FID is shifted by DSP. The ceiling of this number (group delay rounded up) is the number of points should be removed from the start of the FID.
- Return type:
float
- spinlab.io.topspin.import_topspin(path, assign_vdlist=False, remove_digital_filter=False, read_offset=False, verbose=False, **kwargs)
Import topspin data and return sldata object
- Parameters:
path (str) -- Directory of data
assign_vdlist -- False, or the name of dimension to assign topspin vdlist
remove_digital_filter (bool) -- Option to remove group delay (see note below)
verbose (bool) -- Print additional output for troubleshooting
Note
The group delay is a consequence of the oversampling and digital filtering in Bruker spectrometers. For more details see these blog posts https://nmr-analysis.blogspot.com/2010/05/bruker-smiles.html and https://nmr-analysis.blogspot.com/2010/05/bruker-smiles.html
- Returns:
topspin data
- Return type:
sldata
- spinlab.io.topspin.load_acqu(path, required_params=None, verbose=False)
Import topspin acqu or proc files
- Parameters:
path (str) -- directory of acqu or proc file
required_params (list) -- Only return parameters given
verbose (bool) -- If true, print output for troubleshooting
- Returns:
Dictionary of acquisition parameters
- Return type:
dict
- spinlab.io.topspin.load_bin(path, dtype='>i4')
Import Topspin Ser file
- Parameters:
path (str) -- Directory of data
dtype (str) -- data format for import
- Returns:
Data from ser file
- Return type:
raw (np.ndarray)
- spinlab.io.topspin.load_pdata(path, verbose=False)
Import TopSpin processed data
- Parameters:
path (str) -- Directory of pdata
verbose (bool) -- If true, print output for troubleshooting
- Returns:
Topspin processed data
- Return type:
- spinlab.io.topspin.load_ser(path, dtype='>i4')
Deprecated. Use load_bin. Import Topspin Ser file
- Parameters:
path (str) -- Directory of data
dtype (str) -- data format for import
- Returns:
Data from ser file
- Return type:
raw (np.ndarray)
- spinlab.io.topspin.load_title(path='1', title_path='pdata/1', title_filename='title')
Import Topspin Experiment Title File
- Parameters:
path (str) -- Directory of title
title_path (str) -- Path within experiment of title
title_filename (str) -- filename of title
- Returns:
Contents of experiment title file
- Return type:
str
- spinlab.io.topspin.load_topspin_jcamp_dx(path, verbose=False)
Return the contents of topspin JCAMP-DX file as dictionary
- Parameters:
path (str) -- Path to file
verbose (bool) -- If true, print output for troubleshooting
- Returns:
Dictionary of JCAMP-DX file parameters
- Return type:
dict
- spinlab.io.topspin.topspin_vdlist(path)
Return topspin vdlist
- Parameters:
path (str) -- Directory of data
- Returns:
vdlist as numpy array
- Return type:
numpy.ndarray
JEOL
- spinlab.io.delta.import_delta(path, verbose=False)
Import Delta data and return SpinData object
Currently only 1D and 2D data sets are supported.
- Parameters:
path (str) -- Path to .jdf file
- Returns:
SpinData object containing Delta data
- Return type:
sldata (SpinData)
- spinlab.io.delta.import_delta_data(path, params={}, verbose=False)
Import spectrum or spectra of Delta data
Currently only 1D and 2D data sets are supported.
- Parameters:
path (str) -- Path to .jdf file
params (dict) -- dictionary of parameters
- Returns:
spectrum or spectra if >1D abscissa (list) : coordinates of axes dims (list) : axes names params (dict) : updated dictionary of parameters
- Return type:
y_data (ndarray)
- spinlab.io.delta.import_delta_pars(path, context_start)
Import parameter fields of Delta data
- Parameters:
path (str) -- Path to .jdf file
context_start (int) -- the index where the context starts
- Returns:
dictionary of parameter fields and values
- Return type:
params (dict)
Varian / Agilent
- spinlab.io.vnmrj.array_coords(attrs)
Return array dimension coords from parameters dictionary
- Parameters:
attrs (dict) -- Dictionary of procpar parameters
- Returns:
dim and coord for array
- Return type:
tuple
- spinlab.io.vnmrj.import_fid(path, filename='fid')
Import VnmrJ fid file
- Parameters:
path (str) -- Directory of fid file
filename (str) -- Name of fid file. "fid" by default
- Returns:
Array of data
- Return type:
numpy.ndarray
- spinlab.io.vnmrj.import_procpar(path, filename='procpar')
Import VnmrJ procpar parameters file
- Parameters:
path (str) -- Directory of file
- Returns:
Dictionary of procpar parameters
- Return type:
dict
- spinlab.io.vnmrj.import_vnmrj(path, fidFilename='fid', paramFilename='procpar')
Import VnmrJ Data
- Parameters:
path (str) -- path to experiment folder
fidFilename (str) -- FID file name
paramFilename (str) -- process parameter filename
- Returns:
data in sldata object
- Return type:
sldata
Magritek
- spinlab.io.prospa.import_csv(path, return_raw=False, is_complex=True)
Import Kea csv file
- Parameters:
path (str) -- Path to csv file
- Returns:
x(numpy.array): axes if return_raw = False data(numpy.array): Data in csv file
- Return type:
tuple
- spinlab.io.prospa.import_nd(path)
Import Kea binary 1d, 2d, 3d, 4d files
- Parameters:
path (str) -- Path to file
- Returns:
x (None, numpy.array): Axes if included in binary file, None otherwise data (numpy.array): Numpy array of data
- Return type:
tuple
- spinlab.io.prospa.import_par(path)
Import Kea parameters .par file
- Parameters:
path (str) -- Path to parameters file
- Returns:
Dictionary of Kea Parameters
- Return type:
dict
- spinlab.io.prospa.import_prospa(path, parameters_filename=None, experiment=None, verbose=False)
Import Kea data
- Parameters:
path (str) -- Path to data
parameters_filename (str)
experiment (str) -- Prospa experiment, used when calculating coords from parameters
verbose (bool) -- If true, prints additional information for troubleshooting
- Returns:
sldata object with Kea data
- spinlab.io.prospa.prospa_coords(attrs, data_shape, experiment)
Generate coords from prospa acquisition parameters
- Parameters:
attrs (dict) -- Dictionary of prospa acqusition parameters
data_shape (tuple) -- Shape of data
- Returns:
dims and coords
- Return type:
tuple
FeMi
- spinlab.io.specman.analyze_attrs(attrs)
Analyze the attrs and add some important attrs to existing dictionary
- Parameters:
attrs (dict) -- Dictionary of specman acqusition parameters
- Returns:
The dictionary of specman acqusition parameters and added parameters
- Return type:
attrs (dict)
- spinlab.io.specman.calculate_specman_coords(attrs, old_coords, dims=None)
Generate coords from specman acquisition parameters
- Parameters:
attrs (dict) -- Dictionary of specman acqusition parameters
dims (list) -- (Optional) a list of dims
- Returns:
a calculated coords
- Return type:
coords (list)
- spinlab.io.specman.generate_dims(attrs)
Generate dims from specman acquisition parameters
- Parameters:
attrs (dict) -- Dictionary of specman acqusition parameters
- Returns:
a new dims
- Return type:
dims (list)
- spinlab.io.specman.import_specman(path, autodetect_coords: bool = True, autodetect_dims: bool = True, make_complex: bool = True, complex_dim: str = 'x')
Import SpecMan data and return SpinData object
SpinLab function to import SpecMan4EPR data (https://specman4epr.com/). The function returns a Spindata object with the spectral data.
The structure of the Spindata object can be complex and the variables saved by SpecMan depend on the individual spectrometer configuration. Therefore, the import function returns a numpy array with the dimension "x0", "x1", "x2", "x3", "x4". In any case, the dimension "x0" corresponds to the variables stored in the data file. The spectroscopic data is stored in "x1" to "x4", depending on how many dimensions were recorded. The import function will require a parser script to properly assign the spectroscopic data and proper coordinates.
- Parameters:
path (str) -- Path to either .exp file
autodetect_coords (bool) -- Autodetect coords based on attrs
autodetect_dims (bool) -- Autodetect dims based on attrs
make_complex (bool) -- If True, will create a complex SpinData object if the data is complex
complex_dim (str) -- The dimension to use for complex data (default: 'x')
- Returns:
SpinData object containing SpecMan EPR data
- Return type:
data (SpinData)
- spinlab.io.specman.load_specman_d01(path, attrs, verbose=False)
Import SpecMan d01 data file
SpinLab function to import the SpecMan d01 data file. The format of the SpecMan data file is described here:
- Parameters:
path (str) -- Path to either .d01 or .exp file
- Returns:
SpecMan data as numpy array params (dict): Dictionary with import updated parameters dictionary
- Return type:
data (ndarray)
- spinlab.io.specman.load_specman_exp(path)
Import SpecMan parameters
SpinLab function to read and import the SpecMan exp file. The .exp file is a text file that stores the experimental data, the pulse program, and other spectrometer configuration files.
- Parameters:
path (str) -- Path to either .d01 or .exp file
- Returns:
Dictionary of parameter fields and values (SpinLab attributes)
- Return type:
attrs (dict)
Tecmag
- spinlab.io.tnmr.import_tnmr(path, squeeze=True)
Import tnmr data and return SpinData object
- Parameters:
path (str) -- Path to .jdf file
squeeze (bool) -- Automatically remove length 1 dimensions
- Returns:
SpinData object containing tnmr data
- Return type:
sldata (object)
- spinlab.io.tnmr.import_tnmr_data(path)
Import spectrum or spectra of tnmr data
- Parameters:
path (str) -- Path to .tnt file
- Returns:
Spectrum or spectra if >1D abscissa (list): Coordinates of axes dims (list): Axes names
- Return type:
data (ndarray)
RS2D
- spinlab.io.rs2d.import_rs2d(path, datafile='data.dat', headerfile='header.xml', *args, **kwargs)
Import data from an RS2D file.
Accepts either the
header.xmlordata.datfile; the companion file is located automatically in the same directory.- Parameters:
path (str) -- Path to the
header.xmlordata.datfile.datafile (str) -- Name of the binary data file. Default is
"data.dat".headerfile (str) -- Name of the XML header file. Default is
"header.xml".**kwargs -- Additional keyword arguments passed to the data reader (e.g.
endianess,fmt,fmt_size).
- Returns:
Imported data object with axes and acquisition parameters.
- Return type:
Other
- spinlab.io.vna.get_sldata(values, coords, attrs, concat_dim=None)
Construct a SpinData object from VNA data arrays.
For 1D data (single S-parameter trace) a single SpinData is returned. For 2D data (multiple traces, e.g. all four S-parameters of an s2p file) the traces are concatenated along
concat_dim.- Parameters:
values (numpy.ndarray) -- S-parameter data, 1D or 2D.
coords (numpy.ndarray) -- Frequency axis array.
attrs (dict) -- Acquisition attributes (format, center frequency, span).
concat_dim (str, optional) -- Name of the new dimension when concatenating multiple traces. Default is
None.
- Returns:
Data object containing the VNA measurement.
- Return type:
- spinlab.io.vna.import_snp(path, *args, **kwargs)
Import sNp file and return numpy array
- spinlab.io.vna.import_vna(path, *args, **kwargs)
Import VNA data and return sldata object
- spinlab.io.cnsi.get_powers(path, power_file, experiment_list)
Split power readings files into array of power measurements equal in length to number of spectra in dataset
- Parameters:
path (str) -- Path to base folder containing power file
power_file (str) -- filename, "power" or "t1_powers"
experiment_list (list) -- list of folder numbers of experiments corresponding to power_file
- Returns:
list of power readings equal in length to experiment_list
- Return type:
power_list (list)
- spinlab.io.power.assign_power(dataDict, expNumList, powersList)
Given a dictionary of slData objects with key being folder string, return the data with power values assigned to a new axis dimension
- Parameters:
dataDict (dict) -- dictionary of data objects
expNumList (list) -- List of experiment numbers
powersList (list) -- List of powers
- Returns:
Data object with powers
- Return type:
- spinlab.io.power.chop_power(t, p, threshold=0.1)
Use Derivative to chop Powers
- Parameters:
t (numpy.ndarray) -- Array of time points
p (numpy.ndarray) -- Array of powers
threshold (float) -- Threshold to chop powers
- Returns:
Array of average time values averagePowerArray: Array of average power values
- Return type:
averageTimeArray
- spinlab.io.power.import_power(path, filename='')
import powers file
- Parameters:
path (str) -- Directory of powers
filename (str) -- filename of powers if given
- Returns:
Array of time points p (numpy.ndarray): Array of powers
- Return type:
t (numpy.ndarray)