Example #1
0
 def test_1dphase(self, level=1):
     x = np.arange(32.)
     phs = np.angle(np.exp(1.j * x))
     uw_phs = util.unwrap1D(phs)
     assert_array_almost_equal(x, uw_phs, decimal=14)
     wr_phs = util.normalize_angle(uw_phs)
     assert_array_almost_equal(wr_phs, phs, decimal=14)
    def run(self, image):
        # can't perform segmentation correction on a non-segmented image!
        if image.nseg < 2:
            self.log("Image is non-segmented, nothing to do.")
            return
        pe_per_seg = image.n_pe_true/image.nseg

        # phase angle of inverse fft'd ref navs and image navs
        #ref_nav_phs = angle(ifft(image.ref_nav_data[0], shift=True))
        #nav_phs = angle(ifft(image.nav_data, shift=True))

        ref_nav_phs = N.angle(ifft(image.ref_nav_data[0]))
        nav_phs = N.angle(ifft(image.nav_data))

        # phase difference between ref navs and image navs
        phsdiff = normalize_angle(ref_nav_phs - nav_phs)

        # weight phase difference by the phase encode timing during each segment
        pe_times = (image.pe_times[image.nav_per_seg:]/image.echo_time)[:,N.newaxis]
        theta = N.empty(image.shape, N.float64)
        theta[:,:,:pe_per_seg] = phsdiff[:,:,N.newaxis,0]*pe_times
        theta[:,:,pe_per_seg:] = phsdiff[:,:,N.newaxis,1]*pe_times

        # Apply the phase correction.
        apply_phase_correction(image[:], N.exp(-1.j*theta))
Example #3
0
 def test_1dphase(self, level=1):
     x = np.arange(32.)
     phs = np.angle(np.exp(1.j*x))
     uw_phs = util.unwrap1D(phs)
     assert_array_almost_equal(x, uw_phs, decimal=14)
     wr_phs = util.normalize_angle(uw_phs)
     assert_array_almost_equal(wr_phs, phs, decimal=14)
    def run(self, image):
        # can't perform segmentation correction on a non-segmented image!
        if image.nseg < 2:
            self.log("Image is non-segmented, nothing to do.")
            return
        pe_per_seg = image.n_pe_true / image.nseg

        # phase angle of inverse fft'd ref navs and image navs
        #ref_nav_phs = angle(ifft(image.ref_nav_data[0], shift=True))
        #nav_phs = angle(ifft(image.nav_data, shift=True))

        ref_nav_phs = N.angle(ifft(image.ref_nav_data[0]))
        nav_phs = N.angle(ifft(image.nav_data))

        # phase difference between ref navs and image navs
        phsdiff = normalize_angle(ref_nav_phs - nav_phs)

        # weight phase difference by the phase encode timing during each segment
        pe_times = (image.pe_times[image.nav_per_seg:] /
                    image.echo_time)[:, N.newaxis]
        theta = N.empty(image.shape, N.float64)
        theta[:, :, :pe_per_seg] = phsdiff[:, :, N.newaxis, 0] * pe_times
        theta[:, :, pe_per_seg:] = phsdiff[:, :, N.newaxis, 1] * pe_times

        # Apply the phase correction.
        apply_phase_correction(image[:], N.exp(-1.j * theta))
 def test_simple2d(self, level=1):
     grid = outer(ones(64), arange(-32,32)) + \
            1.j * outer(arange(-32,32), ones(64))
     pgrid = abs(grid)
     wr_grid = normalize_angle(pgrid)
     uw_grid = unwrap2D(wr_grid)
     uw_grid += (pgrid[32,32] - uw_grid[32,32])
     
     assert_array_almost_equal(pgrid, uw_grid, decimal=5)
Example #6
0
    def test_simple2d(self, level=1):
        grid = outer(ones(64), arange(-32,32)) + \
               1.j * outer(arange(-32,32), ones(64))
        pgrid = abs(grid)
        wr_grid = normalize_angle(pgrid)
        uw_grid = unwrap2D(wr_grid)
        uw_grid += (pgrid[32, 32] - uw_grid[32, 32])

        assert_array_almost_equal(pgrid, uw_grid, decimal=5)
 def test_simple3d(self):
     grid = indices((64,64,64))
     grid[0] -= 32
     grid[1] -= 32
     grid[2] -= 32
     # get distance of each point in the grid from 0
     grid = power(power(grid, 2.0).sum(axis=0), 0.5)
     wr_grid = normalize_angle(grid)
     uw_grid = unwrap3D(wr_grid)
     uw_grid += (grid[32,32,32] - uw_grid[32,32,32])
     assert_array_almost_equal(grid, uw_grid, decimal=5)
Example #8
0
 def test_simple3d(self):
     grid = indices((64, 64, 64))
     grid[0] -= 32
     grid[1] -= 32
     grid[2] -= 32
     # get distance of each point in the grid from 0
     grid = power(power(grid, 2.0).sum(axis=0), 0.5)
     wr_grid = normalize_angle(grid)
     uw_grid = unwrap3D(wr_grid)
     uw_grid += (grid[32, 32, 32] - uw_grid[32, 32, 32])
     assert_array_almost_equal(grid, uw_grid, decimal=5)