def cpmgT1( self, cpmg_freq, pulse1_us, pulse2_us, pulse1_dtcl, pulse2_dtcl, echo_spacing_us, scan_spacing_us, samples_per_echo, echoes_per_scan, init_adc_delay_compensation, number_of_iteration, ph_cycl_en, pulse180_t1_us, logsw, delay180_sta, delay180_sto, delay180_ste, ref_number_of_iteration, ref_twait_mult, data_folder, en_scan_fig, en_fig ): # create t1 measurement folder t1_meas_folder = datetime.now().strftime( '%Y_%m_%d_%H_%M_%S' ) + '_t1_meas' os.mkdir( t1_meas_folder ) t1_meas_hist = 't1_meas_hist.txt' # the history file name for t1 measurement self.fig_num = 1 self.fcpmg_to_fsys_mult = 16 # system_frequency/cpmg_frequency,set by fpga self.t1_opt_mult = 1.6 # compute period for the system clock (which is multiplication of the cpmg # freq) t_sys = ( 1 / cpmg_freq ) / self.fcpmg_to_fsys_mult # compute pulse180_t1 in integer values and round it to # fcpmg_to_fsys_mult multiplication pulse180_t1_int = np.round( ( pulse180_t1_us / t_sys ) / self.fcpmg_to_fsys_mult ) * self.fcpmg_to_fsys_mult # process delay if logsw: delay180_t1_sw = np.logspace( np.log10( delay180_sta ), np.log10( delay180_sto ), delay180_ste ) else: delay180_t1_sw = np.linspace( delay180_sta, delay180_sto, delay180_ste ) # make delay to be multiplication of fcpmg_to_fsys_mult delay180_t1_sw_int = np.round( ( delay180_t1_sw / t_sys ) / self.fcpmg_to_fsys_mult ) * self.fcpmg_to_fsys_mult # compute the reference and do cpmg ref_twait = ref_twait_mult * delay180_t1_sw_int[delay180_ste - 1] ref_twait_int = np.round( ( ref_twait ) / self.fcpmg_to_fsys_mult ) * self.fcpmg_to_fsys_mult self.cpmgSequence( cpmg_freq, pulse1_us, pulse2_us, pulse1_dtcl, pulse2_dtcl, echo_spacing_us, scan_spacing_us, samples_per_echo, echoes_per_scan, init_adc_delay_compensation, ref_number_of_iteration, ph_cycl_en, pulse180_t1_int, ref_twait_int ) # process the data meas_folder = parse_simple_info( data_folder, 'current_folder.txt' ) ( a_ref, _, a0_ref, snr_ref, T2_ref, noise_ref, res_ref, theta_ref, data_filt_ref, echo_avg_ref, Df, _ ) = compute_iterate( data_folder, meas_folder[0], 0, 0, 0, en_scan_fig ) # move the folder to t1 measurement folder and write history shutil.move( meas_folder[0], t1_meas_folder ) write_text_append( t1_meas_folder, t1_meas_hist, meas_folder[0] ) # make the loop a0_table = np.zeros( delay180_ste ) # normal format a0_table_decay = np.zeros( delay180_ste ) # decay format asum_table = np.zeros( delay180_ste ) # normal format asum_table_decay = np.zeros( delay180_ste ) # decay format for i in range( 0, delay180_ste ): delay180_t1_int = delay180_t1_sw_int[i] # do cpmg scan self.cpmgSequence( cpmg_freq, pulse1_us, pulse2_us, pulse1_dtcl, pulse2_dtcl, echo_spacing_us, scan_spacing_us, samples_per_echo, echoes_per_scan, init_adc_delay_compensation, number_of_iteration, ph_cycl_en, pulse180_t1_int, delay180_t1_int ) # process the data (note that a0 and T2 is based on single # exponential fit) meas_folder = parse_simple_info( data_folder, 'current_folder.txt' ) ( a, _, a0, snr, T2, noise, res, theta, data_filt, echo_avg, Df, _ ) = compute_iterate( data_folder, meas_folder[0], 1, theta_ref, echo_avg_ref, en_scan_fig ) # move the folder to t1 measurement folder and write history shutil.move( meas_folder[0], t1_meas_folder ) write_text_append( t1_meas_folder, t1_meas_hist, meas_folder[0] ) # interscan data store a0_table[i] = a0 a0_table_decay[i] = a0_ref - a0 asum_table[i] = np.mean( np.real( a ) ) asum_table_decay[i] = np.mean( np.real( a_ref ) ) - np.mean( np.real( a ) ) if en_fig: print( 'Loading Figure' ) plt.ion() fig = plt.figure( self.fig_num ) fig.clf() ax = fig.add_subplot( 3, 1, 1 ) if logsw: line1, = ax.semilogx( delay180_t1_sw[0:i + 1] / 1000, asum_table[0:i + 1], 'r-' ) else: line1, = ax.plot( delay180_t1_sw[0:i + 1] / 1000, asum_table[0:i + 1], 'r-' ) # ax.set_xlim(-50, 0) # ax.set_ylim(-50, 0) ax.set_ylabel( 'Initial amplitude [a.u.]' ) ax.set_title( "T1 inversion recovery" ) ax.grid() ax = fig.add_subplot( 3, 1, 2 ) if logsw: line1, = ax.semilogx( delay180_t1_sw[0:i + 1] / 1000, asum_table_decay[0:i + 1], 'r-' ) else: line1, = ax.plot( delay180_t1_sw[0:i + 1] / 1000, asum_table_decay[0:i + 1], 'r-' ) # ax.set_xlim(-50, 0) # ax.set_ylim(-50, 0) # ax.set_xlabel('Wait time [ms]') ax.set_ylabel( 'Initial amplitude [a.u.]' ) ax.grid() ax = fig.add_subplot( 3, 1, 3 ) ax.set_ylabel( 'Amplitude [a.u.]' ) ax.set_xlabel( 'Wait time [ms]' ) ax.grid() fig.canvas.draw() fig.canvas.flush_events() print( 'Figure Loaded' ) # save t1 data to csv file to be processed f = open( t1_meas_folder + '/' + 't1heel_in.csv', "w+" ) for i in range( 0, delay180_ste ): f.write( "%f," % ( delay180_t1_sw[i] / 1000 ) ) # in milisecond f.write( "%f\n" % ( a0_table_decay[i] ) ) f.close() # process t1 data self.doLaplaceInversion( t1_meas_folder + '/' + 't1heel_in.csv', t1_meas_folder ) tvect, data = parse_csv_float2col( t1_meas_folder, 't1heel_out.csv' ) i_peaks = signal.find_peaks_cwt( data, np.arange( 1, 10 ) ) t1_opt = tvect[max( i_peaks )] ''' a_peaks = np.zeros(len(i_peaks)) for i in range(0, len(i_peaks)): a_peaks[i] = data[i_peaks[i]] # find tvect in which the largest peak is found t1_opt = tvect[i_peaks[np.where(max(a_peaks))[0][0]]] # in second ''' if en_fig: ax = fig.add_subplot( 3, 1, 3 ) if logsw: line1, = ax.semilogx( np.multiply( tvect, 1000 ), data, 'r-' ) else: line1, = ax.plot( np.multiply( tvect, 1000 ), data, 'r-' ) ax.set_ylabel( 'Amplitude [a.u.]' ) ax.set_xlabel( 'Wait time [ms]' ) ax.grid() fig.canvas.draw() # copy the measurement history script shutil.copy( 'measurement_history_matlab_script.txt', t1_meas_folder ) return delay180_t1_sw, a0_table, a0_ref, asum_table, t1_opt, t1_meas_folder
# turn off system nmrObj.deassertControlSignal(nmrObj.RX1_1H_msk | nmrObj.RX1_1L_msk | nmrObj.RX2_L_msk | nmrObj.RX2_H_msk | nmrObj.RX_SEL1_msk | nmrObj.RX_FL_msk | nmrObj.RX_FH_msk | nmrObj.PAMP_IN_SEL2_msk) nmrObj.setMatchingNetwork(0, 0) nmrObj.setPreampTuning(0, 0) nmrObj.deassertControlSignal(nmrObj.PSU_15V_TX_P_EN_msk | nmrObj.PSU_15V_TX_N_EN_msk | nmrObj.PSU_5V_TX_N_EN_msk | nmrObj.PSU_5V_ADC_EN_msk | nmrObj.PSU_5V_ANA_P_EN_msk | nmrObj.PSU_5V_ANA_N_EN_msk) shutil.copy2(data_folder + '/' + meas_folder[0] + '/acqu.par', dst_path) for kk in range(0, pulse_us_ste): data_parser.write_text_append(dst_path, 'acqu.par', 'P90 = {}'.format(P90[kk])) for kk in range(0, pulse_us_ste): data_parser.write_text_append(dst_path, 'acqu.par', 'P180 = {}'.format(P180[kk])) if en_fig: fig.savefig(dst_path + '/' + datename + '_pulsesw.pdf') pass pass
Vvarac = 2.8 # (vbias vvarac) nmrObj.setPreampTuning(Vbias, Vvarac) #-2.5, 2.8) # try -2.7, -1.8 if fail nmrObj.setMatchingNetwork( 0, 0 ) nmrObj.setMatchingNetwork( 0, 0 ) while True: nmrObj.assertControlSignal( nmrObj.RX1_1L_msk | nmrObj.RX2_L_msk | nmrObj.RX2_H_msk | nmrObj.RX_SEL1_msk | nmrObj.RX_FL_msk ) nmrObj.assertControlSignal( nmrObj.PSU_15V_TX_P_EN_msk | nmrObj.PSU_15V_TX_N_EN_msk | nmrObj.PSU_5V_TX_N_EN_msk | nmrObj.PSU_5V_ADC_EN_msk | nmrObj.PSU_5V_ANA_P_EN_msk | nmrObj.PSU_5V_ANA_N_EN_msk ) time.sleep( 0.1 ) nmrObj.pamp_char ( sta_freq, sto_freq, spac_freq, samp_freq ) nmrObj.deassertAll() meas_folder = parse_simple_info( data_parent_folder, 'current_folder.txt' ) # meas_folder[0] = "nmr_wobb_2018_06_25_12_44_48" maxS21, maxS21_freq, _ = compute_gain( nmrObj, data_parent_folder, meas_folder[0], en_fig, fig_num ) print( 'maxS21={0:0.2f} maxS21_freq={1:0.2f}'.format( maxS21, maxS21_freq ) ) dst_pat = ( data_parent_folder + '/' + meas_folder[0] + '/' ) data_parser.write_text_append(dst_pat, 'acqu.par', 'target_freq = {}'.format(target_freq)) data_parser.write_text_append(dst_pat, 'acqu.par', 'Vbias = {}'.format(Vbias)) data_parser.write_text_append(dst_pat, 'acqu.par', 'Vvarac = {}'.format(Vvarac))
def log_param(samples_per_echo, echoes_per_scan, scan_spacing_us, t2_opt, t1_opt, t1t2, snr, folder): write_text_append(folder, 'log_samples_per_echo', str(samples_per_echo)) write_text_append(folder, 'log_echoes_per_scan', str(echoes_per_scan)) write_text_append(folder, 'log_scan_spacing_us', str(scan_spacing_us)) write_text_append(folder, 'log_t2_opt', str(t2_opt)) write_text_append(folder, 'log_t1_opt', str(t1_opt)) write_text_append(folder, 'log_t1t2', str(t1t2)) write_text_append(folder, 'log_snr', str(snr))
t2_opt = tvectArray[max(i_peaks)] # in second # adjust echoes_per_scan according to t2_opt echoes_per_scan = np.round((t2_opt * 1e6 * t2_opt_mult) / echo_spacing_us) t1_opt_echoes_per_scan = echoes_per_scan print('num of echoes: %d' % echoes_per_scan) print('t2Opt: %f' % t2_opt) print('t2OptMult: %f' % t2_opt_mult) plt.semilogx(tvect, dataArray) plt.show() # move the folder to t2t1 measurement folder and write history shutil.move(meas_folder[0], t2t1_meas_folder) write_text_append(t2t1_meas_folder, t2t1_meas_hist, meas_folder[0]) # log the parameters to file log_param(samples_per_echo, echoes_per_scan, scan_spacing_us, t2_opt, t1_opt, t1t2, snr, t2t1_meas_folder) print('----- START T1 OPTIMIZATION -----') en_fig = 0 # cpmg settings scan_spacing_us = t2_opt * 13 * 10.0**6 number_of_iteration = 4 # number of averaging pulse180_t1_us = pulse2_us # sweep parameters logsw = 1 # logsw specifies logsweep, or otherwise linsweep
ax = fig.add_subplot( 1, 1, 1 ) line1, = ax.plot( cpmg_freq_sw[0:i + 1], a_integ_table[0:i + 1], 'b-o' ) # ax.set_ylim(-50, 0) # ax.set_xlabel('Frequency [MHz]') # ax.set_ylabel('S11 [dB]') # ax.set_title("Reflection Measurement (S11) Parameter") ax.grid() fig.canvas.draw() # fig.canvas.flush_events() # turn off system nmrObj.deassertControlSignal( nmrObj.RX1_1H_msk | nmrObj.RX1_1L_msk | nmrObj.RX2_L_msk | nmrObj.RX2_H_msk | nmrObj.RX_SEL1_msk | nmrObj.RX_FL_msk | nmrObj.RX_FH_msk | nmrObj.PAMP_IN_SEL2_msk ) nmrObj.setMatchingNetwork( 0, 0 ) nmrObj.setPreampTuning( 0, 0 ) nmrObj.deassertControlSignal( nmrObj.PSU_15V_TX_P_EN_msk | nmrObj.PSU_15V_TX_N_EN_msk | nmrObj.PSU_5V_TX_N_EN_msk | nmrObj.PSU_5V_ADC_EN_msk | nmrObj.PSU_5V_ANA_P_EN_msk | nmrObj.PSU_5V_ANA_N_EN_msk ) shutil.copy2(data_folder + '/' + meas_folder[0] + '/acqu.par', dst_path) for kk in range( 0, Freq_step ): data_parser.write_text_append(dst_path, 'acqu.par', 'Freq = {}'.format(cpmg_freq_sw[kk])) if en_fig: fig.savefig( dst_path + '/' + datename + '_pulsesw.pdf' ) pass pass