Beispiel #1
0
 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')
Beispiel #2
0
 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')
Beispiel #3
0
def fromPipe(file):
    dic, data = pipe.read(file)
    if dic['FDTRANSPOSED'] == 1.:
        dic, data = pp.tp(dic, data, auto=True)

    u = pipe.guess_udic(dic, data)
    u["original_format"] = 'Pipe'
    u["Name"] = get_name(file)
    
    uc = [make_uc_pipe(dic, data, dim) for dim in range(0, data.ndim)]
    return NMRSpectrum(data, u, uc=uc)
Beispiel #4
0
def fromPipe(file):
    dic, data = pipe.read(file)
    if dic['FDTRANSPOSED'] == 1.:
        dic, data = pp.tp(dic, data, auto=True)

    u = pipe.guess_udic(dic, data)
    u["original_format"] = 'Pipe'
    u["Name"] = get_name(file)

    uc = [make_uc_pipe(dic, data, dim) for dim in range(0, data.ndim)]
    return NMRSpectrum(data, u, uc=uc)
Beispiel #5
0
#! /usr/bin/env python
""" Create files for tp unit test """

from subprocess import check_call
import os

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

d, a = pipe.read("time_complex.fid")
d, a = p.tp(d, a, auto=True)
pipe.write("tp1.glue", d, a, overwrite=True)

d, a = pipe.read("time_complex.fid")
d, a = p.tp(d, a, hyper=True)
pipe.write("tp2.glue", d, a, overwrite=True)

d, a = pipe.read("time_complex.fid")
d, a = p.tp(d, a, nohyper=True)
pipe.write("tp3.glue", d, a, overwrite=True)


pipe_command = """\
/bin/csh -c 'nmrPipe -in ./time_complex.fid                \
| nmrPipe  -fn FT  -auto \
-ov -out time-freq.c.ft1'"""
check_call(pipe_command, shell=True)

d, a = pipe.read("time-freq.c.ft1")
d, a = p.tp(d, a, hyper=True)
pipe.write("tp4.glue", d, a, overwrite=True)
Beispiel #6
0
#! /usr/bin/env python
""" Create files for tp unit test """

from subprocess import check_call
import os

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

d, a = pipe.read("time_complex.fid")
d, a = p.tp(d, a, auto=True)
pipe.write("tp1.glue", d, a, overwrite=True)

d, a = pipe.read("time_complex.fid")
d, a = p.tp(d, a, hyper=True)
pipe.write("tp2.glue", d, a, overwrite=True)

d, a = pipe.read("time_complex.fid")
d, a = p.tp(d, a, nohyper=True)
pipe.write("tp3.glue", d, a, overwrite=True)

pipe_command = """\
/bin/csh -c 'nmrPipe -in ./time_complex.fid                \
| nmrPipe  -fn FT  -auto \
-ov -out time-freq.c.ft1'"""
check_call(pipe_command, shell=True)

d, a = pipe.read("time-freq.c.ft1")
d, a = p.tp(d, a, hyper=True)
pipe.write("tp4.glue", d, a, overwrite=True)
Beispiel #7
0
pipe.write("rft11.glue", d, a, overwrite=True)

# HT
# ps90-180 mode doesn't match
d, a = pipe.read("1D_freq_real.dat")
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)
#! /usr/bin/env python
""" Create files for complex_processing unit test """

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

# process 2D complex data with Gaussian and cos^2 windows
d, a = pipe.read("time_complex.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, auto=True)
d, a = p.ps(d, a, p0=-36, p1=0)
d, a = p.di(d, a)
d, a = p.tp(d, a)
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=-7, p1=0)
d, a = p.di(d, a)
pipe.write("2d_complex_processing1.glue", d, a, overwrite=True)
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))