Esempio n. 1
0
 def test_apod_gmb(self):
     spec = fromBruker(self.filename, False, False)
     spec = apod(spec, w=lambda s: GMB(s, 2, 0.5))
     C = converter()
     u = guess_udic(self.dic,self.data)
     C.from_bruker(self.dic, self.data, u)
     
     pipe_dic, pipe_data = C.to_pipe()
     test_data = pipep.gmb(pipe_dic, pipe_data, lb=2, gb=0.5)[1]
     ts.assert_allclose(spec, test_data, 1e-7,1e-3, 'GBM apodization not equal to NMRPipe processed one.')
Esempio n. 2
0
 def test_apod_gm(self):
     spec = fromBruker(self.filename, False, False)
     spec = apod(spec, w=lambda s: GM(s, 1, 10, 5))
     C = converter()
     u = guess_udic(self.dic,self.data)
     C.from_bruker(self.dic, self.data, u)
     
     pipe_dic, pipe_data = C.to_pipe()
     test_data = pipep.gm(pipe_dic, pipe_data, g1=1, g2=10, g3=5)[1]        
     ts.assert_allclose(spec, test_data, 1e-7,1e-3, 'GM apodization not equal to NMRPipe processed one.')
Esempio n. 3
0
 def test_apod_sp(self):
     spec = fromBruker(self.filename, False, False)
     spec = apod(spec, w=lambda s: SP(s, off=0.5, power=2))
     C = converter()
     u = guess_udic(self.dic,self.data)
     C.from_bruker(self.dic, self.data, u)
     
     pipe_dic, pipe_data = C.to_pipe()
     test_data = pipep.sp(pipe_dic, pipe_data, off=0.5, pow=2)[1]        
     ts.assert_allclose(spec, test_data, 1e-7,1e-3, 'SP apodization not equal to NMRPipe processed one.')
Esempio n. 4
0
 def test_apod_jmod(self):
     spec = fromBruker(self.filename, False, False)
     spec = apod(spec, w=lambda s: JMOD(s, 0.5, 5, 1))
     C = converter()
     u = guess_udic(self.dic,self.data)
     C.from_bruker(self.dic, self.data, u)
     
     pipe_dic, pipe_data = C.to_pipe()
     test_data = pipep.jmod(pipe_dic, pipe_data, off=0.5, j=5, lb=1)[1]        
     ts.assert_allclose(spec, test_data, 1e-7,1e-3, 'JMOD apodization not equal to NMRPipe processed one.')
Esempio n. 5
0
 def test_apod_tri(self):
     spec = fromBruker(self.filename, False, False)        
     # Loc < 1 results in dimension reduction of the apodization vector
     with self.assertRaises(NMRShapeError):
         apod(spec, w=lambda s: TRI(s, 0.5, 0.7, 0.5))
     
     spec = fromBruker(self.filename, False, False)
     spec = apod(spec, w=lambda s: TRI(s, 5000, 0.7, 0.5))
     C = converter()
     u = guess_udic(self.dic,self.data)
     C.from_bruker(self.dic, self.data, u)
     
     pipe_dic, pipe_data = C.to_pipe()
     test_data = pipep.tri(pipe_dic, pipe_data, loc=5000, lHi=0.7, rHi=0.5)[1]
     ts.assert_allclose(spec, test_data, 1e-7,1e-3, 'TRI apodization not equal to NMRPipe processed one.')
Esempio n. 6
0
def read_varian_spec_raw(spectrum_directory,
                         fid_filename,
                         procpar_filename,
                         zero_filling=True,
                         apodization=True):
    from nmrglue.fileio import varian, convert
    from nmrglue.process import pipe_proc

    #Read varian files:
    res = varian.read(dir=spectrum_directory,
                      fid_file=fid_filename,
                      procpar_file=procpar_filename)
    varian_data = res[1]
    varian_dic = res[0]

    #Get main parameters for ppm scale:
    sw = float(varian_dic["procpar"]["sw"]["values"][0])
    obs = float(varian_dic["procpar"]["sfrq"]["values"][0])
    car = float(varian_dic["procpar"]["reffrq"]["values"][0])

    #Convert varian to pipe:
    universal_varian_dic = varian.guess_udic(varian_dic, varian_data)
    universal_varian_dic[0]["sw"] = sw
    universal_varian_dic[0]["obs"] = obs
    universal_varian_dic[0]["label"] = varian_dic["procpar"]["tn"]["values"][0]
    universal_varian_dic[0]["car"] = car
    C = convert.converter()
    C.from_varian(varian_dic, varian_data, universal_varian_dic)
    pipe_dic, varian_pipe_data = C.to_pipe()
    pipe_dic["FDF1SW"] = sw
    pipe_dic["FDF1OBS"] = obs
    pipe_dic["FDF1LABEL"] = universal_varian_dic[0]["label"]
    pipe_dic["FDF1CAR"] = car

    #If zero filling:
    if zero_filling:
        pipe_dic, varian_data = pipe_proc.zf(pipe_dic, varian_data)

    #If apodization:
    if apodization:
        lb_d = float(varian_dic["procpar"]["lb"]["values"][0])
        pipe_dic, varian_data = pipe_proc.em(pipe_dic, varian_data, lb=lb_d)

    #Fourier Transform:
    pipe_dic, varian_data = pipe_proc.ft(pipe_dic,
                                         varian_data,
                                         auto=True,
                                         inv=True)

    #Phase correction:
    p_zero = float(varian_dic["procpar"]["rp"]["values"][0])
    p_one = float(varian_dic["procpar"]["lp"]["values"][0])
    pipe_dic, varian_data = pipe_proc.ps(pipe_dic,
                                         varian_data,
                                         p0=p_zero,
                                         p1=p_one,
                                         inv=True)

    #Baseline Correction:
    pipe_dic, varian_data = pipe_proc.cbf(pipe_dic, varian_data)

    #Remove imaginary numbers:
    dic, data = pipe_proc.di(pipe_dic, varian_data)

    #Calculate ppm scale:
    ppm = list()
    ppm_f = (obs * 1000000 + sw / 2 - (car * 1000000)) / car
    ppm_width = sw / car
    ppm_i = ppm_f - ppm_width
    n = int(len(data))
    ppm_step = ppm_width / n
    ppm.append(ppm_i)
    for i in range(1, n):
        ppm.append(ppm[i - 1] + ppm_step)

    return (ppm, abs(data))
def read_varian_spec2d_raw(spectrum_directory,
                           fid_filename,
                           procpar_filename,
                           zero_filling=True,
                           apodization=True):
    from nmrglue.fileio import varian, convert
    from nmrglue.process import pipe_proc

    # Read varian files
    res = varian.read(dir=spectrum_directory,
                      fid_file=fid_filename,
                      procpar_file=procpar_filename)
    varian_data = res[1]
    varian_dic = res[0]

    # Get main parameters for ppm scale:
    sw = float(varian_dic["procpar"]["sw"]["values"][0])  #direct dimension
    sw1 = float(varian_dic["procpar"]["sw1"]["values"][0])  #indirect dimension

    obs = float(varian_dic["procpar"]["sfrq"]["values"][0])  #direct dimension
    obs1 = float(
        varian_dic["procpar"]["dfrq"]["values"][0])  #indirect dimension

    car = float(
        varian_dic["procpar"]["reffrq"]["values"][0])  #direct dimension
    car1 = float(
        varian_dic["procpar"]["reffrq1"]["values"][0])  #indirect dimension

    # Convert varian to pipe
    universal_varian_dic = varian.guess_udic(varian_dic, varian_data)

    ## direct dimension
    universal_varian_dic[0]["sw"] = sw
    universal_varian_dic[0]["obs"] = obs
    universal_varian_dic[0]["label"] = varian_dic["procpar"]["tn"]["values"][0]
    universal_varian_dic[0]["car"] = car

    ## indirect dimension
    universal_varian_dic[1]["sw"] = sw1
    universal_varian_dic[1]["obs"] = obs1
    universal_varian_dic[1]["label"] = varian_dic["procpar"]["dn"]["values"][0]
    universal_varian_dic[1]["car"] = car1

    C = convert.converter()
    C.from_varian(varian_dic, varian_data, universal_varian_dic)
    pipe_dic, varian_pipe_data = C.to_pipe()

    ## direct dimension
    pipe_dic["FDF2SW"] = sw
    pipe_dic["FDF2OBS"] = obs
    pipe_dic["FDF2LABEL"] = universal_varian_dic[0]["label"]
    pipe_dic["FDF2CAR"] = car

    ## indirect dimension
    pipe_dic["FDF1SW"] = sw1
    pipe_dic["FDF1OBS"] = obs1
    pipe_dic["FDF1LABEL"] = universal_varian_dic[1]["label"]
    pipe_dic["FDF1CAR"] = car1

    # process the direct dimension
    ## zero filling
    if zero_filling:
        pipe_dic, varian_pipe_data = pipe_proc.zf(pipe_dic, varian_pipe_data)
    ## apodization
    if apodization:
        lb_d = float(varian_dic["procpar"]["lb"]["values"][0])
        pipe_dic, varian_pipe_data = pipe_proc.em(pipe_dic,
                                                  varian_pipe_data,
                                                  lb=lb_d)
        # for lorentz-to-gauss
        # pipe_dic, varian_pipe_data = pipe_proc.gm(pipe_dic, varian_pipe_data)
    ## Fourier transform
    pipe_dic, varian_pipe_data = pipe_proc.ft(pipe_dic,
                                              varian_pipe_data,
                                              auto=True)
    ## Phase Correction
    p_zero = float(varian_dic["procpar"]["rp"]["values"][0])
    p_one = float(varian_dic["procpar"]["lp"]["values"][0])
    pipe_dic, varian_pipe_data = pipe_proc.ps(pipe_dic,
                                              varian_pipe_data,
                                              p0=p_zero,
                                              p1=p_one)
    ## Remove imaginary numbers:
    pipe_dic, varian_pipe_data = pipe_proc.di(pipe_dic, varian_pipe_data)

    # process the indirect dimension
    pipe_dic, varian_pipe_data = pipe_proc.tp(pipe_dic, varian_pipe_data)
    ## zero filling
    if zero_filling:
        pipe_dic, varian_pipe_data = pipe_proc.zf(pipe_dic, varian_pipe_data)
    ## apodization
    if apodization:
        lb_d1 = float(varian_dic["procpar"]["lb1"]["values"][0])
        pipe_dic, varian_pipe_data = pipe_proc.em(pipe_dic,
                                                  varian_pipe_data,
                                                  lb=lb_d1)
        # for lorentz-to-gauss
        # pipe_dic, varian_pipe_data = pipe_proc.gm(pipe_dic, varian_pipe_data)
    ## Fourier transform
    pipe_dic, varian_pipe_data = pipe_proc.ft(pipe_dic,
                                              varian_pipe_data,
                                              auto=True)
    ## Phase Correction
    p_zero1 = float(varian_dic["procpar"]["rp1"]["values"][0])
    p_one1 = float(varian_dic["procpar"]["lp1"]["values"][0])
    pipe_dic, varian_pipe_data = pipe_proc.ps(pipe_dic,
                                              varian_pipe_data,
                                              p0=p_zero1,
                                              p1=p_one1)
    ## Remove imaginary numbers:
    pipe_dic, varian_pipe_data = pipe_proc.di(pipe_dic, varian_pipe_data)

    dic, data = pipe_proc.tp(pipe_dic, varian_pipe_data)

    # Calculate both ppm scales:
    ## direct dimension
    ppm = list()
    ppm_f = (obs * 1000000 + sw / 2 - (car * 1000000)) / car
    ppm_width = sw / car
    ppm_i = ppm_f - ppm_width
    n = int(data.shape[1])
    ppm_step = ppm_width / n
    ppm.append(ppm_i)
    for i in range(1, n):
        ppm.append(ppm[i - 1] + ppm_step)
    new_ppm = ppm[::-1]

    ## indirect dimension
    # handling homonuclear cases
    if car1 == car and sw == sw1:
        ppm1 = list()
        ppm1.append(ppm_i)
        n1 = int(data.shape[0])
        ppm_step1 = ppm_width / n1
        for i in range(1, n1):
            ppm1.append(ppm1[i - 1] + ppm_step1)
        new_ppm1 = ppm1[::-1]
    else:
        ppm1 = list()
        ppm_f1 = (obs1 * 1000000 + sw1 / 2 - (car1 * 1000000)) / car1
        ppm_width1 = sw1 / car1
        ppm_i1 = ppm_f1 - ppm_width1
        n1 = int(data.shape[0])
        ppm_step1 = ppm_width1 / n1
        ppm1.append(ppm_i1)
        for i in range(1, n1):
            ppm1.append(ppm1[i - 1] + ppm_step1)
        new_ppm1 = ppm1[::-1]

    ppms = [new_ppm, new_ppm1]

    return (ppms, abs(data))