Question about processing of the spectra

15 views
Skip to first unread message

poki456

unread,
Nov 20, 2024, 3:48:21 AM11/20/24
to nmrglue-discuss
Hello everyone !

I am a new user of the nmrglue and I would like to ask a beginner question regarding the processing of the spectra. For start, I have Bruker 2D spectra, which when loaded with ng.bruker.read(), have shape of (4, 8192). These spectra are not classical 2D spectra, instead, each row corresponds to one 1D 1H spectrum that was recorded under different conditions. I have written following function for processing of these spectra:                             
def process_one_spectrum(param, spectrum):
    # remove some weird artifact from the Bruker Data
    spectrum = ng.bruker.remove_digital_filter(param, spectrum)

    # set a line broadening coefficient value for the exponential apodization
    lb_h = 2 / param['acqus']['SW_h']
    #  Zero fill by doubling original data size once or multiple times.
    spectrum = ng.process.proc_base.zf_double(spectrum, n=1)
    lb_value = lb_h / param['acqus']['SW_h']

    # Exponential apodization
    spectrum = ng.process.proc_base.em(spectrum, lb=lb_value)
    # Fourier transform
    spectrum = ng.process.proc_base.fft(spectrum)
    # Automatic linear phase correction
    spectrum = ng.proc_autophase.autops(spectrum, fn='acme')
      
    # Delete imaginary data
    spectrum = ng.process.proc_base.di(spectrum)
    # Reverse data
    spectrum = ng.proc_base.rev(spectrum)

    return spectrum

This function works fine and I get the processed spectra back, however I have one question. Given the shape of data that I am working with, my question is this:
Should I pass all 4 spectra to this function at once (the whole array of shape (4, 8192)), so the code would look simply like this:

param, spec = ng.bruker.read(<bruker_dir>)
processed_spectra = process_one_spectrum(param, spec)

Or should I instead pass each individual spectrum iteratively in a for loop to this function so the code would look like this:

param, spec = ng.bruker.read(<bruker_dir>)
processed_spectra = []

for s in spec:
       processed_spectrumprocess_one_spectrum(param, spec)
       processed_spectra.append(processed_spectrum)

processed_spectra = np.array(processed_spectra)

I have tested both cases and both of them works, however I noticed that resulting arrays between these two methods differ numerically, but upon plotting, they look the same.  

So in summary, what approach is better ? 

Thank You and have a nice day,

Jakub 
Reply all
Reply to author
Forward
0 new messages