Table Of Contents

Previous topic

nmrglue.table

Next topic

nmrglue.proc_base

This Page

nmrglue.varian

Functions for reading and writing Varian binary (fid) files and Varian parameter (procpar) files.

Both file formats are documented in:

  • Varain MR News 2005-04-18 Importing Binary VnmrJ / VNMR FIDs into Third Party Software and VnmrJ / VNMR FID Data Format
  • VnmrJ User Programming - Chapter 5: Parameters and Data

These are available (as of 04/2011) online from Agilent.

This modules is imported as nmrglue.varian and can be called as such.

High-Level Functions

These are the functions most users will use from the varian module.

nmrglue.fileio.varian.read(dir='.', fid_file='fid', procpar_file='procpar', read_blockhead=False, shape=None, torder=None)

Read Varian files in a directory.

Parameters:

  • dir Directory holding Varian data.
  • fid_file Name of fid file in directory.
  • procpar_file Name of procpar file in directory.
  • read_blockhead Set True to read blockheader(s). False otherwise.
  • shape Shape of data, None tries to finds this automatically.
  • torder Trace order (None for automatic). See read function.

Returns: dic,data

Note in torder parameter:

torder is a parameter describing how the traces on disk should be re-organized to form the data matrix. In many cases this can be determined automatically by examining the order of phase parameters in the procpar file, which is what is done if torder is set to None, but in some cases it must be explicitly provided. Three common cases are:

Regular ordering (d3,d2,phase2,phase) which can be specificed by setting torder to ‘regular’ or ‘r’.

Opposite ordering (d3,d2,phase,phase2) which can be specified by setting torder to ‘opposite’ or ‘o’.

Flat ordering, the way data is on organized on disk, no reordering is performed. 1D and 2D file can be read in this manner. Specify by setting torder to ‘flat’ or ‘f’.

In addition a function which maps indirect dimension index tuples to/from trace number as stored on disk can be provided. For reading this function should take 2 arguments (shape,index_tuple) and return an integer trace number. For writing this function should again take 2 arguments (shape,trace_number) and return the indirect dimension index tuple for the given trace.

nmrglue.fileio.varian.read_lowmem(dir='.', fid_file='fid', procpar_file='procpar', read_blockhead=False, shape=None, torder=None)

Read Varian files in a directory using minimal memory.

Parameters:

  • dir Directory holding Varian data.
  • fid_file Name of fid file in directory.
  • procpar_file Name of procpar file in directory.
  • read_blockhead Set True to head blockheader(s). False otherwise.
  • shape Shape of data, None tries to finds this automatically.
  • torder Trace order (None for automatic). See read function.

Returns: dic,data

nmrglue.fileio.varian.write(dir, dic, data, fid_file='fid', procpar_file='procpar', torder=None, repack=False, overwrite=False)

Write Varian files to a directory.

Parameters:

  • dir Directory to write to.
  • dic Python dictionary of file parameters.
  • data Array of spectral data to write.
  • fid_file Name of fid file to write to.
  • procpar_file Name of procpar file to write to.
  • torder Trace order (None for automatic). See read function.
  • repack True/False to repack file and block headers.
  • overwrite True/False to overwrite existing file.

No return value.

nmrglue.fileio.varian.write_lowmem(dir, dic, data, fid_file='fid', procpar_file='procpar', torder=None, repack=False, overwrite=False)

Write Varian files to a directory using minimal memory

Parameters:

  • dir Directory to write to.
  • dic Python dictionary of file parameters.
  • data Array of spectral data to write.
  • fid_file Name of fid file to write to.
  • procpar_file Name of procpar file to write to.
  • torder Trace order (None for automatic). See read function.
  • repack True/False to repack file and block headers.
  • overwrite True/False to overwrite existing file.
nmrglue.fileio.varian.read_fid(filename, shape=None, torder='flat', read_blockhead=False)

Read a Varian binary (fid) file.

Parameters:

  • filename Varian binary file (fid) to read.

  • shape Shape of the Varian fid file.

  • torder Trace order. See read function.

  • read_blockhead Set to True to read the Varian blockheaders(s) into

    the returned dictionary. False ignores them.

Returns: dic,data

If shape is not provided file is read as a 2D.

nmrglue.fileio.varian.read_fid_lowmem(filename, shape=None, torder='flat', read_blockhead=False)

Read a Varian binary (fid) file.

Parameters:

  • filename Varian binary file (fid) to read.

  • shape Shape of the Varian fid file.

  • torder Trace order. See read function.

  • read_blockhead Set to True to read the Varian blockheaders(s) into

    the returned dictionary. False ignores them.

Returns: dic,data

If shape is not provided file is read as a 2D.

nmrglue.fileio.varian.read_fid_ntraces(filename, shape=None, torder='flat', read_blockhead=False)

Read a Varian binary (fid) file possibility having multiple traces per block.

Parameters:

  • filename Varian binary file (fid) to read.

  • shape Shape of the Varian fid file.

  • torder Trace order. See read function.

  • read_blockhead Set to True to read the varian blockheaders(s) into

    the returned dictionary. False ignores them.

Returns: dic,data

If shape is not provided file is read as a 2D.

nmrglue.fileio.varian.write_fid(filename, dic, data, torder='flat', repack=False, overwrite=False)

Write a Varian binary (fid) file

Parameters:

  • filename Name of fid file to write to.
  • dic Python dictionary of file parameters.
  • data Array of spectral data to write.
  • torder Trace order (None for automatic). See read function.
  • repack True/False to repack file and block headers.
  • overwrite True/False to overwrite existing file.

No return value.

nmrglue.fileio.varian.write_fid_lowmem(filename, dic, data, torder='f', repack=False, overwrite=False)

Write a Varian binary (fid) file trace by trace (low memory)

Parameters:

  • filename Name of fid file to write to.
  • dic Python dictionary of file parameters.
  • data Array of spectral data to write.
  • torder Trace order (None for automatic). See read function.
  • repack True/False to repack file and block headers.
  • overwrite True/False to overwrite existing file.

No return value.

nmrglue.fileio.varian.read_procpar(filename)
Read a procpar file returning a python dictionary
nmrglue.fileio.varian.write_procpar(filename, dic, overwrite=False)
Write a varian procpar file from python dictionary
nmrglue.fileio.varian.guess_udic(dic, data)
Guess parameter of universal dictionary from dic,data
nmrglue.fileio.varian.create_dic(udic)
Create a Varian 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 varian files will be interested in these functions.

nmrglue.fileio.varian.create_data(data)
Create a Varian data array (recast into complex64 array)
nmrglue.fileio.varian.create_pdic_param(name, values)
Create a fake procpar dictionary element of name name, with values
nmrglue.fileio.varian.find_torder(dic, shape)

Find the torder from the procpar dictionary

Parameters:

  • dic procpar dictionary.
  • shape Shape of

Returns: torder (file trace ordering string shortcut)

nmrglue.fileio.varian.torder2i2t(torder)
Convert torder to index2trace function
nmrglue.fileio.varian.torder2t2i(torder)
Convert torder to trace2index functions
nmrglue.fileio.varian.reorder_data(data, shape, torder)

Reorder data (raw from disk) packed with torder and shape

Parameters:

  • data Data (2D) array, ordered as on disk.
  • shape True shape of data
  • toder Trace order. See read function.

Returns: data (data with shape shape and ordered correctly)

No error checking is done to see if data and shape contain the same number of values.

nmrglue.fileio.varian.order_data(data, torder)

Order data for writing to disk

Parameters:

  • data Data array
  • torder Trace order. See read function.

Returns: data (2D array ordered for writing to disk)

nmrglue.fileio.varian.get_nblocks(f, nblocks, pts, nbheaders, dt, read_blockhead)

Read n blocks from a Varian binary file.

Parameters:

  • f File object of varian binaruy file

  • nblocks Number of blocks to read

  • pts Number of points per trace

  • nbheaders Number of block headers in each block

  • dt Data type of data in binary file (real)

  • read_blockhead True to read the Varian blockheaders(s) into

    the returned dictionary. False ignores them.

Returns: dic,data if read_blockhead is True, data if False

nmrglue.fileio.varian.get_block(f, pts, nbheaders, dt, read_blockhead=False)

Read a block from Varian binary file.

Parameters:

  • f File object of varian binaruy file.

  • pts Number of points per trace.

  • nbheaders Number of block headers in each block

  • dt Data type of data in binary file (real).

  • read_blockhead Set to True to read the varian blockheaders(s) into

    the returned dictionary. False ignores them.

Returns: dic,data if read_blockhead is True, data if False

nmrglue.fileio.varian.get_nblocks_ntraces(f, nblocks, ntraces, pts, nbheaders, dt, read_blockhead)

Read n blocks from a Varian binary file which may have multiple traces per block.

Parameters:

  • f File object of Varian binary file to read from.

  • nblocks Number of blocks to read.

  • ntraces Number of traces per block.

  • pts Number of points per trace.

  • nbheaders Number of block headers in each block.

  • dt Data type of data in binary file (real).

  • read_blockhead Set to True to read the varian blockheaders(s) into

    the returned dictionary. False ignores them.

Returns: dic,data if read_blockhead is True, data if False

nmrglue.fileio.varian.get_block_ntraces(f, ntraces, pts, nbheaders, dt, read_blockhead=False)

Read a block from Varian binary file which may have multiple traces per block.

Parameters:

  • f File object of Varian binary file to read from.

  • ntraces Number of traces per block.

  • pts Number of points per trace.

  • nbheaders Number of block headers in each block.

  • dt Data type of data in binary file (real).

  • read_blockhead Set to True to read the varian blockheaders(s) into

    the returned dictionary. False ignores them.

Returns: dic,data if read_blockhead is True, data if False.

nmrglue.fileio.varian.get_trace(f, pts, dt)

Read trace of pts points of dtype dt from Varian binary file

Does not correct Endiness as dt should handle this

nmrglue.fileio.varian.get_fileheader(f)

Unpack file header parameters into list.

Reads the 32-byte file header from file and unpacks into a list. Endiness is corrected as needed.

Returned list contents:

N Variable Description
0 nblocks data blocks in file
1 ntraces traces per block
2 np elements per trace
3 ebytes bytes per element
4 tbytes bytes per trace
5 bbytes bytes per block
6 vers_id software version, file_id status bits
7 status status of whole file
8 nbheaders number of block headers per block (1)
nmrglue.fileio.varian.get_blockheader(f)

Unpack block header parameters into a list.

Reads the 28-byte block header from f and unpacks into a list. Endiness is corrected as needed.

Returned list contents:

N Variable Description
0 scale scaling factor
1 status status of data in block
2 index block index
3 mode block mode
4 ctcount ct value of FID
5 lpval left phase
6 rpval right phase
7 lvl level drift correction
8 tlt tilt drift correction
nmrglue.fileio.varian.skip_blockheader(f)

Read a block header but do not unpack

This is a replacement for get_blockheader. It skips f ahead 28 bytes.

nmrglue.fileio.varian.get_hyperheader(file)

Unpack hypercomplex header parameters to a list.

Reads the 28-bytes block header from file and unpacks into a list. Endiness is corrected as needed.

Returned list contents:

N Variable Description
0 s_spare1 Not Used
1 status status of block
2 s_spare2 Not Used
3 s_spart3 Not Used
4 l_spare1 Not Used
5 lpval1 2D left phase
6 rpval1 2D right phase
7 f_spare1 Not Used
8 f_spare2 Not Used
nmrglue.fileio.varian.put_block(f, trace, nbheaders, bh, hh=False)

Put blockheader(s) and trace to file

Parameters:

  • f File object to write to.
  • trace Trace to write to block.
  • nbheaders Number of block headers.
  • bh Blockheader list.
  • hh Hyperheader list (if required).

when nbheaders > 2, additional headers are written as all zeros.

nmrglue.fileio.varian.put_trace(f, trace)
Write trace to file f.
nmrglue.fileio.varian.put_fileheader(f, fh)

Write fileheader list to file (32-bytes written)

Parameters:

  • f file object
  • fh fileheader list (length 9)
nmrglue.fileio.varian.put_blockheader(f, bh)

Write blockheader list to file (28-bytes written)

Parameters:

  • f file object
  • bh blockheaders list, length 9
nmrglue.fileio.varian.put_hyperheader(f, hh)

Write hyperheader list to file (28-bytes written)

Parameters:

  • f file object
  • hh hyperheader list, length 9
nmrglue.fileio.varian.hyperheader2dic(head)
Convert a hypercomplex block header into a python dictionary.
nmrglue.fileio.varian.repack_hyperheader(dic)
Repack hyperheader dictionary bit flag parameters into status.
nmrglue.fileio.varian.dic2hyperheader(head)

Convert a python dictionary into a hypercomplex block header list.

Does not repack status from bit flags.

nmrglue.fileio.varian.make_blockheader(filedic=False, index=1)

Make a generic blockheader dictionary with a given block index.

filedic can be provided for status flags, if not provided creates header for float32 data

nmrglue.fileio.varian.blockheader2dic(head)
Convert a block header list into a python dictionary.
nmrglue.fileio.varian.repack_blockheader(dic)
Repack blockheader dic bit flag parameters into status and mode.
nmrglue.fileio.varian.dic2blockheader(dic)

Convert a python dictionary into block header list.

Does not repack status and mode from bit flags.

nmrglue.fileio.varian.fileheader2dic(head)
Convert fileheader list into a python dictionary
nmrglue.fileio.varian.repack_fileheader(dic)
Repack blockheader dic bit flag parameters into status and mode.
nmrglue.fileio.varian.dic2fileheader(dic)

Convert a python dictionary into a fileheader list

Does not repack status from bit flags

nmrglue.fileio.varian.find_shape(pdic)
Determine the shape of a varian file from the procpar dictionary
nmrglue.fileio.varian.find_cdtype(dic)
Find the complex dtype from a dictionary
nmrglue.fileio.varian.find_dtype(dic)
Find the dtype from a dictionary
nmrglue.fileio.varian.uninterleave_data(data)

Unpack interleaved real,imag data

data dtype Return dtype
int16 ‘complex64’
float32 ‘complex64’
int32 ‘complex128’
nmrglue.fileio.varian.interleave_data(data_in)

Interleave real, imag data

Does not check if resulting dtype is a valid varian dtype

nmrglue.fileio.varian.get_parameter(f)

Reads a procpar parameter from a file object

Returns a dictionary with the attributes of the parameter

Low-Level Classes

class nmrglue.fileio.varian.fid_nd(filename, i2t_func, fshape=None, order=None)

Emulate a numpy.ndarray objects without loading data into memory for low memory reading of Varian fid files (one trace per block)

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