pyspecdata.load_files package

Submodules

pyspecdata.load_files.acert module

Open ACERT-format HDF5 files. Provides post-processing routines for: ‘ELDOR’ ‘ELDOR_3D’ ‘FID’ ‘echo_T2’ ‘B1_se’ (which are typically experiment names set in (h5 root).experiment.description['class'])

pyspecdata.load_files.acert.automagical_phasecycle(data, verbose=False)

Use the phase cycle list to determine the phase cycles, and then ift them to return coherence skips

pyspecdata.load_files.acert.load_cw(filename, use_sweep=False)

load the cw file given by filename

Parameters:use_sweep (bool) – If true, return the axis labeled by sweep current rather than by field.
pyspecdata.load_files.acert.load_pulse(filename, indirect_dimlabels=None, prefilter=None)

Load ACERT pulse data from the 95 GHz.

Parameters:
  • indirect_dimlabels (str) – In case dimlabels is not set properly, I can manually pass the value of indirect_dimlabels.
  • prefilter (tuple) – If prefilter is set, FT the result, and select a specific slice. I should think of a more general way of doing this, where I pass an ndshape-based slice, instead.
pyspecdata.load_files.acert.postproc_B1_se(data)
pyspecdata.load_files.acert.postproc_b1_fid_file(data, fl=None, **kwargs)
pyspecdata.load_files.acert.postproc_blank(data)
pyspecdata.load_files.acert.postproc_cw(data, phase=True, use_sweep=False)

this opens the cw data, using search_freed_file and open_cw_file, and then autophases it

pyspecdata.load_files.acert.postproc_echo_T2(data)
pyspecdata.load_files.acert.postproc_eldor_3d(data)
pyspecdata.load_files.acert.postproc_eldor_file(data, fl=None)
pyspecdata.load_files.acert.postproc_eldor_old(data, **kwargs)
pyspecdata.load_files.acert.postproc_generic(data)

pyspecdata.load_files.bruker_esr module

pyspecdata.load_files.bruker_esr.winepr(filename, dimname='')

For opening WinEPR files.

Parameters:filename (str) – The filename that ends with either .par or .spc.
pyspecdata.load_files.bruker_esr.winepr_load_acqu(filename)

Load the parameters for the winepr filename

pyspecdata.load_files.bruker_esr.xepr(filename, dimname='', verbose=False)

For opening Xepr files.

Parameters:filename (str) – The filename that ends with .DSC, .DTA, or .YGF.
pyspecdata.load_files.bruker_esr.xepr_load_acqu(filename)

Load the Xepr acquisition parameter file, which should be a .dsc extension.

Returns:
  • A dictionary of the relevant results.
  • Because of the format of the .dsc files, this is a dictionary of
  • dictionaries, where the top-level keys are the hash-block (*i.e.*
  • #DESC, etc.).

pyspecdata.load_files.bruker_nmr module

pyspecdata.load_files.bruker_nmr.det_phcorr(v)
pyspecdata.load_files.bruker_nmr.det_rg(a)

determine the actual voltage correction from the value of rg for a bruker NMR file

pyspecdata.load_files.bruker_nmr.load_1D(file_reference, *subpath, **kwargs)

Load 1D bruker data into a file. Load acquisition parameters into property ‘acq’ and processing parameters from procno 1 only into ‘proc’

Note that is uses the ‘procs’ file, which appears to contain the correct data

pyspecdata.load_files.bruker_nmr.load_acqu(file_reference, *subpath, **kwargs)

based on file_reference, determine the jcamp file that stores the acquisition info, and load it

Parameters:
  • file_reference – the file reference – see open_subpath
  • subpath – the subpath – see open_subpath
  • whichdim (optional string) – Default null string – for multi-dimensional data, there is a separate acqu file for each dimension
  • return_s (bool) – Default True – whether to return the parameters of the saved data, or those manipulated since then.
pyspecdata.load_files.bruker_nmr.load_jcamp(file_reference, *subpath)

return a dictionary with information for a jcamp file

pyspecdata.load_files.bruker_nmr.load_title(file_reference, *subpath)
pyspecdata.load_files.bruker_nmr.load_vdlist(file_reference, *subpath, **kwargs)
pyspecdata.load_files.bruker_nmr.match_line(line, number_re, string_re, array_re)
pyspecdata.load_files.bruker_nmr.series(file_reference, *subpath, **kwargs)

For opening Bruker ser files. Note that the expno is included as part of the subpath.

Parameters:
  • filename – see open_subpath()
  • subpath – the path within the directory or zip file that’s one level up from the ser file storing the raw data (this is typically a numbered directory).

pyspecdata.load_files.open_subpath module

pyspecdata.load_files.open_subpath.open_subpath(file_reference, *subpath, **kwargs)
Parameters:
  • file_reference (str or tuple) – If a string, then it’s the name of a directory. If it’s a tuple, then, it has three elements: the ZipFile object, the filename of the zip file (for reference), and the name of the file we’re interested in within the zip file.
  • test_only (bool) – just test if the path exists

pyspecdata.load_files.prospa module

routines specific to loading information from prospa files

pyspecdata.load_files.prospa.decim_correct(data)
pyspecdata.load_files.prospa.load_1D(filename)
pyspecdata.load_files.prospa.load_2D(filename, dimname='')
pyspecdata.load_files.prospa.load_acqu(file)
pyspecdata.load_files.prospa.load_datafile(file, dims=1)

load a prospa datafile into a flat array as a 1D file use dims=2 if it’s a 2D file

pyspecdata.load_files.prospa.t1_info(file)

Module contents

This subpackage holds all the routines for reading raw data in proprietary formats. It’s intended to be accessed entirely through the function find_file(), which uses :module:`datadir` to search for the filename, then automatically identifies the file type and calls the appropriate module to load the data into an nddata.

Currently, Bruker file formats (both ESR and NMR) are supported, as well as (at least some earlier iteration) of Magritek file formats.

Users/developers are very strongly encouraged to add support for new file types.

pyspecdata.load_files.find_file(searchstring, exp_type=None, postproc=None, print_result=True, verbose=False, prefilter=None, expno=None, dimname='', return_acq=False, add_sizes=[], add_dims=[], use_sweep=None, indirect_dimlabels=None, lookup={}, **kwargs)

Find the file given by the regular expression searchstring inside the directory identified by exp_type, load the nddata object, and postprocess with the function postproc.

It looks at the top level of the directory first, and if that fails, starts to look recursively. Whenever it finds a file in the current directory, it will not return data from files in the directories underneath. (For information on how to set up the file searching mechanism, see register_directory()).

Note that all loaded files will be logged in the data_files.log file in the directory that you run your python scripts from (so that you can make sure they are properly synced to the cloud, etc.).

It calls load_indiv_file(), which finds the specific routine from inside one of the modules (sub-packages) associated with a particular file-type.

If it can’t find any files matching the criterion, it logs the missing file and throws an exception.

Parameters:
  • searchstring (str) – Most commonly, this is just a fragment of the file name, with any literal *, ., or ? characters preceded by a backslash. More generally, it is a regular expression, where .*searchstring.* matches a filename inside the directory appropriate for exp_type.
  • expno (int) – For Bruker NMR and Prospa files, where the files are stored in numbered subdirectories, give the number of the subdirectory that you want. Currently, this parameter is needed to load Bruker and Kea files. If it finds multiple files that match the regular expression, it will try to load this experiment number from all the directories.
  • exp_type (str) – Since the function assumes that you have different types of experiments sorted into different directories, this argument specifies the type of experiment see getDATADIR() for more info.
  • postproc (function, str, or None) –

    This function is fed the nddata data and the remaining keyword arguments (kwargs) as arguments. It’s assumed that each module for each different file type provides a dictionary called postproc_lookup (some are already available in pySpecData, but also, see the lookup argument, below).

    If postproc is a string, it looks up the string inside the postproc_lookup dictionary that’s appropriate for the file type.

    If postproc is None, it checks to see if the any of the loading functions that were called set the postproc_type property – i.e. it checks the value of data.get_prop('postproc_type') – if this is set, it uses this as a key to pull the corresponding value from postproc_lookup. For example, if this is a bruker file, it sets postproc to the name of the pulse sequence.

    For instance, when the acert module loads an ACERT HDF5 file, it sets postproc_type to the value of (h5 root).experiment.description['class']. This, in turn, is used to choose the type of post-processing.

    dimname:passed to load_indiv_file()
    return_acq:passed to load_indiv_file()
    add_sizes:passed to load_indiv_file()
    add_dims:passed to load_indiv_file()
    use_sweep:passed to load_indiv_file()
    indirect_dimlabels:
     passed to load_indiv_file()
  • lookup (dictionary with str:function pairs) – types of postprocessing to add to the postproc_lookup dictionary
pyspecdata.load_files.find_file(searchstring, exp_type=None, postproc=None, print_result=True, verbose=False, prefilter=None, expno=None, dimname='', return_acq=False, add_sizes=[], add_dims=[], use_sweep=None, indirect_dimlabels=None, lookup={}, **kwargs)

Find the file given by the regular expression searchstring inside the directory identified by exp_type, load the nddata object, and postprocess with the function postproc.

It looks at the top level of the directory first, and if that fails, starts to look recursively. Whenever it finds a file in the current directory, it will not return data from files in the directories underneath. (For information on how to set up the file searching mechanism, see register_directory()).

Note that all loaded files will be logged in the data_files.log file in the directory that you run your python scripts from (so that you can make sure they are properly synced to the cloud, etc.).

It calls load_indiv_file(), which finds the specific routine from inside one of the modules (sub-packages) associated with a particular file-type.

If it can’t find any files matching the criterion, it logs the missing file and throws an exception.

Parameters:
  • searchstring (str) – Most commonly, this is just a fragment of the file name, with any literal *, ., or ? characters preceded by a backslash. More generally, it is a regular expression, where .*searchstring.* matches a filename inside the directory appropriate for exp_type.
  • expno (int) – For Bruker NMR and Prospa files, where the files are stored in numbered subdirectories, give the number of the subdirectory that you want. Currently, this parameter is needed to load Bruker and Kea files. If it finds multiple files that match the regular expression, it will try to load this experiment number from all the directories.
  • exp_type (str) – Since the function assumes that you have different types of experiments sorted into different directories, this argument specifies the type of experiment see getDATADIR() for more info.
  • postproc (function, str, or None) –

    This function is fed the nddata data and the remaining keyword arguments (kwargs) as arguments. It’s assumed that each module for each different file type provides a dictionary called postproc_lookup (some are already available in pySpecData, but also, see the lookup argument, below).

    If postproc is a string, it looks up the string inside the postproc_lookup dictionary that’s appropriate for the file type.

    If postproc is None, it checks to see if the any of the loading functions that were called set the postproc_type property – i.e. it checks the value of data.get_prop('postproc_type') – if this is set, it uses this as a key to pull the corresponding value from postproc_lookup. For example, if this is a bruker file, it sets postproc to the name of the pulse sequence.

    For instance, when the acert module loads an ACERT HDF5 file, it sets postproc_type to the value of (h5 root).experiment.description['class']. This, in turn, is used to choose the type of post-processing.

    dimname:passed to load_indiv_file()
    return_acq:passed to load_indiv_file()
    add_sizes:passed to load_indiv_file()
    add_dims:passed to load_indiv_file()
    use_sweep:passed to load_indiv_file()
    indirect_dimlabels:
     passed to load_indiv_file()
  • lookup (dictionary with str:function pairs) – types of postprocessing to add to the postproc_lookup dictionary
pyspecdata.load_files.search_filename(searchstring, exp_type, print_result=True, unique=False)

Use regular expression searchstring to find a file inside the directory indicated by exp_type (For information on how to set up the file searching mechanism, see register_directory()).

Parameters:
  • searchstring (str) – Most commonly, this is just a fragment of the file name, with any literal *, ., or ? characters preceded by a backslash. More generally, it is a regular expression, where .*searchstring.* matches a filename inside the directory appropriate for exp_type.
  • exp_type (str) – Since the function assumes that you have different types of experiments sorted into different directories, this argument specifies the type of experiment see getDATADIR() for more info.
  • unique (boolean (default False)) – If true, then throw an error unless only one file is found.
pyspecdata.load_files.load_indiv_file(filename, dimname='', return_acq=False, add_sizes=[], add_dims=[], use_sweep=None, indirect_dimlabels=None, expno=None)

Open the file given by filename, use file signature magic and/or filename extension(s) to identify the file type, and call the appropriate function to open it.

Parameters:
  • dimname (str) – When there is a single indirect dimension composed of several scans, call the indirect dimension dimname.
  • return_acq (DEPRECATED) –
  • add_sizes (list) – the sizes associated with the dimensions in add_dims
  • add_dims (list) – Can only be used with dimname. Break the dimension dimname into several dimensions, with the names given by the list add_dims and sizes given by add_sizes. If the product of the sizes is not the same as the original dimension given by dimname, retain it as the “outermost” (leftmost) dimension. pyspecdata.core.chunkoff() is used to do this, like so: data.chunkoff(dimname,add_dims,add_sizes)
  • indirect_dimlabels (str or None) – passed through to acert.load_pulse (names an indirect dimension when dimlabels isn’t provided)
Returns:

the nddata containing the data, or else, None, indicating that this is part of a pair of files that should be skipped

Return type:

nddata or None

pyspecdata.load_files.format_listofexps(args)

Phased out: leaving documentation so we can interpret and update old code

This is an auxiliary function that’s used to decode the experiment list.

Parameters:args (list or tuple) –

can be in one of two formats :(dirname,[i,j,k,...N]): typically used, e.g. for

Bruker NMR experiments. i,j,...N are integer numbers referring to individual experiments that are stored in subdirectories of dirname (a string).
([exp_name1,...,exp_nameN]):
 just return this list of experiments given by the strings exp_name1…`exp_nameN`.
([exp_name1,...,exp_nameN],[]):
 identical to previous
([exp_name1,...,exp_nameN],[]):
 identical to previous
(exp_name1,...,exp_nameN):
 identical to previous
(exp_name) or (exp_name,[]):
 works for a single experiment
pyspecdata.load_files.load_t1_axis(file)
pyspecdata.load_files.bruker_load_t1_axis(file)
pyspecdata.load_files.prospa_t1_info(file)
pyspecdata.load_files.bruker_load_title(file)
pyspecdata.load_files.bruker_dir(search_string, exp_type)

A generator that returns a 3-tuple of dirname, expno, and dataset for a directory

pyspecdata.load_files.cw(file, **kwargs)