Functions for reading and writing Varian binary (fid) files and Varian parameter (procpar) files.
Both file formats are documented in:
These are available (as of 04/2011) online from Agilent.
This modules is imported as nmrglue.varian and can be called as such.
These are the functions most users will use from the varian module.
Read Varian files in a directory.
Parameters:
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.
Read Varian files in a directory using minimal memory.
Parameters:
Returns: dic,data
Write Varian files to a directory.
Parameters:
No return value.
Write Varian files to a directory using minimal memory
Parameters:
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.
the returned dictionary. False ignores them.
Returns: dic,data
If shape is not provided file is read as a 2D.
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.
the returned dictionary. False ignores them.
Returns: dic,data
If shape is not provided file is read as a 2D.
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.
the returned dictionary. False ignores them.
Returns: dic,data
If shape is not provided file is read as a 2D.
Write a Varian binary (fid) file
Parameters:
No return value.
Write a Varian binary (fid) file trace by trace (low memory)
Parameters:
No return value.
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.
Find the torder from the procpar dictionary
Parameters:
Returns: torder (file trace ordering string shortcut)
Reorder data (raw from disk) packed with torder and shape
Parameters:
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.
Order data for writing to disk
Parameters:
Returns: data (2D array ordered for writing to disk)
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)
the returned dictionary. False ignores them.
Returns: dic,data if read_blockhead is True, data if 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).
the returned dictionary. False ignores them.
Returns: dic,data if read_blockhead is True, data if False
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).
the returned dictionary. False ignores them.
Returns: dic,data if read_blockhead is True, data if 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).
the returned dictionary. False ignores them.
Returns: dic,data if read_blockhead is True, data if False.
Read trace of pts points of dtype dt from Varian binary file
Does not correct Endiness as dt should handle this
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) |
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 |
Read a block header but do not unpack
This is a replacement for get_blockheader. It skips f ahead 28 bytes.
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 |
Put blockheader(s) and trace to file
Parameters:
when nbheaders > 2, additional headers are written as all zeros.
Write fileheader list to file (32-bytes written)
Parameters:
Write blockheader list to file (28-bytes written)
Parameters:
Write hyperheader list to file (28-bytes written)
Parameters:
Convert a python dictionary into a hypercomplex block header list.
Does not repack status from bit flags.
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
Convert a python dictionary into block header list.
Does not repack status and mode from bit flags.
Convert a python dictionary into a fileheader list
Does not repack status from bit flags
Unpack interleaved real,imag data
| data dtype | Return dtype |
|---|---|
| int16 | ‘complex64’ |
| float32 | ‘complex64’ |
| int32 | ‘complex128’ |
Interleave real, imag data
Does not check if resulting dtype is a valid varian dtype
Reads a procpar parameter from a file object
Returns a dictionary with the attributes of the parameter
Emulate a numpy.ndarray objects without loading data into memory for low memory reading of Varian fid files (one trace per block)