nmrglue.sparky
Functions for reading and writing sparky (.ucsf) files.
Information on the sparky file format can be found online at:
http://www.cgl.ucsf.edu/home/sparky/manual/files.html
and in the source file ucsffile.cc .
This modules is imported as nmrglue.sparky and can be called as such.
High-Level Functions
These are the functions most users will use from the sparky module.
-
nmrglue.fileio.sparky.read(filename)
- Read a sparky file returning a dic,data pair
-
nmrglue.fileio.sparky.read_lowmem(filename)
- Read a sparky file with minimal memory returning a dic,data pair.
-
nmrglue.fileio.sparky.write(filename, dic, data, overwrite=False)
Write a sparky file
Parameters:
- filename Name of file to write to.
- data Data array.
- dic Sparky parameter dictionary.
- overwrite Set to True to overwrite existing file.
No return
-
nmrglue.fileio.sparky.write_lowmem(filename, dic, data, overwrite=False)
Write a sparky file tile by tile (low memory)
Parameters:
- filename Name of file to write to.
- data Data array.
- dic Sparky parameter dictionary.
- overwrite Set to True to overwrite existing file.
No return
-
nmrglue.fileio.sparky.make_uc(dic, data, dim=-1)
Make a unit conversion object
Parameters:
- dic Sparky dictionary
- data data array
- dim dimention to make converter for (0,1,2,3 or -1, last)
-
nmrglue.fileio.sparky.guess_udic(dic, data)
- Guess parameter of universal dictionary from dic,data pair
-
nmrglue.fileio.sparky.create_dic(udic, datetimeobj=datetime.datetime(2011, 4, 6, 16, 39, 24, 715379), user='user')
- Create a sparky dictionary from universal dictionary
-
nmrglue.fileio.sparky.datetime2dic(datetimeobj, dic)
- Add time datetime object to dictionary
-
nmrglue.fileio.sparky.dic2datetime(dic)
- Create a datetime object from sparky 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 sparky
files will be interested in these functions.
-
nmrglue.fileio.sparky.create_data(data)
- Create a sparky data array (recast into float32 array)
-
nmrglue.fileio.sparky.create_axisdic(adic, tlen, dlen)
Make an sparky axis dictionary from a universal axis dictionary
Parameters:
- adic axis dictionary from universal dictionary
- tlen tile length
- dlen data length
-
nmrglue.fileio.sparky.calc_tshape(shape, kbyte_max=128)
Calculate tile shape from data shape
shape is a tuple representing the data shape (data.shape)
kbyte_max determined the largest tile size in Kbytes
Algorithm divides each dimention by 2 until under kbyte_max tile size.
-
nmrglue.fileio.sparky.read_2D(filename)
- Read a 2D sparky file returning a dic,data pair.
-
nmrglue.fileio.sparky.write_2D(filename, dic, data, overwrite=False)
- Write a sparky file from 2D data
-
nmrglue.fileio.sparky.read_3D(filename)
- Read a 3D sparky file returning a dic,data pair
-
nmrglue.fileio.sparky.write_3D(filename, dic, data, overwrite=False)
- Write a sparky file from 3D data
-
nmrglue.fileio.sparky.read_lowmem_2D(filename)
- Read a 2D sparky file with minimal memory usage.
-
nmrglue.fileio.sparky.read_lowmem_3D(filename)
- Read a 3D sparky file with minimal memory usage
-
nmrglue.fileio.sparky.get_tilen(f, n_tile, tw_tuple)
Read in tile n from file object with tile sizes given by tw_tuple
Current file position is loss (store before calling if desired)
-
nmrglue.fileio.sparky.get_tile(f, num_points)
- Read tile data from file object
-
nmrglue.fileio.sparky.put_tile(f, tile)
- Put tile data to file
-
nmrglue.fileio.sparky.get_data(f)
- Read all data from sparky file object
-
nmrglue.fileio.sparky.put_data(f, data)
Put data to file
Does not untile data, assumes this has been done
-
nmrglue.fileio.sparky.find_tilen_2d(data, ntile, (lentY, lentX))
Return a single tile from untiled data
Parameters:
- data untiled data
- ntile Tile number to return
- (lentY,lentX) Tuple representing tile size
Returns 1D numpy array of floats, zero filling as needed.
-
nmrglue.fileio.sparky.tile_data2d(data, (lentY, lentX))
Tile sparky data into 1D numpy array
Parameters:
- data Two-dimensional data array
- lentY Y (w1) dimention tile size
- lentX X (w2) dimention tile size
Returns 1D numpy array of floats
-
nmrglue.fileio.sparky.untile_data2D(data, (lentY, lentX), (lenY, lenX))
Reorganize tiled sparky data into 2D data
Parameters:
- data 1D numpy array of tile data
- lentY size of tile in Y (w1) dim
- lentX size of tile in X (w2) dim
- lenY size of data in Y dim
- lenX size of data in X dim
Returns 2D np.array of floats with size (lenY,lenX)
-
nmrglue.fileio.sparky.find_tilen_3d(data, ntile, (lentZ, lentY, lentX))
Return a single tile from untiled data
Parameters:
- data untiled data
- ntile Tile number to return
- lentZ Tile Z (w1) size
- lentY Tile Y (w2) size
- lentX Tile X (w3) size
Returns 1D numpy array of floats, zero filling as needed.
-
nmrglue.fileio.sparky.tile_data3d(data, (lentZ, lentY, lentX))
Tile sparky data into 1D numpy array
Parameters:
- data Three-dimensional data array
- lentZ Z (w1) dimention tile size
- lentY Y (w2) dimention tile size
- lentX X (w3) dimention tile size
Returns 1D numpy array of floats
-
nmrglue.fileio.sparky.untile_data3D(data, (lentZ, lentY, lentX), (lenZ, lenY, lenX))
Reorganize tiled sparky data into 3D data
Parameters:
- data 1D numpy array of tile data
- lentZ size of tile in Z (w1) dim
- lentY size of tile in Y (w2) dim
- lentX size of tile in X (w3) dim
- lenZ size of data in Z dim
- lenY size of data in Y dim
- lenX size of data in X dim
Returns 3D np.array of floats with size (lenZ,lenY,lenX)
Get fileheader from file and return a list
Reads the 180 byte file header of a sparky file
- Write fileheader list to file (180-bytes)
- Convert fileheader list into dictionary
- Convert fileheader dictionary to list
Get axisheader from file and return a list
Only the first 44 bytes are examined, the NMR_PROCESSED and other header
parameters are ignored since the current version of sparky does not use
them.
- Write axisheader list to file (128-bytes)
- Convert axisheader list into dictionary
- Convert axisheader dictionary to list
Low-Level Classes
-
class nmrglue.fileio.sparky.sparky_2d(filename, order=None)
Emulates a numpy.ndarray object without loading data into memory for low
memory reading of 2D Sparky 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.
-
class nmrglue.fileio.sparky.sparky_3d(filename, order=None)
Emulates a numpy.ndarray object without loading data into memory for low
memory reading of 3D Sparky 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.