Utility

Classes, functions, and exceptions that serve as the backbone of handling NMR data

DataFrame

class nmrPype.utils.DataFrame.DataFrame(file: str = '', header: dict = {}, array: ndarray | None = None, verb: int = 0, inc: int = 16)

Object containing the nmr data vectors as well as the header. Contains methods for accessing and modifying the data based on the header included with the data.

Parameters:
  • file (str) – Input file or stream for initializing frame

  • header (dict) – Header to initialize, by default obtained from file or set

  • array (Array [numpy.ndarray or None]) – Array to initialize, by default obtained from file or set

getArray() ndarray | None

Dataframe array variable getter

Returns:

self.array – Object’s current ndarray

Return type:

Array

getCurrDim() int

Obtain current dim for Dataframe based on dim order

Returns:

Current direct dimension

Return type:

int

getDimOrder(dim: int) int

Convert order number into correct dimension index

Parameters:

dim (int) –

Dimension Index

  • 1 = Direct

  • 2 = First Indirect

  • 3 = Second Indirect

  • 4 = Third Indirect

  • and so on..

Returns:

Integer corresponding to the inputted dimension specifically for this dataset

Return type:

int

getHeader() dict

Dataframe header variable getter

Returns:

self.header – Object’s current header

Return type:

dict

getInc() int

Obtain verbose increment vlue

Returns:

Integer corresponding to verbose output loop increment

Return type:

int

getParam(param: str, dim: int = 0) float

Obtain header parameter from dictionary given key and dimension

Parameters:
  • param (str) – Header parameter to obtain value from

  • dim (int) – Dimension of parameter

Returns:

Float value of header parameter

Return type:

float

getVerb() int

Obtain verbosity value

Returns:

Integer corresponding to verbosity value

Return type:

int

runFunc(targetFunction: str, arguments: dict = {}) int

runFunc completes the following:

  1. Checks for valid function call

  2. Passes function arguments to function call

  3. Uses function call to process array based on function implementation

  4. Update the data’s header accordingly

Can be called outside of command-line mode if arguments are passed with proper keys

Parameters:
  • targetFunction (str) – Function Code (e.g. FT, SP, ZF)

  • arguments (dict) – Dictionary of arguments to pass to function initialization (May become a kwargs in the future for user simplicity)

Returns:

Integer exit code obtained by the function itself (e.g. 0 success 1 fail)

Return type:

int

setArray(array: ndarray | None) int

Dataframe array variable setter

Parameters:

array (Array) – New array to assign to data frame

Returns:

Integer exit code (e.g. 0 success 1 fail)

Return type:

int

setHeader(dic: dict) int

Dataframe header variable setter

Parameters:

dic (dict) – New header to assign to data frame

Returns:

Integer exit code (e.g. 0 success 1 fail)

Return type:

int

setInc(level: int)

Set verbosity increment

Parameters:

level (int) – Integer for verbose output loop increment

setParam(param: str, value: float, dim: int = 0) int

Set given header parameter’s value to inputted value

Parameters:
  • param (str) – Header parameter to set value to

  • value (float) – Value to replace header value with

  • dim (int) – Dimension of parameter

Returns:

Integer exit code (e.g. 0 success 1 fail)

Return type:

int

setVerb(level: int)

Set verbosity value

Parameters:

level (int) – Integer for new verbosity value

updateParamSyntax(param, dim: int) str

Converts header keywords from ND to proper parameter syntax if necessary

Parameters:

dim (int) – Target parameter dimension

Returns:

param – Parameter string with updated syntax

Return type:

str

updatePipeCount(reset: bool = False) int

Increment the FDPIPECOUNT parameter or reset to zero Modify FDPIPEFLAG, FDCUBEFLAG, and FDFILECOUNT if needed

Parameters:

reset (bool) – Whether or not to reset pipe count or increment pipe count

Returns:

Integer exit code (e.g. 0 success 1 fail)

Return type:

int

Error Handling

Exception classes and Exception handler for NMR data

Exceptions

exception nmrPype.utils.FileIOError

Exception called when there is an error in reading/writing the data

exception nmrPype.utils.FunctionError

Exception called when attempting to run a function fails

exception nmrPype.utils.PipeBurst

Exception called when the main script reaches an exception, a.k.a. something broke. Just done for the nice name opportunity honestly

exception nmrPype.utils.UnknownHeaderParam

Exception called when there is an attempt to call a nonexistent header param

Error Handling Function

This function is an error-handling helper function for nmrPype. It can output to the stderr and continue, or terminate running.

param e:

Exception that called this error handler

type e:

Exception

param new_e:

New exception to pass onto the chain

type new_e:

Exception

param msg:

Error message to output to the screen

type msg:

str

param ePrint:

Whether to print to standard error stream or raise and error

type ePrint:

bool