Plot varian data, scale in ppm

188 views
Skip to first unread message

Bruno

unread,
Aug 28, 2013, 8:57:20 AM8/28/13
to nmrglue...@googlegroups.com
Hello,
I'm trying to process diffusion experiment recorded with vnmrj.
I recorded 15 values for the gradients.
I opened the data with this command:
dic, data = ng.varian.read(data_path + folder)
data.shape give me:
(1, 15, 8192)

Then to plot the spectra I would like to have the scale in ppm:
I convert the data into nmrpipe data (varian.make_uc did not exist) :
C = ng.convert.converter()
C.from_varian(dic,data)
pdic,pdata = C.to_pipe()
uc0 = ng.pipe.make_uc(pdic,pdata,dim=0)
uc1 = ng.pipe.make_uc(pdic,pdata,dim=1)
uc2 = ng.pipe.make_uc(pdic,pdata,dim=2)

uc0.ppm_scale()
>> array([], dtype=float64)
uc1.ppm_scale()
>>array([ 1.4 , 1.25555556, 1.11111111, 0.96666667, 0.82222222, 0.67777778, 0.53333333])
uc2.ppm_scale()
>>array([ 1.5 , 1.49987793, 1.49975586, ..., 0.50036621, 0.50024414, 0.50012207])
uc2.ppm_scale().size
>>8192

I don't understand what are these numbers, my window is sw = 5000Hz, from 9.71ppm to -0.29ppm (read in vnmrj)
I also did a zerofiling, so the number of point is 2*8192
So I can't really follow your tutorial
http://jjhelmus.github.io/nmrglue/current/examples/plot_1d_freq.html

Can you help me?

Thank you a lot.
Regards
Bruno


Jonathan Helmus

unread,
Aug 30, 2013, 10:38:41 AM8/30/13
to nmrglue...@googlegroups.com
Bruno,

The Varian/Agilent data that nmrglue reads is the raw unprocessed
time domain data, so any processing performed in VnmrJ is not going to
show up in the data you read in. Rather you will need to perform the
processing in nmrglue or another program that nmrglue can read processed
data from, such as NMRPipe. In addition, although nmrglue reads in the
data as a 3D this is just an artefact of how Varian records metadata.
From your description of the data it sounds like your data is a
pseudo-2D dataset, which is similar to the data in the
seperate_1d_varian example
(http://jjhelmus.github.io/nmrglue/current/examples/separate_1d_varian.html).
Finally you will need to provide a universal dictionary with the correct
spectral parameter when performing the the conversion from Varian to
NMRPipe data, without one default values are used which give you the
strange ppm scale.

The following script takes each 1D trace from the separate_1d_varian
example data
(http://nmrglue.googlecode.com/files/example_separate_1d_varian.zip),
converts to NMRPipe format, does some basic processing, creates a plot
of the data with a ppm scale, and saves the plot to file with names
plot_0.png, plot_1.png, .... You should be able to adapt this script to
work with your data.

#! /usr/bin/env python

import numpy as np
import nmrglue as ng
import matplotlib.pyplot as plt

##############################################################################
# read in the arrayed data
# http://jjhelmus.github.io/nmrglue/current/examples/separate_1d_varian.html
##############################################################################
dir_name = 'arrayed_data.dir' # directory where the Varian data is held.
dic, all_data = ng.varian.read(dir_name, as_2d=True)

# each separated 1D dataset could be written out to its own directory as
# in the example above and then processed in a variety of ways, here all
# the processing and plotting is done by looping over the traces with
# no intermediate writing of the separated data.

# loop over each elements in the arrayed data
for slice_num in range(all_data.shape[0]):

print "Processing and plotting slice_num:", slice_num
###########################################################################
# convert into NMRPipe format
#
http://jjhelmus.github.io/nmrglue/current/examples/agilent2pipe_1d.html
###########################################################################
data = all_data[slice_num]

# Set the spectral parameters, adjust these to reflect the actual
# parameters used.
udic = ng.varian.guess_udic(dic, data)
udic[0]['size'] = 1500 # number of R|I points in the
spectrum
udic[0]['complex'] = True # True if complex data
udic[0]['encoding'] = 'direct' # keep as 'direct'
udic[0]['sw'] = 50000.0 # spectral width in Hz
udic[0]['obs'] = 125.681 # Observation freq. in MHz.
udic[0]['car'] = 99.0 * 125.681 # carrier freq in Hz
udic[0]['label'] = 'C13' # the observed nucleus.

# create the converter object and load in Agilent data
C = ng.convert.converter()
C.from_varian(dic, data, udic)

pdic, pdata = C.to_pipe()

###########################################################################
# process the data
#
http://jjhelmus.github.io/nmrglue/current/examples/process_pipe_1d.html
###########################################################################

# process the direct dimension
# these will need to be changed according to the processing needs of
# your data.
pdic, pdata = ng.pipe_proc.sp(pdic, pdata, off=0.35, end=0.98,
pow=2, c=1.0)
pdic, pdata = ng.pipe_proc.zf(pdic, pdata, auto=True)
pdic, pdata = ng.pipe_proc.ft(pdic, pdata, auto=True)
pdic, pdata = ng.pipe_proc.ps(pdic, pdata, p0=60.0, p1=0.0)
pdic, pdata = ng.pipe_proc.di(pdic, pdata)

###########################################################################
# plot
# http://jjhelmus.github.io/nmrglue/current/examples/plot_1d_freq.html
###########################################################################

# create a unit conversion object for the axis
uc = ng.pipe.make_uc(pdic, pdata)

# plot the spectrum
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(uc.ppm_scale(), pdata, 'k-')
ax.set_xlim(200, 0) # change this to good limits for your data

# save the figure
fig.savefig('plot_%i.png' % (slice_num))
plt.close(fig)

Hope this helps, let me know if you have any addition troubles.

- Jonathan Helmus
Reply all
Reply to author
Forward
0 new messages