for sim_no, pulse_sequence in zip(range(num_sims), pulse_sequences):
        # Initialize simulation
        # Long relaxation times
        def T1_map(position):
            return 100.0

        def T2_map(position):
            return 100.0

        sim = Sim(em_magnetizations, em_positions, em_velocities,
                  em_gyromagnetic_ratio, em_shielding_constants,
                  em_equilibrium_magnetization, T1_map, T2_map, main_field,
                  pulse_sequence)

        # Run simulation
        ems, mrsignals = sim.run_sim()

        # Extract tranverse magnetization as a function of position
        m[sim_no, :] = np.empty(num_ems, dtype=complex)
        for em_no in range(num_ems):
            em = ems[em_no]
            m[sim_no, em_no] = em.mu[0] + em.mu[1] * 1j

    # Plot and calculate theoretical values
    phase_theory = np.angle(m[0, :]) - em_gyromagnetic_ratio * (
        main_field - Gz_tip_amp * z_positions) * pulse_refocus_length * delta_t
    phase_theory = np.mod(phase_theory, 2 * np.pi)
    for phase_no in range(len(phase_theory)):
        if phase_theory[phase_no] > np.pi:
            phase_theory[phase_no] = phase_theory[phase_no] - 2 * np.pi
    plt.figure()
Example #2
0
                                        em_gyromagnetic_ratio,
                                        fe_sample_radius, pe_sample_radius,
                                        kx_max, ky_max, kmove_time, adc_rate,
                                        delta_t)
if see_sequence:
    see_2DFT_sequence(pulse_sequence)

# Run simulation
if run_sim:

    def T1_map(position):
        return 1e6

    def T2_map(position):
        return 1e6

    print('beginning sim with ' + str(num_ems) + ' ems')
    sim = Sim(em_magnetizations, em_positions, em_velocities,
              em_gyromagnetic_ratio, em_shielding_constants,
              em_equilibrium_magnetization, T1_map, T2_map, main_field,
              pulse_sequence)
    ems, mrs = sim.run_sim()

    num_pe_samples = int(2 * pe_sample_radius + 1)
    num_fe_samples = int(2 * fe_sample_radius + 1)
    S = np.empty([num_pe_samples, num_fe_samples], dtype=complex)
    for line_no in range(num_pe_samples):
        S[line_no, :] = mrs[line_no]
    np.savetxt('S_real.csv', np.real(S), delimiter=',', fmt='%.5f')
    np.savetxt('S_imag.csv', np.imag(S), delimiter=',', fmt='%.5f')
        def T1_map(position):
            return T1_max

        def T2_map(position):
            return T2_max

        def D_map(position):
            return np.array([D_water, 0.0, 0.0])

        print('beginning sim with b = ' + str(b_vals[b_val_no]))
        sim = Sim(em_magnetizations, em_positions, em_gyromagnetic_ratio,
                  em_shielding_constants, em_equilibrium_magnetization,
                  em_delta_t, T1_map, T2_map, main_field, pulse_sequence,
                  D_map)
        ems, mr = sim.run_sim()
        mr_store.append(mr)

if plot_sim_results:
    plt.figure()
    for b_val_no in range(num_b_vals):
        mr = mr_store[b_val_no]
        mr = mr[0]
        plt.plot(np.real(mr), label='b=' + str(b_vals[b_val_no]))
    plt.xlabel('sample number')
    plt.ylabel('amplitude')
    plt.title('mr signal for various b-values')
    plt.legend()
    plt.savefig(fig_name)
    plt.show()
Example #4
0
pulse_length = 500
mode = 'free'
Gx = np.ones(pulse_length)
Gy = np.ones(pulse_length)
readout = np.zeros(pulse_length, dtype=bool)
for i in range(len(readout)):
    if not i % 2:
        readout[i] = True
pulse = Pulse(mode=mode, Gx=Gx, Gy=Gy, readout=readout, time_step=time_step)

# Initialize simulation
num_ems = 1
main_field = 10.0
pulse_sequence = [pulse]
sim = Sim(num_ems, main_field, pulse_sequence)

# Run simulation and collect MR signal
mr_signals = sim.run_sim()
mr_signal = mr_signals[0]

# Plot MR signal (FID of one em)
t_readout = []
for step_no in range(pulse_length):
    if readout[step_no]:
        t_readout.append(time_step * step_no)
plt.plot(t_readout, mr_signal.real, '-o')
plt.xlabel('Time (s)')
plt.ylabel('MR signal (a.u.)')
plt.title('FID of a single em')
plt.savefig('fid_one_em.pdf')
Example #5
0
em_positions = np.array([r0])
em_velocities = np.array([v0])
em_gyromagnetic_ratio = gamma
em_shielding_constants = np.array([sigma])
em_equilibrium_magnetization = mu_eq


def T1_map(position):
    return 1e6


def T2_map(position):
    return 1e6


main_field = B0
pulse_sequence = [pulse]
sim = Sim(em_magnetizations, em_positions, em_velocities,
          em_gyromagnetic_ratio, em_shielding_constants,
          em_equilibrium_magnetization, T1_map, T2_map, main_field,
          pulse_sequence)
ems, mrs_demodulated = sim.run_sim()

# Look at MR signal
mr = mrs[0]
plt.plot(t_vals * 1e3, np.real(mr))
plt.plot(t_vals * 1e3, np.imag(mr))
plt.xlabel('Time (ms)')
plt.ylabel('Amplitude (a.u.)')
plt.show()