Пример #1
0
time_step = 0.01
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')
if run_simulation:  # Runs simulation with and without refocus
    pulse_sequences = [[pulse_tip], [pulse_tip, pulse_refocus]]
    num_sims = len(pulse_sequences)
    m = np.empty([num_sims, num_ems], dtype=complex)
    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)
Пример #3
0
# Create pulse sequence
pulse_sequence = generate_DWI_sequence(main_field,Gz_amplitude,slice_width,gyromagnetic_ratio,fe_sample_radius,pe_sample_radius,kx_max,ky_max,kmove_time,kread_time,repetition_time,pulse_delta_t,read_all,diffusion_gradients,diffusion_gradient_time,diffusion_time)



if run_sim:
    # Run simulation
    def T1_map(position): return T1_max
    def T2_map(position): return T2_max
    def D_map(position):
        if position[0]>0:
            return np.array([5e-6,5e-6,0.0])
        else:
            return np.array([0.0,0.0,0.0])
    print('beginning sim with ' + str(num_ems) + ' ems')
    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,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]
    img,x,y = reconstruct_from_2DFT(S,kx_max,ky_max)
    np.savetxt('em-positions_'+fig_params+'.csv',em_positions,delimiter=',')
    np.savetxt('img_'+fig_params+'.csv',img,delimiter=',')
    np.savetxt('x_'+fig_params+'.csv',x,delimiter=',')
    np.savetxt('y_'+fig_params+'.csv',y,delimiter=',')

if plot_sim_results:
    em_positions_0 = 1e-2*np.array([[0.5,0.5,0.0],
                              [0.5,0.0,0.0],