def test_phase(self):
        """
        Compares phase generation to matlab results.
        """
        expected_gpe = get_data_with_key(TEST_DIR, TEST_FILE, "gpe")
        expected_petable = get_data_with_key(TEST_DIR, TEST_FILE, "petable")

        Np = 32
        Fov_p = 7
        gpe, petable = generate_phase_encode_gradient(Np, Fov_p, g_max, s_max, dt)
        self.assertTrue(np.allclose(expected_gpe, gpe))
        self.assertTrue(np.allclose(expected_petable, petable))
    def test_readout(self):
        """
        Compares readout generation to matlab results.
        """
        expected_gx = get_data_with_key(TEST_DIR, TEST_FILE, "gx")
        expected_rowin = get_data_with_key(TEST_DIR, TEST_FILE, "rowin")

        Nf = 64
        Fov_r  = 14
        bwpp = 1862.4
        gx, rowin = generate_readout_gradient(Nf, Fov_r, bwpp, g_max, s_max, dt)
        self.assertTrue(np.allclose(expected_gx, gx))
        self.assertTrue(np.allclose(expected_rowin, rowin))
    def test_phase(self):
        """
        Compares phase generation to matlab results.
        """
        expected_gpe = get_data_with_key(TEST_DIR, TEST_FILE, "gpe")
        expected_petable = get_data_with_key(TEST_DIR, TEST_FILE, "petable")

        Np = 32
        Fov_p = 7
        gpe, petable = generate_phase_encode_gradient(Np, Fov_p, g_max, s_max,
                                                      dt)
        self.assertTrue(np.allclose(expected_gpe, gpe))
        self.assertTrue(np.allclose(expected_petable, petable))
    def test_readout(self):
        """
        Compares readout generation to matlab results.
        """
        expected_gx = get_data_with_key(TEST_DIR, TEST_FILE, "gx")
        expected_rowin = get_data_with_key(TEST_DIR, TEST_FILE, "rowin")

        Nf = 64
        Fov_r = 14
        bwpp = 1862.4
        gx, rowin = generate_readout_gradient(Nf, Fov_r, bwpp, g_max, s_max,
                                              dt)
        self.assertTrue(np.allclose(expected_gx, gx))
        self.assertTrue(np.allclose(expected_rowin, rowin))
    def test_waveforms(self):
        """
        Tests waveforms against matlab code results.
        """
        expected_gy = get_data_with_key(TEST_DIR, TEST_FILE, "gy") 

        Np = 32
        fov = 7
        smax = 15000
        gmax = 4
        gamma = 4257
        dt = 4e-6

        kmax = 1/(fov/Np)/2
        area = kmax / gamma
        gy = minimum_time_gradient(area, gmax, smax, dt)
        self.assertTrue(np.allclose(expected_gy, gy))
    def test_sinc_pulse(self):
        """
        Tests generation of sinc pulse.
        """
        expected_mxy = get_data_with_key(TEST_DIR, "rf_test", "mxy")

        duration = 3.2e-3
        dt = duration / 256
        flip = np.pi / 2
        tbw = 8

        rf = sinc_pulse(tbw, flip, duration, dt)
        g = np.ones(rf.size) * .6
        dp = np.linspace(-2, 2, 512)
        mx0 = np.zeros(512)
        my0 = np.zeros(512)
        mz0 = np.ones(512)

        mx, my, mz = bloch(rf, g, dt, 100, 100, 0, dp, 0, mx0, my0, mz0)
        mxy = mx + 1.0j * my
        np.allclose(expected_mxy, mxy)
    def test_sinc_pulse(self):
        """
        Tests generation of sinc pulse.
        """
        expected_mxy = get_data_with_key(TEST_DIR, "rf_test", "mxy")

        duration = 3.2e-3
        dt = duration / 256
        flip = np.pi / 2
        tbw = 8

        rf = sinc_pulse(tbw, flip, duration, dt)
        g = np.ones(rf.size) * .6
        dp = np.linspace(-2, 2, 512)
        mx0 = np.zeros(512)
        my0 = np.zeros(512)
        mz0 = np.ones(512)

        mx, my, mz = bloch(rf, g, dt, 100, 100, 0, dp, 0, mx0, my0, mz0)
        mxy = mx + 1.0j*my
        np.allclose(expected_mxy, mxy)