nmrglue.convert

Functions to convert between NMR file formats

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

User Information

User Classes

This class is targetted for users of nmrglue.

class nmrglue.fileio.convert.converter[source]

Object which allows conversion between NMR file formats, including low memory data objects.

Conversion between NMR file formats with this class involves three steps. First a new converter object must be created. Then the converter must be loaded with data using a from_ method. Finally, the dictionary and data representation of a NMR data in the desired format is extracted using a to_ method. This can then be written to disk.

Example conversion:

vdic, vdata = ng.varian.read("varian_dir")
C = ng.convert.converter()
C.from_varian(vdic, vdata)
pdic, pdata = C.to_pipe()
ng.pipe.write("test.fid", pdic, pdata)

Spectral parameters can be provided directly by passing a Universal dictionary to any of the from_ methods. If not provided the spectral parameters are guessed from the file format’s dictionary of parameters.

from_bruker(dic, data, udic=None, remove_digital_filter=False)[source]

Load converter with Bruker data.

Parameters
dicdict

Dictionary of Bruker parameters.

dataarray_like

NMR data.

udicdict, optional

Universal dictionary, if not provided will be guesses from dic.

remove_digital_filterbool, optional

True to remove the Bruker digital filter. Do not use this option with low memory data or when the udic parameter is specified. False leave the digital filter in place.

from_pipe(dic, data, udic=None)[source]

Load converter with NMRPipe data.

Parameters
dicdict

Dictionary of NMRPipe parameters.

dataarray_like

NMR data.

udicdict, optional

Universal dictionary, if not provided will be guesses from dic.

from_rnmrtk(dic, data, udic=None, agilent_compatible=False)[source]

Load converter with RNMRTK data.

Parameters
dicdict

Dictionary of RNMRTK parameters.

dataarray_like

NMR data.

udicdict, optional

Universal dictionary, if not provided will be guesses from dic.

agilent_compatiblebool, optional

True when RNMRTK data is being compared to Agilent/Varian data.

from_sparky(dic, data, udic=None)[source]

Load converter with Sparky data.

Parameters
dicdict

Dictionary of Sparky parameters.

dataarray_like

NMR data.

udicdict, optional

Universal dictionary, if not provided will be guesses from dic.

from_universal(dic, data)[source]

Load converter with Universal data.

Parameters
dicdict

Dictionary of universal parameters.

dataarray_like

NMR data.

from_varian(dic, data, udic=None)[source]

Load converter with Agilent/Varian data.

Parameters
dicdict

Dictionary of Agilent/Varian parameters.

dataarray_like

NMR data.

udicdict, optional

Universal dictionary, if not provided will be guesses from dic.

to_bruker()[source]

Return Bruker format data.

Returns
dicdict

Dictionary of Bruker parameters.

dataarray_like

NMR data in Bruker format.

to_pipe(datetimeobj=datetime.datetime(2020, 10, 29, 17, 6, 52, 238754))[source]

Return NMRPipe format data.

Parameters
datetimedatetime object, optional

Datetime object to include in the NMRPipe parameters. The current date and time is used by default.

Returns
dicdict

Dictionary of NMRPipe parameters.

dataarray_like

NMR data in NMRPipe format.

to_rnmrtk(agilent_compatible=False, dim_order=None)[source]

Return RNMRTK format data.

Parameters
agilent_compatiblebool, optional

True when RNMRTK data is being compared to Agilent/Varian data.

dim_orderlist, optional

List mapping axis numbers in the universal dictionary to the to the order in which they will appear in the RNMRTK dictionary. If None, the default, [0, 1, 2, …] will be used.

Returns
dicdict

Dictionary of RNMRTK parameters.

dataarray_like

NMR data in RNMRTK format.

to_sparky(datetimeobj=datetime.datetime(2020, 10, 29, 17, 6, 52, 238763), user='user')[source]

Return Sparky format data.

Parameters
datetimedatetime object, optional

Datetime object to include in the Sparky parameters. The current date and time is used by default.

userstr, optional

Username to include in the Sparky parameters. ‘user’ is the default.

Returns
dicdict

Dictionary of Sparky parameters.

dataarray_like

NMR data in Sparky format.

to_universal()[source]

Return Universal format data.

Returns
dicdict

Dictionary of Universal parameters.

dataarray_like

NMR data in format as provided.

to_varian()[source]

Return Agilent/Varian format data.

Returns
dicdict

Dictionary of Agilent/Varian parameters.

dataarray_like

NMR data in Agilent/Varian format.

Developer Information

Developer Classes

These classes are typically not used directly by users. Developers who want fine control over file conversion will be interested in these classes

class nmrglue.fileio.convert.udata_nd(edata, iproc, oproc, odtype, order=None)[source]

Wrap other fileiobase.data_nd derived objects with input/output conversion when slices are requested.

  • 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
edatafileiobase.data_nd derived object

Data object to wrap.

iprocdict

Dictionary of processing required by input format.

oproc :

Dictionary of processing required by output format.

odtypedtype

Output dtype.

ordertuple

Axis ordering relative to input data.

Notes

The iproc and oproc dictionary can contains the following keys and values.

key

value

Description

alt_id_sign

True/False

True alternates signs along indirect dims.

realfactor

float

Real channel scaling factor.

imagfactor

float

Imaginary channel scaling factor.