コード例 #1
0
ファイル: test_apod.py プロジェクト: fenglb/nmrpro
 def test_apod_pipe(self):
     dic, data = self.dic, self.data
     spec2d = fromPipe(self.filename)
     
     
     # 2D FFT using pipe_proc functions
     dic3, data3 = pipep.em(dic, data, 0.2)
     dic3, data3 = pipep.tp(dic3, data3, auto=True)
     dic3, data3 = pipep.em(dic3, data3, 0.2)
     dic3, data3 = pipep.tp(dic3, data3, auto=True)
     
     # test auto class implementation
     apoded = apod(spec2d, w=lambda s: EM(s))
     ts.assert_equal(data3, apoded, '2D Apodized spectrum doesnt match pipe_proc.em')
コード例 #2
0
ファイル: test_apod.py プロジェクト: fenglb/nmrpro
 def test_apod_em(self):
     spec = fromBruker(self.filename, False, False)
     spec = apod(spec, w=lambda s: EM(s))
     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.em(pipe_dic, pipe_data, lb=0.2)[1]        
     ts.assert_allclose(spec, test_data, 1e-7,1e-3, 'EM apodization not equal to NMRPipe processed one.')
コード例 #3
0
ファイル: test_apod.py プロジェクト: fenglb/nmrpro
 def test_apod_different_F1F2(self):
     dic, data = self.dic, self.data
     spec2d = fromPipe(self.filename)
     
     
     # 2D FFT using pipe_proc functions
     dic3, data3 = pipep.em(dic, data, 0.2)
     dic3, data3 = pipep.tp(dic3, data3, auto=True)
     dic3, data3 = pipep.gm(dic3, data3, 1, 0.5, 0.5)
     dic3, data3 = pipep.tp(dic3, data3, auto=True)
     
     # test auto class implementation
     apoded = apod(spec2d, F2_w1=lambda s: EM(s, 0.2), F1_w2=lambda s: GM(s, 1, 0.5, 0.5))
     ts.assert_equal(data3, apoded, '2D Apodized spectrum doesnt match pipe_proc.em and gm on F1 and F2')
コード例 #4
0
ファイル: to_fix.py プロジェクト: winter27/nmrglue
d, a = p.ht(d, a, mode="ps90-180")
pipe.write("ht4.glue", d, a, overwrite=True)

# Integration tests
# process 2D mixed mode data
d, a = pipe.read("time_real.fid")
d, a = p.gmb(d, a, gb=0.1, lb=-8, c=0.5)
d, a = p.zf(d, a, auto=True)
d, a = p.ft(d, a, alt=True)  # BUG glue seems to double the data...?
d, a = p.ps(d, a, p0=0, p1=0)
d, a = p.tp(d, a, hyper=True)
d, a = p.sp(d, a, off=0.5, pow=2, c=0.5)
d, a = p.zf(d, a, auto=True)
d, a = p.ft(d, a, auto=True)
d, a = p.ps(d, a, p0=0, p1=0)
d, a = p.di(d, a)
pipe.write("2d_mixed_processing1.glue", d, a, overwrite=True)

# process 2D mixed mode data
d, a = pipe.read("time_real.fid")
d, a = p.em(d, a, lb=8)
d, a = p.zf(d, a, auto=True)
d, a = p.ft(d, a, auto=True)
d, a = p.di(d, a)
d, a = p.tp(d, a)
d, a = p.sp(d, a, off=0.5, pow=1, c=0.5)
d, a = p.zf(d, a, auto=True)
d, a = p.ft(d, a, auto=True)
d, a = p.mc(d, a)
pipe.write("2d_mixed_processing2.glue", d, a, overwrite=True)
コード例 #5
0
ファイル: em.py プロジェクト: winter27/nmrglue
#! /usr/bin/env python
""" Create files for em unit test """

import nmrglue.fileio.pipe as pipe
import nmrglue.process.pipe_proc as p

# EM Testing
d, a = pipe.read("time_complex.fid")
d, a = p.em(d, a, lb=40, c=0.5, start=100, size=750, one=True)
pipe.write("em1.glue", d, a, overwrite=True)

d, a = pipe.read("time_complex.fid")
d, a = p.em(d, a, lb=20, c=1.5, size=900)
pipe.write("em2.glue", d, a, overwrite=True)
コード例 #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))
コード例 #7
0
ファイル: em.py プロジェクト: rpbarnes/nmrglue
#! /usr/bin/env python

import nmrglue.fileio.pipe as pipe
import nmrglue.process.pipe_proc as p

# EM Testing
d,a = pipe.read("time_complex.fid")
d,a = p.em(d,a,lb=40,c=0.5,start=100,size=750,one=True)
pipe.write("em.glue",d,a,overwrite=True)

d,a = pipe.read("time_complex.fid")
d,a = p.em(d,a,lb=20,c=1.5,size=900)
pipe.write("em2.glue",d,a,overwrite=True)
コード例 #8
0
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))