Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load Bruker Data #176

Open
NightflyerX opened this issue Dec 1, 2022 · 2 comments
Open

Failed to load Bruker Data #176

NightflyerX opened this issue Dec 1, 2022 · 2 comments

Comments

@NightflyerX
Copy link

NightflyerX commented Dec 1, 2022

Hi, I tried reading a Bruker NMR file, but somehow I only get a weird spectra:
Figure_1

#%matplotlib inline
import matplotlib.pyplot as plt
import nmrglue as ng
import numpy as np
import scipy as sp
import os
import glob

plt.style.use('ggplot')
print("                                            ")
class process_nmr:

    def getpath(self):
        self.filepath = os.path.dirname(os.path.realpath(__file__))

nmr = process_nmr()
nmr.getpath()
d = nmr.filepath

print(d)

path = "./" #Current dir
dirlist = os.listdir(d) #get dirlist
dirlist = list(filter(lambda x : ( x.find(".") == -1 ), dirlist)) #filter files in dirlist

print(dirlist)

root_folder = nmr.filepath 
zero_fill_size = 32768
data = [] # <1>
for folder in dirlist:
    print(folder)
    dic, data = ng.fileio.bruker.read(os.path.join(root_folder,folder))
    # remove the digital filter
    data = ng.bruker.remove_digital_filter(dic, data)

    # process the spectrum
    data = ng.proc_base.zf_size(data, 32768)    # zero fill to 32768 points
    data = ng.proc_base.fft(data)               # Fourier transform
    data = ng.proc_base.ps(data, p0=-50.0)      # phase correction
    data = ng.proc_base.di(data)                # discard the imaginaries
    data = ng.proc_base.rev(data)               # reverse the data


fig = plt.figure(figsize=(12,4))
ax = fig.add_subplot(1,1,1)
#ax.plot(np.arange(0, data.shape[0]), data) # <1>
ax.plot(data) # <1>

plt.show()

RawData from Bruker

@kaustubhmote
Copy link
Collaborator

kaustubhmote commented Dec 3, 2022

Apart from the correct phasing, and optionally using a different way remove the digital filter, I find that I can read and process the spectrum correctly using nearly the same script as you.

dic, data = ng.bruker.read("./")
datap = ng.proc_base.em(data, lb=1/dic["acqus"]["SW_h"])
datap = ng.proc_base.fft(data)
datap = ng.bruker.remove_digital_filter(dic, datap, post_proc=True)
datap = ng.proc_autophase.autops(datap, fn='acme', disp=False)
datap = ng.proc_base.rev(datap)
udic = ng.bruker.guess_udic(dic, datap, strip_fake=True)
uc = {i: ng.fileiobase.uc_from_udic(udic, dim=i) for i in range(udic["ndim"])}

fig, ax = plt.subplots(figsize=(8, 2))
ax.plot(uc[0].ppm_scale(), datap.real, linewidth=0.5)
ax.set_ylim(-1e7, 1e8)
ax.set_xlim(4.1, 1.0)
ax.set_title("zoomed in to better see the small peaks", fontsize=12)
plt.show()

output

@NightflyerX
Copy link
Author

Wow, thank you so much :) It works like a charm. Adding the integrals like in the examples was still a pain though - but works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants