Table Of Contents

Previous topic

Reference Guide

Next topic

nmrglue.convert

This Page

nmrglue.bruker

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.

High-Level Functions

These are the functions that most users will use from the bruker module.

nmrglue.fileio.bruker.read(dir='.', bin_file=None, acqus_files=None, pprog_file=None, shape=None, cplex=None, big=None, read_prog=True, read_acqus=True)

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).

  • big Endianness of binary file. Set to True for big-endian,

    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.

nmrglue.fileio.bruker.read_lowmem(dir='.', bin_file=None, acqus_files=None, pprog_file=None, shape=None, cplex=None, big=None, read_prog=True, read_acqus=True)

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).

  • big Endianness of binary file. Set to True for big-endian,

    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.

nmrglue.fileio.bruker.write(dir, dic, data, bin_file=None, acqus_files=None, pprog_file=None, overwrite=False, big=None, write_prog=True, write_acqus=True)

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.

  • big Endiness to write binary data with,

    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

nmrglue.fileio.bruker.write_lowmem(dir, dic, data, bin_file=None, acqus_files=None, pprog_file=None, overwrite=False, big=None, write_prog=True, write_acqus=True)

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.

  • big Endiness to write binary data with,

    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

nmrglue.fileio.bruker.read_binary(filename, shape=1, cplex=True, big=True)

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

  • big Endianness of binary file, True for big-endian, False for

    little-endian

Returns: dic,data. dic contains “FILE_SIZE” key/value.

If data cannot be reshaped 1D version of data will be returned

nmrglue.fileio.bruker.read_binary_lowmem(filename, shape=1, cplex=True, big=True)

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

  • big Endianness of binary file, True for big-endian, False for

    little-endian

Returns: dic,data. dic contains “FILE_SIZE” key/value.

Raises ValueError if shape does not agree with file size

nmrglue.fileio.bruker.write_binary(filename, dic, data, overwrite=False, big=True)

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.

  • big Endiness to write binary data with,

    bigendian=True, little=False

No return.

nmrglue.fileio.bruker.write_binary_lowmem(filename, dic, data, overwrite=False, big=True)

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.

  • big Endiness to write binary data with,

    bigendian=True, little=False

No return.

nmrglue.fileio.bruker.read_jcamp(filename)

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”]

nmrglue.fileio.bruker.write_jcamp(dic, filename, overwrite=False)

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

nmrglue.fileio.bruker.read_pprog(filename)

Parse a Bruker pulse program (pulseprogram) file for information

Parameter:

  • filename name of pulseprogram file to read from

Returns a dictionary with following keys:

  • var dictionary of variables assigned in pulseprogram
  • incr list of lists containing increment times
  • loop list of loop multipliers
  • phase list of lists containing phase elements
  • ph_extra list of lists containing comments at the end of phase lines

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.

nmrglue.fileio.bruker.write_pprog(filename, dic, overwrite=False)

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.

nmrglue.fileio.bruker.remove_digital_filter(dic, data)

Remove the digial filter from Bruker data.

Use rm_dig_filter to specify decim, dspfvs, and grpdly paraters.

Parameters:

  • dic Dictionary of Bruker parameters
  • data array of data.

Returns: array with digital filter removed

nmrglue.fileio.bruker.guess_udic(dic, data)
Guess parameters of universal dictionary from dic,data pair
nmrglue.fileio.bruker.create_dic(udic)
Create a bruker dictionary from a universal dictionary

Low-Level Functions

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.

nmrglue.fileio.bruker.create_data(data)
Create a bruker data array (recast into a complex128 or int32)
nmrglue.fileio.bruker.create_acqus_dic(adic, direct=False)
Create a acqus dictionary for an universal axis dictionary. Set direct=True for direct dimension.
nmrglue.fileio.bruker.guess_shape(dic)

Determind data shape and complexity from dictionary

Returns: (shape,cplex)

  • shape Tuple representing shape of the binary file.
  • cplex Complexity of direct dimension.

When dictionary does not contain enough information warning will be issued and (1),True is returned

nmrglue.fileio.bruker.get_data(f, big)
Get binary data from file object with given endiness
nmrglue.fileio.bruker.put_data(f, data, big=True)
Put data to file object with given endiness
nmrglue.fileio.bruker.complexify_data(data)
Complexify data packed real,imag data
nmrglue.fileio.bruker.uncomplexify_data(data_in)
Uncomplexify data (pack real,imag) into a int32 array
nmrglue.fileio.bruker.rm_dig_filter(data, decim, dspfvs, grpdly=0)

Remove the digital filter from Bruker data.

Use remove_digital_filter to find parameters from Bruker dictionary.

Parameters:

  • data Array of data.
  • decim Decimation rate (Bruker DECIM parameter).
  • dspfvs Firmware version (Bruker DSPFVS parameter).
  • grpdly Group delay, when available. (Bruker GRPDLY parameter).

grpdly is not always needed, but when provided decim and dspfvs are ignored.

Returns: array with digital filter removed.

nmrglue.fileio.bruker.parse_jcamp_line(line, f)

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.

nmrglue.fileio.bruker.write_jcamp_pair(f, key, value)

Write out a line of a JCAMP file

a ‘line’ might actually be more than one line for arrays

Low-Level Classes

class nmrglue.fileio.bruker.bruker_nd(filename, fshape, cplex, big, order=None)

Emulate a numpy.ndarray objects without loading data into memory for low memory reading of Bruker fid/ser files

  • slicing operations return ndarray objects.
  • can iterate over with expected results.
  • transpose and swapaxes methods create a new objects with correct axes ordering.
  • has ndim, shape, and dtype attributes.