Functions for reading and writing Bruker binary (ser/fid) files, Bruker JCAMP-DX parameter (acqus) files, and Bruker pulse program (pulseprogram) files.
Bruker binary files (ser/fid) store data as an array of int32s whose endiness is determinded by the parameter BYTORDA (1 = big endian, 0 = little endian). Typically the direct dimension is digitally filtered. The exact method of removing this filter is unknown but an approximation is avaliable.
Bruker JCAMP-DX files (acqus, etc) are text file which are described by the JCAMP-DX standard. Bruker parameters are prefixed with a ‘$’.
Bruker pulseprogram files are text files described in various Bruker manuals. Of special important are lines which describe external variable assignments (surrounded by “‘s), loops (begin with lo), phases (contain ip of dp) or increments (contain id, dd, ipu or dpu). These lines are parsed when reading the file with nmrglue.
This modules is imported as nmrglue.bruker and can be called as such.
These are the functions that most users will use from the bruker module.
Read Bruker files in directory
Parameters:
dir Directory to read from.
bin_file Filename of binary file in directory.
acqus_files List of filename(s) of acqus parameter files in directory.
pprog_file Filename of pulseprogram in directory.
shape Shape of resulting data (tuple).
cplex Complexity of direct dimention (True/False).
False for little-endian and None to determind automatically
read_prog True will read pulseprogram file, False prevents reading.
read_acqus True will read acqus file(s), False prevents reading.
Returns: dic,data
Only the dir parameter must be defined, others will be determined automatically if not specified.
Read Bruker files using minimal amounts of memory
Parameters:
dir Directory to read from.
bin_file Filename of binary file in directory.
acqus_files List of filename(s) of acqus parameter files in directory.
pprog_file Filename of pulseprogram in directory.
shape Shape of resulting data (tuple).
cplex Complexity of direct dimention (True/False).
False for little-endian and None to determind automatically
read_pprog True will read pulseprogram file, False prevents reading.
read_acqus True will read acqus file(s), False prevents reading.
Returns: dic,data
Only the dir parameter must be defined, others will be determined automatically if not specified.
Write Bruker files
Parameters:
dir Directory to write to.
dic dictionary holding acqus_files and pprog_file parameters.
data array of data
bin_file Filename of binary file to write to in directory
acqus_files Filename(s) of acqus files in directory to write to.
pprog_file Filename of pulseprogram in directory.
overwrite True to overwrite files, False to warn.
bigendian=True, little=False, determined from dictionary if None.
write_prog True will write pulseprogram file, False does not.
write_acqus True will write acqus file(s), False does not.
No return.
If any of bin_file,acqus_files or pprog_file are None the associated file(s) will be determined automatically
Write Bruker files trace by trace (low memory)
Parameters:
dir Directory to write to.
dic dictionary holding acqus_files and pprog_file parameters.
data array of data
bin_file Filename of binary file to write to in directory
acqus_files Filename(s) of acqus files in directory to write to.
pprog_file Filename of pulseprogram in directory.
overwrite True to overwrite files, False to warn.
bigendian=True, little=False
write_prog True will write pulseprogram file, False does not.
write_acqus True will write acqus file(s), False does not.
No return.
If any of bin_file,acqus_files or pprog_file are None the associated file(s) will be determined automatically
Read Bruker binary data from file and return dic,data pair
Parameters:
filename Filename of Bruker binary file
shape Tuple describing shape of resulting file
cplex Flag indicating if direct dimension is complex
little-endian
Returns: dic,data. dic contains “FILE_SIZE” key/value.
If data cannot be reshaped 1D version of data will be returned
Read Bruker binary data from file using minimal memory.
Parameters:
filename Filename of Bruker binary file
shape Tuple describing shape of resulting file
cplex Flag indicating if direct dimension is complex
little-endian
Returns: dic,data. dic contains “FILE_SIZE” key/value.
Raises ValueError if shape does not agree with file size
Write Bruker binary data to file
Parameters:
filename Filename to write to.
dic dictionary holding acqus_files and pprog_file parameters.
data array of data
overwrite True to overwrite files, False to warn.
bigendian=True, little=False
No return.
Write Bruker binary data to file trace by trace (using minimal memory).
Parameters:
filename Filename to write to.
dic dictionary holding acqus_files and pprog_file parameters.
data array of data
overwrite True to overwrite files, False to warn.
bigendian=True, little=False
No return.
Read a Bruker JCAMP-DX file into a dictionary
Note: This is not a fully functional JCAMP-DX reader, it is only intended to read Bruker acqus (and similar) files
Creates two special dictionary keys _coreheader and _comments
Bruker parameter “$FOO” are extracted into strings, floats or lists and assigned to dic[“FOO”]
Write a Bruker JCAMP-DX file from a dictionary
Written file will differ slightly from bruker’s JCAMP-DX files in that all multi-value parameters will be written on multiple lines. Bruker is inconsistent on what is written to a single line and what is not. In addition line breaks may be slightly different but will always be within JCAMP-DX specification. Finally long floating point values may loose precision when writing.
For example:
##$QS= (0..7)83 83 83 83 83 83 83 22
will be written as ##$QS= (0..7) 83 83 83 83 83 83 83 22
Parse a Bruker pulse program (pulseprogram) file for information
Parameter:
Returns a dictionary with following keys:
The incr,phase and ph_extra lists match up with loop list. For example incr[0],phase[0] and ph_extra[0] are all increment and phase commands with comments which occur during loop 0 which has loop[0] steps.
Write a minimal Bruker pulse program
DO NOT TRY TO RUN THE RESULTING PULSE PROGRAM
This pulse program should return the same dictionary when read using read_pprog, nothing else. The pulse program will be nonsense.
Remove the digial filter from Bruker data.
Use rm_dig_filter to specify decim, dspfvs, and grpdly paraters.
Parameters:
Returns: array with digital filter removed
These functions are typically not used directly by users. They are called by high level functions. Developers and user who want fine control over bruker files will be interested in these functions.
Determind data shape and complexity from dictionary
Returns: (shape,cplex)
When dictionary does not contain enough information warning will be issued and (1),True is returned
Remove the digital filter from Bruker data.
Use remove_digital_filter to find parameters from Bruker dictionary.
Parameters:
grpdly is not always needed, but when provided decim and dspfvs are ignored.
Returns: array with digital filter removed.
Parse a single JCAMP-DX line
Extract the Bruker parameter name and value from a line from a JCAMP-DX file. This may entail reading additional lines from the fileobj f if the parameter value extends over multiple lines.
Write out a line of a JCAMP file
a ‘line’ might actually be more than one line for arrays
Emulate a numpy.ndarray objects without loading data into memory for low memory reading of Bruker fid/ser files