NMR Input Utility¶
Functions tasked with handling input properly
Adopted from nmrglue’s source code for use in nmrPype
Data Conversion¶
- nmrPype.utils.fdata.dic2fdata(dic: dict) ndarray ¶
Converts a NMRPipe dictionary into an array. See
fdata2dic()
for the inverse function.- Parameters:
dic (dict) – python dictionary representation of NMRPipe header
- Returns:
fdata – 512x4-byte array header
- Return type:
ndarray
- nmrPype.utils.fdata.fdata2dic(fdata: ndarray) dict ¶
Convert a fdata array to fdata dictionary.
Converts the raw 512x4-byte NMRPipe header into a python dictionary with keys as given in fdatap.h
See
dic2fdata()
for the inverse function.- Parameters:
fdata (ndarray) – 512x4-byte array header
- Returns:
dic – python dictionary representation of NMRPipe header
- Return type:
dict
- nmrPype.utils.fdata.get_fdata(filename: str | PathLike | bytes | BytesIO) ndarray ¶
Get an array of length 512-bytes holding NMRPipe header.
- Parameters:
filename (InputFile [bytes/string/path-like]) – Input stream to read fdata from
- Returns:
fdata – 512x4-byte numpy array for header
- Return type:
ndarray
- nmrPype.utils.fdata.get_fdata_data(filename: str | PathLike | bytes | BytesIO) tuple[ndarray, ndarray] ¶
Get fdata and data array one after another
- Parameters:
filename (InputFile [bytes/string/path-like]) – Input stream to read fdata from
- Returns:
fdata (ndarray) – 512x4-byte header array
data (ndarray) – 1D array representation of NMR data
Data Handling¶
- nmrPype.utils.fdata.append_data(data: ndarray) ndarray ¶
Return data with last axis (-1) appended.
Data should be complex
See
unappend_data()
for the inverse operation.- Parameters:
data (np.ndarray) – NMR data with complex direct dimension represented as complex numpy values
- Returns:
NMR data with complex direct dimension concatenating real and imaginary points
- Return type:
ndarray
- nmrPype.utils.fdata.find_shape(dic: dict) tuple ¶
Find the shape (tuple) of data in a NMRPipe file from parameters.
The last dimension of the tuple is length of the data in the file, the actual length of the data matrix may be half of this if the data is complex.
- Parameters:
dic (dict) – NMR data header as python dictionary for obtaining correct shape
- Returns:
1-tuple is returned for 1D data, 2-tuple for 2D and non-stream 3D/4D data, 3-tuple or 4-tuple for stream 3D/4D data.
- Return type:
tuple
- nmrPype.utils.fdata.reshape_data(data: ndarray, shape: tuple) ndarray ¶
Reshape data or return 1D data after warning.
- Parameters:
data (ndarray) – 1D numpy array data
shape (tuple) – Target reshape
- Returns:
Data shaped to match input shape
- Return type:
ndarray
- nmrPype.utils.fdata.unappend_data(data: ndarray) ndarray ¶
Return complex data with last axis (-1) unappended.
Data should have imaginary data vector appended to real data vector
See
append_data()
for the inverse operation.- Parameters:
data (np.ndarray) – NMR data with complex direct dimension concatenating real and imaginary points
- Returns:
NMR data with direct dimension represented as complex numpy values
- Return type:
ndarray
- nmrPype.utils.fdata.unshape_data(data: ndarray) ndarray ¶
Return 1D version of data.
Put To Disk¶
- nmrPype.utils.fdata.put_data(filename, fdata, data, overwrite=False)¶
Put fdata and data to 2D NMRPipe.
- nmrPype.utils.fdata.put_fdata(fh, fdata: ndarray)¶
Put NMR data, fdata, to a NMRPipe file described by file object fh.
- nmrPype.utils.fdata.put_trace(fh, trace: ndarray)¶
Put a trace (real or complex) to NMRPipe file described by file object fh.
Data Manipulation Classes¶
- class nmrPype.utils.fdata.pipe_2d(filename, order=(0, 1))¶
Emulate a ndarray objects without loading data into memory for low memory reading of 2D NMRPipe 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.
- Parameters:
filename (str) – Filename of 2D NMRPipe file.
order (tuple) – Ordering of axes against file.
- class nmrPype.utils.fdata.pipe_3d(filemask, order=(0, 1, 2), fcheck=False)¶
Emulate a ndarray objects without loading data into memory for low memory reading of 3D NMRPipe files (multiple file data sets).
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.
- Parameters:
filemask (str) – Filename of 3D NMRPipe file. Should contain one formatter ‘%’ operator.
order (tuple) – Ordering of axes against file.
fcheck (bool, optional.) – True to perform a basic check to see if all files expected for the data set exist. Raises a IOError if files are missing. Default is False.
- class nmrPype.utils.fdata.pipe_4d(filemask, order=(0, 1, 2, 3), fcheck=False)¶
Emulate a ndarray objects without loading data into memory for low memory reading of single/two index 4D NMRPipe data 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.
- Parameters:
filemask (str) – Filename of 4D NMRPipe file with one or two formatter (%) operators.
order (tuple) – Ordering of axes against file.
fcheck (bool, optional.) – True to perform a basic check to see if all files expected for the data set exist. Raises a IOError if files are missing. Default is False.
- class nmrPype.utils.fdata.pipestream_3d(filename, order=(0, 1, 2))¶
Emulate a ndarray objects without loading data into memory for low memory reading of 3D NMRPipe data stream files (one file data sets).
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.
- Parameters:
filename (str) – Filename of 3D NMRPipe stream file.
order (tuple) – Ordering of axes against file.
- class nmrPype.utils.fdata.pipestream_4d(filename, order=(0, 1, 2, 3))¶
Emulate a ndarray objects without loading data into memory for low memory reading of 4D NMRPipe data streams (one file 4D data sets).
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.
- Parameters:
filename (str) – Filename of 4D NMRPipe stream file.
order (tuple) – Ordering of axes against file.