Show projections in 2D spectra

76 views
Skip to first unread message

Carlos

unread,
Jan 20, 2022, 7:30:17 AM1/20/22
to nmrglue-discuss
Hi

I was wondering if is it possible to show the projections of a 2D spectra. The code below shows only the correlation peaks but I would like to have also the projection of the F1 and F2 dimensions

dic, data = ng.pipe.read('mg1_2d.fid')

uc_31P = ng.pipe.make_uc(dic, data, dim=1)
ppm_31P = uc_31P.ppm_scale()
ppm_31P_0, ppm_31P_1 = uc_31P.ppm_limits()
uc_1H = ng.pipe.make_uc(dic, data, dim=0)
ppm_1H = uc_1H.ppm_scale()
ppm_1H_0, ppm_1H_1 = uc_1H.ppm_limits()

fig = plt.figure()
ax = fig.add_subplot(111)

cmap = matplotlib.cm.Blues_r  
contour_start = 160000        
contour_num = 30            
contour_factor = 1.6      
 
cl = contour_start * contour_factor ** np.arange(contour_num)

ax.contour(data, cl, cmap=cmap, extent=(ppm_31P_0, ppm_31P_1, ppm_1H_0, ppm_1H_1))
ax.set_xlim(100, 20)
ax.set_ylim(18, -2)

Thanks
Carlos

Kaustubh Mote

unread,
Jan 22, 2022, 5:53:39 AM1/22/22
to nmrglue-discuss
Hi,
You will need to calculate the F1 and F2 projections using something like:

f2proj = data.sum(axis=0, where=data > noise)
f1proj = data.sum(axis=1, where=data > noise)

These two 1D datasets can then be plotted as usual on the 2-D.
You should select the parameter 'noise' such that only the points above a noise threshold contribute to the sum.

If you want slices, then the example given at https://nmrglue.readthedocs.io/en/latest/jbnmr_examples/s4_2d_plotting.html will be useful

Hope this helps.
Kaustubh.

Carlos

unread,
Jan 24, 2022, 10:24:21 AM1/24/22
to nmrglue-discuss
Hi Kaustubh

Thank you for the answer.

I have two quick questions:

1 -  When I tried to plot the data using 
f2proj = data.sum(axis=0)
f1proj = data.sum(axis=1)
plt.plot(ppm_31P, f2proj)
plt.plot(ppm_1H, f1proj)
I get an error just for the f1 dimension saying that "x and y must have same first dimension, but have shapes (128,) and (256,)" do you know what might be causing this? 

2 -  Which function do you use to get the noise values? I've been searching nmrglue's documentation and did not find it.

Thanks
Carlos

Kaustubh Mote

unread,
Jan 27, 2022, 12:33:01 PM1/27/22
to nmrglue-discuss
Hi Carlos,

Perhaps the ppm_31P and ppm_1H are interchanged?

Also,
The projection of each dimension in Topspin is just the array of the maximum intensity in each of the slices.
So, you can get the same results as Topspin by doing this:

f1proj = np.amax(data, axis=1)
f2proj = np.amax(data, axis=0)

The ones I suggested earlier corresponds to the Topspin commands 'f1sum' and 'f2sum' (and in some versions, selecting the 'sum' option in the dialog)

As for the noise, you can use numpy's inbuilt functions for calculating it.
Pick an area of your data that is just noise:

noisedata = data[0:200, 0:200]
noise =  np.std(noisedata)

Make sure to subtract the np.average(noisedata) from data to make the mean noise level 0.
Reply all
Reply to author
Forward
0 new messages