jjhelmus / nmrglue

A module for working with NMR data in Python
BSD 3-Clause "New" or "Revised" License
211 stars 86 forks source link

Bruker ppm calculation (unit conversion) #39

Closed mfitzp closed 8 years ago

mfitzp commented 8 years ago

It doesn't look like the unit conversion is supported on Bruker format fids, is this correct? When I attempt to use it I get an error that ndims is not in the Bruker dic.

For reference I am able to generate the Bruker ppm scale using the following calculation:

offset = (float(dic['acqus']['SW']) / 2) - (float(dic['acqus']['O1']) / float(dic['acqus']['BF1']))
start = float(dic['acqus']['SW']) - offset
end = -offset
step = float(dic['acqus']['SW']) / zero_fill_size

ppms = np.arange(start, end, -step)[:zero_fill_size]

Where zero_fill_size is the size of the spectra.

jjhelmus commented 8 years ago

Unit conversion objects can be created for Bruker files by creating a universal dictionary and using that to create the appropriate unit conversion object. For example:

import nmrglue as ng
dic, data = ng.bruker.read('./bruker_1d/')
udic = ng.bruker.guess_udic(dic, data)
uc = ng.fileiobase.uc_from_udic(udic)
ppm_scale = uc.ppm_scale()

What function are you using that gives an error about ndims not being in the Bruker dic? Some of these features are relatively new, you may need to update your install of nmrglue.

The parameters you are using to generate a PPM scale are similar to those used by nmrglue in lines 109-119 of the Bruker module to populate the universal dictionary.

mfitzp commented 8 years ago

Quite right I was on an outdated version — I thought this had made it into nmrglue but couldn't figure it out. Thanks!