Exemplo n.º 1
0
 def testTriInverse(self):
     from org.nmrfx.processor.operations import Tri
     op = Tri(0, 1.0, 1.0, False)
     v = Vec(1000, False)
     v.ones()
     op.eval(v)
     iop = op.getInverseOp()
     iop.eval(v)
     self.isAlmostEqualTo(v.getList(), 1.0)
Exemplo n.º 2
0
 def testSinebellApodInverseComplex(self):
     v = Vec(1024, True)
     v.ones()
     offset = 0.5
     end = 0.98
     power = 1.0
     c = 1.0
     apodSize = 0
     op = SinebellApod(offset, end, power, c, apodSize, False)
     op.eval(v)
     iop = op.getInverseOp()
     iop.eval(v)
     self.isAlmostEqualTo(v.getList(), 1.0)
Exemplo n.º 3
0
    def testGf(self):
        importOp("Gf")
        from math import pi, exp
        v = Vec(1025, False)
        v.ones()
        dwell = 1.0 / 1000.0
        v.setDwellTime(dwell)

        gf = 0.5
        gfs = 0.1
        fPoint = 1.0

        op = Gf(gf, gfs, fPoint)
        op.eval(v)
Exemplo n.º 4
0
    def testExpdInverse(self):
        importOp("Expd")
        from math import pi, exp
        v = Vec(1025, False)
        v.ones()
        dwell = 1.0 / 1000.0
        v.setDwellTime(dwell)

        lb = 2.0
        fPoint = 1.0

        op = Expd(lb, fPoint, False)
        op.eval(v)
        iop = op.getInverseOp()
        iop.eval(v)
        self.isAlmostEqualTo(v.getList(), 1.0)
Exemplo n.º 5
0
    def testExpd(self):
        importOp("Expd")
        from math import pi, exp
        v = Vec(1025, False)
        v.ones()
        dwell = 1.0 / 1000.0
        v.setDwellTime(dwell)

        lb = 2.0
        fPoint = 1.0
        op = Expd(lb, fPoint, False)
        op.eval(v)
        decay = pi * lb

        for index, val in enumerate(v.getList()):
            testVal = exp(-1.0 * index * decay * dwell)
            self.assertAlmostEqual(val, testVal)
Exemplo n.º 6
0
    def testGmbInverse(self):
        importOp("Gmb")
        from math import pi, exp
        v = Vec(1025, False)
        v.ones()
        dwell = 1.0 / 1000.0
        v.setDwellTime(dwell)

        gb = 0.1
        lb = 2.0
        fPoint = 1.0

        op = Gmb(gb, lb, fPoint)
        op.eval(v)
        iop = op.getInverseOp()
        iop.eval(v)

        self.isAlmostEqualTo(v.getList(), 1.0)
Exemplo n.º 7
0
    def testGfInverse(self):
        importOp("Gf")
        from math import pi, exp
        v = Vec(1025, False)
        v.ones()
        dwell = 1.0 / 1000.0
        v.setDwellTime(dwell)

        gf = 0.5
        gfs = 0.1
        fPoint = 1.0

        op = Gf(gf, gfs, fPoint)
        op.eval(v)
        iop = op.getInverseOp()
        iop.eval(v)

        self.isAlmostEqualTo(v.getList(), 1.0)
Exemplo n.º 8
0
        def test_case(size, pt1, pt2):
            '''Pass in pt1, pt2, and vector size and verify that it is correct'''
            v = Vec(size, False)
            v.ones()
            op = Tm(pt1, pt2)
            op.eval(v)

            for i in range(0, pt1):
                self.assert_(v[i] < v[i + 1])

            for i in range(pt1, pt2):
                self.assert_(v[i] == v[i + 1])

            for i in range(pt2, size - 1):
                self.assert_(v[i] > v[i + 1])
            self.assertAlmostEqual(v[pt1], 1.0)
            self.assertAlmostEqual(v[pt1 / 2], 0.5, 5)
            self.assertAlmostEqual(v[pt2], 1.0)
            self.assertAlmostEqual(v[pt2 + (size - pt2) / 2], 0.5, 5)
Exemplo n.º 9
0
    def testApodization(self):
        importOp('Apodization')

        class MultByLineApod(Apodization):
            def __init__(self, size):
                self.resize(size)
                self.setApodVec([float(i) / 256 for i in range(256)])

            def eval(self, vector):
                self.applyApod(vector)
                return self

        v = Vec(256, True)
        v.ones()

        op = MultByLineApod(256)

        op.eval(v)
        temp = v.getList()
        for i, v in enumerate(temp):
            self.assertEqual(i / 256.0, v)
Exemplo n.º 10
0
    def testTri(self):
        from org.nmrfx.processor.operations import Tri
        op = Tri(0, 1.0, 1.0, False)

        v = Vec(1000, False)
        v.ones()
        op.eval(v)
        for i in range(v.getSize()):
            self.assertAlmostEqual(v[i], 1.0)
        self.assertEqual(v.getReal(0), 1.0)
        self.assertEqual(v.getReal(999), 1.0)

        op = Tri(500, -10.0, 10.0, False)
        v1 = Vec(1000, False)
        v1.ones()
        op.eval(v1)
        self.assertAlmostEqual(v1.getReal(0), -10.0)
        self.assertAlmostEqual(v1.getReal(999), 10.0)

        for i in range(v.getSize() - 1):
            self.assert_(v[i] <= v[i + 1])

        v2 = Vec(100, False)
        v2.ones()
        op = Tri(0, 0.0, 2.0, False)
        op.eval(v2)
        self.assertAlmostEqual(v2.getReal(0), 1.0)
        self.assertAlmostEqual(v2.getReal(49), 1.5, 1)
        self.assertAlmostEqual(v2.getReal(99), 2.0)

        for i in range(v.getSize() - 1):
            self.assert_(v[i] <= v[i + 1])
Exemplo n.º 11
0
        def test_case(size=10, shift=1, complex=False, useApache=False):
            v = Vec(10, complex)
            if (useApache):
                v.makeApache()

            v.ones()
            v.rand()

            temp = v.getList()

            shift = 3
            op = Shift(shift)
            op.eval(v)

            for index, val in enumerate(v.getList()):
                if index < shift:
                    self.assertEqual(val.real, 0)
                    if complex:
                        self.assertEqual(val.imag, 0)
                else:
                    self.assertEqual(val.real, temp[index - shift].real)
                    if complex:
                        self.assertEqual(val.imag, temp[index - shift].imag)
Exemplo n.º 12
0
    def testSinebellApod(self):
        importOp("SinebellApod")
        from math import pi, sin
        #from 0 to Pi inclusive
        v = Vec(1025, False)
        v.ones()

        #offset = 0.5
        offset = 0.0
        end = 1.0
        power = 1.0
        c = 1.0
        apodSize = 0

        temp = v.getList()
        op = SinebellApod(offset, end, power, c, apodSize, False)

        op.eval(v)

        for val, index in zip([sin(i) for i in [pi * j / 4 for j in range(5)]],
                              [0, 256, 512, 768, 1024]):
            self.assertAlmostEqual(val, v[index])

        offset = 0.5
        end = 1.5

        v = Vec(1025, False)
        v.ones()

        op = SinebellApod(offset, end, power, c, apodSize, False)

        op.eval(v)
        for val, index in zip(
            [sin(i) for i in [.5 * pi + pi * j / 4 for j in range(5)]],
            [0, 256, 512, 768, 1024]):
            self.assertAlmostEqual(val, v[index])
Exemplo n.º 13
0
    def offtestIstCL(self):
        importOp("IstCL")
        importOp("Ft")
        importOp("Add")
        import pyproc
        from java.util import ArrayList

        #testing single Vector FFT with JavaCL and comparing the result to
        #the vector.ft method
        vec = Vec(1024, True)
        self.assert_(vec.useApache())
        pyproc.GEN(vector=vec)
        vectors = ArrayList()
        vectors.add(vec)

        op = IstCL(1)
        op.initializeVectors(vectors)
        op.initializeBuffers()
        #op.onePass(vectors)
        op.parallelfft(False)
        op.copyBack(vectors, False)
        op.finish()

        vec2 = Vec(1024, True)
        pyproc.GEN(vector=vec2)

        op = Ft(False, False)
        op.eval(vec2)

        #vec2.ft()

        #testing fft
        for (v1, v2) in zip(vec.getList(), vec2.getList()):
            self.assertAlmostEqual(v1.real, v2.real, 12)
            self.assertAlmostEqual(v1.imag, v2.imag, 12)
        '''
        test norm
        '''
        vec1 = Vec(32, True)
        vec2 = Vec(32, True)

        add = Add(100.0, 100.0)
        add.eval(vec1)
        add.eval(vec2)

        set_max_index = 31

        vec1.set(set_max_index, 101.0, 101.0)
        vec2.set(set_max_index, 101.0, 101.0)

        op = IstCL(1)
        vectors = ArrayList()
        vectors.add(vec1)

        op.initializeVectors(vectors)
        op.initializeBuffers()
        op.declareComplexNorm()
        op.declareReduceMax()
        op.norm()
        norms = op.copyBackNormBuffer()
        op.reduceMax()
        m = op.copyBackMaxBuffer()
        index = op.copyBackMaxIndexBuffer()
        print index
        op.finish()

        vec2norm = [i.real**2 + i.imag**2 for i in vec2.getList()]
        for v1, v2 in zip(norms, vec2norm):
            self.assertEqual(v1, v2)

        self.assertEqual(m, 101 * 101 + 101 * 101)
        self.assertAlmostEqual(index, set_max_index)

        #for (v1, v2) in zip(vec1.getList(), vec2.getList()):
        #    self.assertAlmostEqual(v1.real, v2.real, 12)
        #    self.assertAlmostEqual(v1.imag, v2.imag, 12)
        '''Test thresholding without fft'''
        vec1 = Vec(256, True)
        vec2 = Vec(256, True)

        vec1.ones()
        vec2.ones()

        vec1.multiply(100.0, 0)
        vec2.multiply(3.04, 0)
        #vec2.ft();
        #vec2.ift();
        #if we have a threshold of .96, then all values will be thresholded by
        #96.96 and will be reduced to 3.04
        vec1.setComplex(2, 101.0, 0.0)
        vec2.setComplex(2, 3.04, 0.0)

        op = IstCL(1)
        vectors = ArrayList()
        vectors.add(vec1)
        op.initializeVectors(vectors)
        op.initializeBuffers()
        op.norm()
        op.reduceMax()
        op.threshold()
        op.copyBack(vectors, True)

        op.finish()

        for (i, (v1, v2)) in enumerate(zip(vec1.getList(), vec2.getList())):
            print i
            self.assertAlmostEqual(v1.real, v2.real, 12)
            self.assertAlmostEqual(v1.imag, v2.imag, 12)
        '''