def fit_cos(x, y, **kw): a = kw.pop('a', 0) A = kw.pop('A', 0.8) x0 = kw.pop('x0', 0) T = kw.pop('T', 1000) n = kw.pop('n', 1) f = kw.pop('a', 1 / 200.) phi = kw.pop('a', 0) fixed = kw.pop('fixed', [0, 2, 4]) show_guess = kw.pop('show_guess', False) do_print = kw.pop('do_print', False) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( a, A, x0, T, n, f, phi) if show_guess: ax.plot(np.linspace(0, x[-1], 201), fitfunc(np.linspace(0, x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=do_print, ret=True, fixed=fixed) return fit_result
def fit_cos(x,y,**kw): a = kw.pop('a',0) A = kw.pop('A',0.8) x0 = kw.pop('x0',0) T = kw.pop('T',1000) n = kw.pop('n',1) f = kw.pop('a',1/200.) phi = kw.pop('a',0) fixed=kw.pop('fixed',[0,2,4]) show_guess = kw.pop('show_guess',False) do_print = kw.pop('do_print',False) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos(a,A,x0,T,n,f,phi) if show_guess: ax.plot(np.linspace(0,x[-1],201), fitfunc(np.linspace(0,x[-1],201)), ':', lw=2) fit_result = fit.fit1d(x,y, None, p0=p0, fitfunc=fitfunc, do_print=do_print, ret=True,fixed=fixed) return fit_result
def Carbon_Ramsey(timestamp=None, measurement_name=['adwindata'], ssro_folder=None, frequency=1, offset=0.5, x0=0, amplitude=0.5, decay_constant=0.015, phase=0, exponent=2, plot_fit=False, do_print=False, fixed=[2], show_guess=True, return_phase=False, return_freq=False, return_A=False, return_results=True, close_plot=False, title='Carbon'): ''' ''' folder = toolbox.data_from_time(timestamp) ssro_calib_folder = ssro_folder fit_results = [] a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] y_err = a.u_p0.reshape(-1)[:] ax.plot(x, y) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( offset, amplitude, x0, decay_constant, exponent, frequency, phase) #plot the initial guess if show_guess: ax.plot(np.linspace(x[0], x[-1], 201), fitfunc(np.linspace(x[0], x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True, fixed=fixed) print 'fitfunction: ' + fitfunc_str ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 1001), ax=ax, plot_data=False) fit_results.append(fit_result) if title == None: title = 'analyzed_result' plt.savefig(os.path.join(folder, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder, title + '.png'), format='png') return x, y, y_err, fit_result
def Carbon_Ramsey(timestamp=None, measurement_name = ['adwindata'], ssro_folder =None, frequency = 1, offset = 0.5, x0 = 0, amplitude = 0.5, decay_constant = 0.015, phase =0, exponent = 2, plot_fit = False, do_print = False, fixed = [2], show_guess = True, return_phase = False, return_freq = False, return_A = False, return_results = True, close_plot = False, title = 'Carbon' ): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') offset, amplitude, decay_constant,exponent,frequency ,phase ''' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data(title) if ssro_folder == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_calib_folder = ssro_folder fit_results = [] for k in range(0,len(measurement_name)): a = mbi.MBIAnalysis(folder) print folder a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) # ax = a.plot_results_vs_sweepparam(ret='ax') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] y_err = a.u_p0.reshape(-1)[:] # ax.plot(x,y) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos(offset, amplitude, x0, decay_constant,exponent,frequency ,phase ) #plot the initial guess # if show_guess: # ax.plot(np.linspace(x[0],x[-1],201), fitfunc(np.linspace(x[0],x[-1],201)), ':', lw=2) fit_result = fit.fit1d(x,y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True,fixed=fixed) print 'fitfunction: '+fitfunc_str ## plot data and fit as function of total time # if plot_fit == True: # plot.plot_fit1d(fit_result, np.linspace(x[0],x[-1],1001), ax=ax, plot_data=False) fit_results.append(fit_result) if title == None: title = 'analyzed_result' # plt.savefig(os.path.join(folder, title + '.pdf'), # format='pdf') # plt.savefig(os.path.join(folder, title + '.png'), # format='png') # if close_plot == True: # plt.close() if return_freq == True: f0 = fit_result['params_dict']['f'] u_f0 = fit_result['error_dict']['f'] return f0, u_f0 if return_phase == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] return phi0, u_phi0 if return_phase == True and return_A == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] A = fit_result['params_dict']['A'] u_A = fit_result['error_dict']['A'] return phi0, u_phi0, A, u_A print 'ok' if return_phase == True and return_A == True and return_n == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] A = fit_result['params_dict']['A'] u_A = fit_result['error_dict']['A'] n = fit_result['params_dict']['n'] u_n = fit_result['error_dict']['n'] return phi0, u_phi0, A, u_A print 'ok' # if return_results == True: # return fit_results return x, y, y_err, fit_result
def Carbon_Ramsey_DD_freq(older_than = None, carbon = 1, frequency = 1, offset = 0.5, x0 = 0, amplitude = 0.5, decay_constant = 200, phase =0, exponent = 2, plot_fit = False, do_print = False, fixed = [2], show_guess = True, return_phase = False, return_freq = False, return_results = True, close_plot = False): ''' ''' folder1 = toolbox.latest_data(contains = 'evo_times_1_C' + str(carbon), older_than = older_than) folder2 = toolbox.latest_data(contains = 'evo_times_2_C' + str(carbon), older_than = older_than) folder3 = toolbox.latest_data(contains = 'evo_times_3_C' + str(carbon), older_than = older_than) a1 = mbi.MBIAnalysis(folder1) a1.get_sweep_pts() a1.get_readout_results(name='adwindata') a1.get_electron_ROC() a2 = mbi.MBIAnalysis(folder2) a2.get_sweep_pts() a2.get_readout_results(name='adwindata') a2.get_electron_ROC() a3 = mbi.MBIAnalysis(folder3) a3.get_sweep_pts() a3.get_readout_results(name='adwindata') a3.get_electron_ROC() ''' folder4 = toolbox.latest_data(contains = 'evo_times_4_C' + str(carbon), older_than = older_than) folder5 = toolbox.latest_data(contains = 'evo_times_5_C' + str(carbon), older_than = older_than) folder6 = toolbox.latest_data(contains = 'evo_times_6_C' + str(carbon), older_than = older_than) folder7 = toolbox.latest_data(contains = 'evo_times_7_C' + str(carbon), older_than = older_than) a4 = mbi.MBIAnalysis(folder4) a4.get_sweep_pts() a4.get_readout_results(name='adwindata') a4.get_electron_ROC() a5 = mbi.MBIAnalysis(folder5) a5.get_sweep_pts() a5.get_readout_results(name='adwindata') a5.get_electron_ROC() a6 = mbi.MBIAnalysis(folder6) a6.get_sweep_pts() a6.get_readout_results(name='adwindata') a6.get_electron_ROC() a7 = mbi.MBIAnalysis(folder7) a7.get_sweep_pts() a7.get_readout_results(name='adwindata') a7.get_electron_ROC() a1.p0 = np.r_[a1.p0,a2.p0,a3.p0,a4.p0,a5.p0,a6.p0,a7.p0] a1.u_p0 = np.r_[a1.u_p0,a2.u_p0,a3.u_p0,a4.u_p0,a5.u_p0,a6.u_p0,a7.u_p0] a1.sweep_pts = np.r_[a1.sweep_pts,a2.sweep_pts,a3.sweep_pts,a4.sweep_pts,a5.sweep_pts,a6.sweep_pts,a7.sweep_pts] ''' a1.p0 = np.r_[a1.p0,a2.p0,a3.p0] a1.u_p0 = np.r_[a1.u_p0,a2.u_p0,a3.u_p0] a1.sweep_pts = np.r_[a1.sweep_pts,a2.sweep_pts,a3.sweep_pts] x = a1.sweep_pts.reshape(-1)[:] y = a1.p0.reshape(-1)[:] ax = a1.plot_results_vs_sweepparam(ret='ax') ax.plot(x,y) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos(offset, amplitude, x0, decay_constant,exponent,frequency ,phase ) #plot the initial guess if show_guess: ax.plot(np.linspace(x[0],x[-1],201), fitfunc(np.linspace(x[0],x[-1],201)), ':', lw=2) fit_result = fit.fit1d(x,y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True,fixed=fixed) print 'fitfunction: '+fitfunc_str ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0],x[-1],1001), ax=ax, plot_data=False) title = 'DD freq ramsey C' +str(carbon) plt.savefig(os.path.join(folder1, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder1, title + '.png'), format='png')
def Carbon_Ramsey_Crosstalk(timestamp=None, measurement_name = ['adwindata'], ssro_calib_timestamp =None, frequency = 1, offset = 0.5, x0 = 0, amplitude = 0.5, decay_constant = 200, phase =0, exponent = 2, plot_fit = False, do_print = False, fixed = [2,3,4], show_guess = True, return_phase = False, return_freq = False, return_results = True, return_amp = False, close_plot = False, title = None): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') offset, amplitude, decay_constant,exponent,frequency ,phase ''' if timestamp != None: folder_a = toolbox.data_from_time(timestamp) else: folder_a, timestamp = toolbox.latest_data('Crosstalk', return_timestamp = True) folder_b = toolbox.latest_data('Crosstalk',older_than = timestamp) if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp) ssro_calib_folder = toolbox.datadir + '/'+ssro_dstmp+'/'+ssro_tstmp+'_AdwinSSRO_SSROCalibration_Hans_sil1' print ssro_calib_folder fit_results = [] for k in range(0,len(measurement_name)): a = mbi.MBIAnalysis(folder_a) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') X_RO_data = 2*(a.p0.reshape(-1)[:])-1 X_RO_data_u = 2*(a.u_p0.reshape(-1)[:]) a = mbi.MBIAnalysis(folder_b) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') x = a.sweep_pts.reshape(-1)[:] Y_RO_data = 2*(a.p0.reshape(-1)[:])-1 Y_RO_data_u = 2*(a.u_p0.reshape(-1)[:]) RO_data = (X_RO_data**2 + Y_RO_data**2)**0.5 RO_data_u = (1./(X_RO_data**2 + Y_RO_data**2)*(X_RO_data**2 * X_RO_data_u**2 + Y_RO_data**2 *Y_RO_data_u**2))**0.5 fig = a.default_fig(figsize=(7.5,5)) ax2 = a.default_ax(fig) ax2.axhspan(0,1,fill=False,ls='dotted') ax2.set_ylim(-1,1) ax2.errorbar(x,RO_data,RO_data_u) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos(offset, amplitude, x0, decay_constant,exponent,frequency ,phase ) #plot the initial guess if show_guess: ax2.plot(np.linspace(x[0],x[-1],201), fitfunc(np.linspace(x[0],x[-1],201)), ':', lw=2) fit_result = fit.fit1d(x,RO_data, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True,fixed=fixed) print 'fitfunction: '+fitfunc_str ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0],x[-1],1001), ax=ax2, plot_data=False) fit_results.append(fit_result) if title == None: title = 'analyzed_result' plt.savefig(os.path.join(folder_a, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder_a, title + '.png'), format='png') if close_plot == True: plt.close() if return_freq == True: f0 = fit_result['params_dict']['f'] u_f0 = fit_result['error_dict']['f'] return f0, u_f0 if return_phase == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] Amp = fit_result['params_dict']['A'] if return_amp == True: return phi0, u_phi0, Amp else: return phi0, u_phi0 if return_results == True: return fit_results
def Carbon_Ramsey_mult_msmts(timestamp=None, measurement_name = ['adwindata'], ssro_calib_timestamp =None, frequency = 1, offset = 0.5, x0 = 0, amplitude = 0.5, decay_constant = 200, phase =0, exponent = 2, plot_fit = False, do_print = False, fixed = [2], show_guess = True, return_phase = False, return_freq = False, return_amp = False, return_results = True, close_plot = False, partstr = 'part', contains=[], title = 'Carbon'): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') offset, amplitude, decay_constant,exponent,frequency ,phase ''' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data(title) if partstr in folder: numberstart = folder.find(partstr)+len(partstr) numberofparts = int(folder[numberstart:len(folder)]) basis_str = folder[folder.rfind('\\')+7:numberstart] else: numberofparts = 1 if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp) ssro_calib_folder = toolbox.datadir + '/'+ssro_dstmp+'/'+ssro_tstmp+'_AdwinSSRO_SSROCalibration_111_1_sil18' print ssro_calib_folder fit_results = [] #for kk in range(numberofparts): for kk,cnts in enumerate(contains): ''' if partstr in folder: folder = toolbox.latest_data(basis_str+str(kk+1)) else: folder = toolbox.latest_data(basis_str) ''' folder = toolbox.latest_data(cnts) a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') if kk == 0: cum_sweep_pts = a.sweep_pts cum_p0 = a.p0 cum_u_p0 = a.u_p0 cum_pts = a.pts else: cum_sweep_pts = np.concatenate((cum_sweep_pts, a.sweep_pts)) cum_p0 = np.concatenate((cum_p0, a.p0)) cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0)) cum_pts += a.pts a.pts = cum_pts a.sweep_pts = cum_sweep_pts a.p0 = cum_p0 a.u_p0 = cum_u_p0 sorting_order=a.sweep_pts.argsort() a.sweep_pts.sort() a.p0=a.p0[sorting_order] a.u_p0=a.u_p0[sorting_order] ax=a.plot_results_vs_sweepparam(ret='ax') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] ax.plot(x,y) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos(offset, amplitude, x0, decay_constant,exponent,frequency ,phase ) #plot the initial guess if show_guess: ax.plot(np.linspace(x[0],x[-1],201), fitfunc(np.linspace(x[0],x[-1],201)), ':', lw=2) fit_result = fit.fit1d(x,y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True,fixed=fixed) ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0],x[-1],1001), ax=ax, plot_data=False) fit_results.append(fit_result) if title == None: title = 'analyzed_result' plt.savefig(os.path.join(folder, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder, title + '.png'), format='png') if close_plot == True: plt.close() if return_freq == True: f0 = fit_result['params_dict']['f'] u_f0 = fit_result['error_dict']['f'] return f0, u_f0 if return_phase == True and return_amp == False: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] return phi0, u_phi0 if return_phase == True and return_amp == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] A = fit_result['params_dict']['A'] u_A = fit_result['error_dict']['A'] return phi0, u_phi0, A, u_A if return_results == True: return fit_results
def CosineSum_MBI_data(folder=None, timestamp=[], measurement_name=['adwindata'], ssro_calib_folder=None, ssro_calib_timestamp=None, new_tsmp='20170612_230600', old_tsmp='20170614_071700', two_cos=True, title='Cluster', x_ticks=np.arange(0, 100, 5), y_ticks=np.arange(0.2, 0.8, 0.1), color='b', c=1, t=1, frequency=[1, 1], offset=0.5, amplitude=[0.5, 0.5], phase=[0, 0], fixed=[], plot_fit=False, do_print=False, show_guess=True, xlim1=None, xlim2=None): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: folder: allows to specify specific folder for the data(this overwrites the timestamp input) ssro_folder: allows to specify specific folder for ssro calib(this overwrites the ssro_timestamp input) timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') [freq, offset, Amplitude, phase] ''' timestamp = [] plot_fit = True show_guess = False exponent = 2 #two_cos=True fit_results = [] cum_pts = 0 cum_sweep_pts = np.empty(0) cum_p0 = np.empty(0) cu = np.empty(0) cu_u = np.empty(0) cum_u_p0 = np.empty(0) cum_tau_list = np.empty(0) # new_tsmp = '20170611_165140' ## newer than # old_tsmp = '20170611_235700' ## older than # new_tsmp = '20170612_005040' ## newer than # old_tsmp = '20170612_015800' ## older than # new_tsmp = '20170612_230600' ## newer than # old_tsmp = '20170614_071700' ## older than # new_tsmp = '20170616_190600' ## newer than # old_tsmp = '20170617_053700' ## older than # new_tsmp = '20170621_183900' ## newer than # old_tsmp = '20170621_185800' ## older than # new_tsmp = '20170719_161700' ## newer than # old_tsmp = '20170719_165500' ## older than # new_tsmp = '20170720_171400' ## newer than # old_tsmp = '20170720_181700' ## older than # new_tsmp = '20170720_182900' ## newer than # old_tsmp = '20170720_195700' ## older than search_string = 'Carbon' while toolbox.latest_data(contains=search_string, return_timestamp=True, older_than=old_tsmp, newer_than=new_tsmp, raise_exc=False) != False: old_tsmp, folder = toolbox.latest_data(contains=search_string, return_timestamp=True, older_than=old_tsmp, newer_than=new_tsmp, raise_exc=False) timestamp.append(old_tsmp) timestamp = timestamp[::-1] if ssro_calib_folder == None: if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp( ssro_calib_timestamp) ssro_calib_folder = toolbox.datadir + '/' + ssro_dstmp + '/' + ssro_tstmp + '_AdwinSSRO_SSROCalibration_111_1_sil18' print ssro_calib_folder for kk in range(len(timestamp)): folder = toolbox.data_from_time(timestamp[kk]) a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) cum_pts += a.pts # temperature = (a.g.attrs['temp']-100)/0.385 # temperature_list.append(temperature) if kk == 0: cum_sweep_pts = a.sweep_pts cum_p0 = a.p0 cum_u_p0 = a.u_p0 #cum_tau_list = a.tau_list #elif kk in [5,10,15,21,26,31]: else: cum_sweep_pts = np.concatenate((cum_sweep_pts, a.sweep_pts)) cum_p0 = np.concatenate((cum_p0, a.p0)) cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0)) #cum_tau_list = np.concatenate((cum_tau_list, a.tau_list)) a.pts = cum_pts a.sweep_pts = 1.0e3 * cum_sweep_pts a.p0 = cum_p0 a.u_p0 = cum_u_p0 #ax = a.plot_results_vs_sweepparam(ret='ax',fmt='o',color='brown',figsize=(46,12)) e = a.u_p0 x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] # fig = plt.figure(1,figsize=(10,2)) # ax2 = fig.add_subplot(111) # ax2.set_xlabel('Free evolution time (ms)') # ax2.set_ylabel('State Fidelity') #f = plt.figure(1,figsize=(60,2)) #f,(ax1,ax2,ax3,ax4) = plt.subplots(1,4,sharey=True, facecolor='w',figsize=(10,3.5)) fig = plt.figure(figsize=(9, 3.3)) gs = gridspec.GridSpec(1, 4, width_ratios=[3, 3, 2, 1]) ax1 = plt.subplot(gs[0]) ax2 = plt.subplot(gs[1]) ax3 = plt.subplot(gs[2]) ax4 = plt.subplot(gs[3]) ax1.errorbar(x.flatten(), y.flatten(), yerr=e, fmt='o', label='', color=color, lw=1, markersize=3) ax2.errorbar(x.flatten(), y.flatten(), yerr=e, fmt='o', label='', color=color, lw=1, markersize=3) ax3.errorbar(x.flatten(), y.flatten(), yerr=e, fmt='o', label='', color=color, lw=1, markersize=3) ax4.errorbar(x.flatten(), y.flatten(), yerr=e, fmt='o', label='', color=color, lw=1, markersize=3) fit_result = [None] #p0, fitfunc, fitfunc_str = common.fit_sum_2cos(offset,amplitude[0],frequency[0],phase[0],amplitude[1],frequency[1],phase[1]) if two_cos == True: p0, fitfunc, fitfunc_str = common.fit_gaussian_decaying_2cos( offset, c, t, amplitude[0], frequency[0], phase[0], amplitude[1], frequency[1], phase[1]) else: p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( offset, amplitude[0], 0, t, exponent, frequency[0], phase[0]) if show_guess: ax1.plot(np.linspace(x[0], x[-1], 201), fitfunc(np.linspace(x[0], x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=do_print, ret=True, fixed=fixed) if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 8001), ax=ax1, color=color, plot_data=False, print_info=False, lw=1.5) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 8001), ax=ax2, color=color, plot_data=False, print_info=False, lw=1.5) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 8001), ax=ax3, color=color, plot_data=False, print_info=False, lw=1.5) plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 8001), ax=ax4, color=color, plot_data=False, print_info=False, lw=1.5) fit.write_to_file(fit_result, folder, fitname='Sum of cosine fit') ## plot data and fit as function of total time #plt.xticks(x_ticks) # plt.yticks(np.arange(min(y),(max(y)),0.1)) #plt.yticks(y_ticks) ax1.set_xlim(0, 31) ax2.set_xlim(xlim1, xlim2) ax3.set_xlim(609, 631) ax4.set_xlim(910, 920) #ax2.set_ylim(0,1) #ax2.set_xlabel('Free evolution time (ms)') #ax2.set_ylabel('State Fidelity') d = .045 # how big to make the diagonal lines in axes coordinates # arguments to pass plot, just so we don't keep repeating them ax1.spines['right'].set_visible(False) ax2.spines['left'].set_visible(False) ax2.spines['right'].set_visible(False) ax3.spines['left'].set_visible(False) ax3.spines['right'].set_visible(False) ax1.yaxis.tick_left() ax1.tick_params(labelright='off') ax2.tick_params(labelleft='off') ax2.tick_params(labelright='off') ax3.tick_params(labelleft='off') ax3.tick_params(labelright='off') ax4.tick_params(labelleft='off') ax4.tick_params(labelright='off') #ax4.tick_params(labelbottom='off') #ax1.tick_params(labelbottom='off') #ax2.tick_params(labelbottom='off') #ax3.tick_params(labelbottom='off') ax4.spines['left'].set_visible(False) plt.sca(ax1) plt.xticks([10, 20, 30]) plt.yticks([0.4, 0.5, 0.6, 0.7]) plt.sca(ax2) plt.xticks([200, 210, 220, 230]) plt.yticks([]) plt.sca(ax3) plt.xticks([610, 620, 630]) plt.yticks([]) plt.sca(ax4) plt.xticks([910, 920]) plt.yticks([]) #plt.step(ax1,ax2,xticks=[10,20,30],yticks=[0.4,0.5,0.6,0.7]) #ax4.yaxis.tick_right() #ax4.xaxis.tick_bottom() # kwargs = dict(transform=ax1.transAxes, color='k', clip_on=False) # ax1.plot((1-d,1+d), (-d,+d), **kwargs) # ax1.plot((1-d,1+d),(1-d,1+d), **kwargs) # kwargs.update(transform=ax2.transAxes) # switch to the bottom axes # ax2.plot((-d,+d), (1-d,1+d), **kwargs) # ax2.plot((-d,+d), (-d,+d), **kwargs) # ax2.plot((1-d,1+d), (-d,+d), **kwargs) # ax2.plot((1-d,1+d),(1-d,1+d), **kwargs) # kwargs = dict(transform=ax3.transAxes, color='k', clip_on=False) # ax3.plot((-d,+d), (1-d,1+d), **kwargs) # ax3.plot((-d,+d), (-d,+d), **kwargs) # ax3.plot((1-d,1+d), (-d,+d), **kwargs) # ax3.plot((1-d,1+d),(1-d,1+d), **kwargs) # kwargs.update(transform=ax4.transAxes) # switch to the bottom axes # ax4.plot((-d,+d), (1-d,1+d), **kwargs) # ax4.plot((-d,+d), (-d,+d), **kwargs) folder = 'C:\Users\TUD277931\Dropbox\TaminiauLab\Projects\Coherence in multi-qubit systems\Paper\Figures' plt.savefig(os.path.join(folder, title + '.pdf'), format='pdf', bbox_inches='tight', pad_inches=0.2, transparent=True)
def Carbon_Ramsey(timestamp=None, measurement_name=['adwindata'], ssro_folder=None, frequency=1, offset=0.5, x0=0, amplitude=0.5, decay_constant=200, phase=0, exponent=2, plot_fit=False, do_print=False, fixed=[2], show_guess=True, return_phase=False, return_freq=False, return_A=False, return_results=True, close_plot=False, title='Carbon'): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') offset, amplitude, decay_constant,exponent,frequency ,phase ''' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data(title) if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_calib_folder = ssro_folder fit_results = [] for k in range(0, len(measurement_name)): a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] y_err = u_p0(-1)[:] ax.plot(x, y) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( offset, amplitude, x0, decay_constant, exponent, frequency, phase) #plot the initial guess if show_guess: ax.plot(np.linspace(x[0], x[-1], 201), fitfunc(np.linspace(x[0], x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True, fixed=fixed) print 'fitfunction: ' + fitfunc_str ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 1001), ax=ax, plot_data=False) fit_results.append(fit_result) if title == None: title = 'analyzed_result' plt.savefig(os.path.join(folder, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder, title + '.png'), format='png') if close_plot == True: plt.close() if return_freq == True: f0 = fit_result['params_dict']['f'] u_f0 = fit_result['error_dict']['f'] return f0, u_f0 if return_phase == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] return phi0, u_phi0 if return_phase == True and return_A == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] A = fit_result['params_dict']['A'] u_A = fit_result['error_dict']['A'] return phi0, u_phi0, A, u_A print 'ok' if return_results == True: return fit_results return x, y, y_err, fit_results
def CosineSum_MBI_data(folder=None, timestamp=[], measurement_name=['adwindata'], ssro_calib_folder=None, ssro_calib_timestamp=None, new_tsmp='20170612_230600', old_tsmp='20170614_071700', two_cos=True, title='Cluster', x_ticks=np.arange(0, 100, 5), y_ticks=np.arange(0.2, 0.8, 0.1), color='b', c=1, t=1, frequency=[1, 1], offset=0.5, amplitude=[0.5, 0.5], phase=[0, 0], fixed=[], plot_fit=False, do_print=False, show_guess=True, xlim=None): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: folder: allows to specify specific folder for the data(this overwrites the timestamp input) ssro_folder: allows to specify specific folder for ssro calib(this overwrites the ssro_timestamp input) timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') [freq, offset, Amplitude, phase] ''' timestamp = [] plot_fit = True show_guess = False exponent = 2 #two_cos=True fit_results = [] cum_pts = 0 cum_sweep_pts = np.empty(0) cum_p0 = np.empty(0) cu = np.empty(0) cu_u = np.empty(0) cum_u_p0 = np.empty(0) cum_tau_list = np.empty(0) # new_tsmp = '20170611_165140' ## newer than # old_tsmp = '20170611_235700' ## older than # new_tsmp = '20170612_005040' ## newer than # old_tsmp = '20170612_015800' ## older than # new_tsmp = '20170612_230600' ## newer than # old_tsmp = '20170614_071700' ## older than # new_tsmp = '20170616_190600' ## newer than # old_tsmp = '20170617_053700' ## older than # new_tsmp = '20170621_183900' ## newer than # old_tsmp = '20170621_185800' ## older than # new_tsmp = '20170719_161700' ## newer than # old_tsmp = '20170719_165500' ## older than # new_tsmp = '20170720_171400' ## newer than # old_tsmp = '20170720_181700' ## older than # new_tsmp = '20170720_182900' ## newer than # old_tsmp = '20170720_195700' ## older than search_string = 'Carbon' while toolbox.latest_data(contains=search_string, return_timestamp=True, older_than=old_tsmp, newer_than=new_tsmp, raise_exc=False) != False: old_tsmp, folder = toolbox.latest_data(contains=search_string, return_timestamp=True, older_than=old_tsmp, newer_than=new_tsmp, raise_exc=False) timestamp.append(old_tsmp) timestamp = timestamp[::-1] if ssro_calib_folder == None: if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp( ssro_calib_timestamp) ssro_calib_folder = toolbox.datadir + '/' + ssro_dstmp + '/' + ssro_tstmp + '_AdwinSSRO_SSROCalibration_111_1_sil18' print ssro_calib_folder for kk in range(len(timestamp)): folder = toolbox.data_from_time(timestamp[kk]) a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) cum_pts += a.pts # temperature = (a.g.attrs['temp']-100)/0.385 # temperature_list.append(temperature) if kk == 0: cum_sweep_pts = a.sweep_pts cum_p0 = a.p0 cum_u_p0 = a.u_p0 #cum_tau_list = a.tau_list #elif kk in [5,10,15,21,26,31]: else: cum_sweep_pts = np.concatenate((cum_sweep_pts, a.sweep_pts)) cum_p0 = np.concatenate((cum_p0, a.p0)) cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0)) #cum_tau_list = np.concatenate((cum_tau_list, a.tau_list)) a.pts = cum_pts a.sweep_pts = 1.0e3 * cum_sweep_pts a.p0 = cum_p0 a.u_p0 = cum_u_p0 #ax = a.plot_results_vs_sweepparam(ret='ax',fmt='o',color='brown',figsize=(46,12)) e = a.u_p0 x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] fig = plt.figure(1, figsize=(4, 1.5)) ax2 = fig.add_subplot(111) ax2.errorbar(x.flatten(), y.flatten(), yerr=e, fmt='o', label='', color=color, lw=1, markersize=3) ax2.set_xlabel('Free evolution time (ms)') ax2.set_ylabel('State Fidelity') fit_result = [None] #p0, fitfunc, fitfunc_str = common.fit_sum_2cos(offset,amplitude[0],frequency[0],phase[0],amplitude[1],frequency[1],phase[1]) if two_cos == True: p0, fitfunc, fitfunc_str = common.fit_gaussian_decaying_2cos( offset, c, t, amplitude[0], frequency[0], phase[0], amplitude[1], frequency[1], phase[1]) else: p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( offset, amplitude[0], 0, t, exponent, frequency[0], phase[0]) if show_guess: ax.plot(np.linspace(x[0], x[-1], 201), fitfunc(np.linspace(x[0], x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=do_print, ret=True, fixed=fixed) if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 8001), ax=ax2, color=color, plot_data=False, print_info=False, lw=1.5) fit.write_to_file(fit_result, folder, fitname='Sum of cosine fit') ## plot data and fit as function of total time plt.xticks(x_ticks) # plt.yticks(np.arange(min(y),(max(y)),0.1)) plt.yticks(y_ticks) ax2.set_xlim(0, xlim) #ax2.set_ylim(0,1) #ax2.set_xlabel('Free evolution time (ms)') #ax2.set_ylabel('State Fidelity') folder = 'C:\Users\TUD277931\Dropbox\TaminiauLab\Projects\Coherence in multi-qubit systems\Paper\Figures\Fig 3' plt.savefig(os.path.join(folder, title + '.pdf'), format='pdf', bbox_inches='tight', pad_inches=0.2, transparent=True)
def Carbon_Ramsey(timestamp=None, carbon=None, transition=None, measurement_name = ['adwindata'], ssro_calib_timestamp =None, frequency = 1, offset = 0.5, x0 = 0, amplitude = 0.5, decay_constant = 200, phase =0, exponent = 2, plot_fit = False, do_print = False, fixed = [2], show_guess = True, return_phase = False, return_freq = False, return_amp = False, return_results = True, close_plot = False, color='b', title = 'Carbon', x_ticks=np.arange(0,100,5), y_ticks=np.arange(0.2,0.8,0.1)): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') offset, amplitude, decay_constant,exponent,frequency ,phase ''' if timestamp != None: folder = toolbox.data_from_time(timestamp) elif carbon != None: folder = toolbox.latest_data(contains='C'+str(carbon)+'_ms'+str(transition)) else: folder = toolbox.latest_data(title) print folder if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSROCalibration') else: ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp) ssro_calib_folder = toolbox.datadir + '/'+ssro_dstmp+'/'+ssro_tstmp+'_AdwinSSRO_SSROCalibration_111_1_sil18' print ssro_calib_folder fit_results = [] for k in range(0,len(measurement_name)): a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) x = 1.0e3*a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] e= a.u_p0 # fig = plt.figure(1,figsize=(4,1.5)) fig = plt.figure(1,figsize=(8,3)) ax2 = fig.add_subplot(111) ax2.errorbar(x.flatten(),y.flatten(),yerr=e,fmt='o',label='',color=color,markersize=4,lw=1) ax2.set_xlabel('Free evolution time (ms)') ax2.set_ylabel('State Fidelity') print min(y) print max(y) #plt.xticks(x_ticks) # plt.yticks(np.arange(min(y),(max(y)),0.1)) #plt.yticks(y_ticks) #ax2.set_ylim(min(y)-0.03,max(y)+0.07) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos(offset, amplitude, x0, decay_constant,exponent,frequency ,phase ) #plot the initial guess if show_guess: ax2.plot(np.linspace(x[0],x[-1],201), fitfunc(np.linspace(x[0],x[-1],201)), ':', lw=2) fit_result = fit.fit1d(x,y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True,fixed=fixed) print 'fitfunction: '+fitfunc_str ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0],x[-1],1001), ax=ax2, add_txt = False, color=color, plot_data=False,lw=1.5) fit_results.append(fit_result) if title == None: title = 'analyzed_result' folder='C:\Users\TUD277931\Dropbox\TaminiauLab\Projects\Coherence in multi-qubit systems\Paper\Figures\Fig 3' plt.savefig(os.path.join(folder, title + '.pdf'), format='pdf',bbox_inches='tight',pad_inches=0.2,transparent=True) if close_plot == True: plt.close() # plt.savefig('C:\Users\TUD277931\Dropbox\TaminiauLab\Projects\Coherence in multi-qubit systems\Paper\Figures\Fig 1\T1_sum_log.pdf', # format='pdf',bbox_inches='tight',pad_inches=0.2,transparent=True) # for item in fit_result['params_dict']: # print item # return fit_result #print folder if return_freq == True: f0 = fit_result['params_dict']['f'] u_f0 = fit_result['error_dict']['f'] return f0, u_f0 if return_phase == True and return_amp == False: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] return phi0, u_phi0 if return_phase == True and return_amp == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] A = fit_result['params_dict']['A'] u_A = fit_result['error_dict']['A'] return phi0, u_phi0, A, u_A if return_amp == True: A = fit_result['params_dict']['A'] u_A = fit_result['error_dict']['A'] return A, u_A if return_results == True: return fit_results
def Carbon_Ramsey_DD_freq(older_than=None, transition=None, carbon=1, frequency=1, offset=0.5, x0=0, amplitude=0.5, decay_constant=200, phase=0, exponent=2, plot_fit=False, do_print=False, fixed=[2], show_guess=True, return_phase=False, return_freq=True, return_results=True, close_plot=False): ''' ''' if transition != None: folder1 = toolbox.latest_data(contains='evo_times_1_C' + str(carbon) + str(transition), older_than=older_than) folder2 = toolbox.latest_data(contains='evo_times_2_C' + str(carbon) + str(transition), older_than=older_than) folder3 = toolbox.latest_data(contains='evo_times_3_C' + str(carbon) + str(transition), older_than=older_than) else: folder1 = toolbox.latest_data(contains='evo_times_1_C' + str(carbon), older_than=older_than) folder2 = toolbox.latest_data(contains='evo_times_2_C' + str(carbon), older_than=older_than) folder3 = toolbox.latest_data(contains='evo_times_3_C' + str(carbon), older_than=older_than) a1 = mbi.MBIAnalysis(folder1) a1.get_sweep_pts() a1.get_readout_results(name='adwindata') a1.get_electron_ROC() a2 = mbi.MBIAnalysis(folder2) a2.get_sweep_pts() a2.get_readout_results(name='adwindata') a2.get_electron_ROC() a3 = mbi.MBIAnalysis(folder3) a3.get_sweep_pts() a3.get_readout_results(name='adwindata') a3.get_electron_ROC() ''' folder4 = toolbox.latest_data(contains = 'evo_times_4_C' + str(carbon), older_than = older_than) folder5 = toolbox.latest_data(contains = 'evo_times_5_C' + str(carbon), older_than = older_than) folder6 = toolbox.latest_data(contains = 'evo_times_6_C' + str(carbon), older_than = older_than) folder7 = toolbox.latest_data(contains = 'evo_times_7_C' + str(carbon), older_than = older_than) a4 = mbi.MBIAnalysis(folder4) a4.get_sweep_pts() a4.get_readout_results(name='adwindata') a4.get_electron_ROC() a5 = mbi.MBIAnalysis(folder5) a5.get_sweep_pts() a5.get_readout_results(name='adwindata') a5.get_electron_ROC() a6 = mbi.MBIAnalysis(folder6) a6.get_sweep_pts() a6.get_readout_results(name='adwindata') a6.get_electron_ROC() a7 = mbi.MBIAnalysis(folder7) a7.get_sweep_pts() a7.get_readout_results(name='adwindata') a7.get_electron_ROC() a1.p0 = np.r_[a1.p0,a2.p0,a3.p0,a4.p0,a5.p0,a6.p0,a7.p0] a1.u_p0 = np.r_[a1.u_p0,a2.u_p0,a3.u_p0,a4.u_p0,a5.u_p0,a6.u_p0,a7.u_p0] a1.sweep_pts = np.r_[a1.sweep_pts,a2.sweep_pts,a3.sweep_pts,a4.sweep_pts,a5.sweep_pts,a6.sweep_pts,a7.sweep_pts] ''' a1.p0 = np.r_[a1.p0, a2.p0, a3.p0] a1.u_p0 = np.r_[a1.u_p0, a2.u_p0, a3.u_p0] a1.sweep_pts = np.r_[a1.sweep_pts, a2.sweep_pts, a3.sweep_pts] x = a1.sweep_pts.reshape(-1)[:] y = a1.p0.reshape(-1)[:] ax = a1.plot_results_vs_sweepparam(ret='ax') ax.plot(x, y) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( offset, amplitude, x0, decay_constant, exponent, frequency, phase) #plot the initial guess if show_guess: ax.plot(np.linspace(x[0], x[-1], 201), fitfunc(np.linspace(x[0], x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True, fixed=fixed) print 'fitfunction: ' + fitfunc_str ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 1001), ax=ax, plot_data=False) title = 'DD freq ramsey C' + str(carbon) print folder1 plt.savefig(os.path.join(folder1, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder1, title + '.png'), format='png')
def Carbon_Ramsey_Crosstalk(timestamp=None, measurement_name=['adwindata'], ssro_calib_timestamp=None, frequency=1, offset=0.5, x0=0, amplitude=0.5, decay_constant=200, phase=0, exponent=2, plot_fit=False, do_print=False, fixed=[2, 3, 4], show_guess=True, return_phase=False, return_freq=False, return_results=True, return_amp=False, close_plot=False, title=None): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') offset, amplitude, decay_constant,exponent,frequency ,phase ''' if timestamp != None: folder_a = toolbox.data_from_time(timestamp) else: folder_a, timestamp = toolbox.latest_data('Crosstalk', return_timestamp=True) folder_b = toolbox.latest_data('Crosstalk', older_than=timestamp) if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp) ssro_calib_folder = toolbox.datadir + '/' + ssro_dstmp + '/' + ssro_tstmp + '_AdwinSSRO_SSROCalibration_Hans_sil1' print ssro_calib_folder fit_results = [] for k in range(0, len(measurement_name)): a = mbi.MBIAnalysis(folder_a) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') X_RO_data = 2 * (a.p0.reshape(-1)[:]) - 1 X_RO_data_u = 2 * (a.u_p0.reshape(-1)[:]) a = mbi.MBIAnalysis(folder_b) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') x = a.sweep_pts.reshape(-1)[:] Y_RO_data = 2 * (a.p0.reshape(-1)[:]) - 1 Y_RO_data_u = 2 * (a.u_p0.reshape(-1)[:]) RO_data = (X_RO_data**2 + Y_RO_data**2)**0.5 RO_data_u = (1. / (X_RO_data**2 + Y_RO_data**2) * (X_RO_data**2 * X_RO_data_u**2 + Y_RO_data**2 * Y_RO_data_u**2))**0.5 fig = a.default_fig(figsize=(7.5, 5)) ax2 = a.default_ax(fig) ax2.axhspan(0, 1, fill=False, ls='dotted') ax2.set_ylim(-1, 1) ax2.errorbar(x, RO_data, RO_data_u) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( offset, amplitude, x0, decay_constant, exponent, frequency, phase) #plot the initial guess if show_guess: ax2.plot(np.linspace(x[0], x[-1], 201), fitfunc(np.linspace(x[0], x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, RO_data, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True, fixed=fixed) print 'fitfunction: ' + fitfunc_str ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 1001), ax=ax2, plot_data=False) fit_results.append(fit_result) if title == None: title = 'analyzed_result' plt.savefig(os.path.join(folder_a, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder_a, title + '.png'), format='png') if close_plot == True: plt.close() if return_freq == True: f0 = fit_result['params_dict']['f'] u_f0 = fit_result['error_dict']['f'] return f0, u_f0 if return_phase == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] Amp = fit_result['params_dict']['A'] if return_amp == True: return phi0, u_phi0, Amp else: return phi0, u_phi0 if return_results == True: return fit_results
def Carbon_Ramsey_mult_msmts(timestamp=None, measurement_name=['adwindata'], ssro_calib_timestamp=None, frequency=1, offset=0.5, x0=0, amplitude=0.5, decay_constant=200, phase=0, exponent=2, plot_fit=False, do_print=False, fixed=[2], show_guess=True, return_phase=False, return_freq=False, return_amp=False, return_results=True, close_plot=False, partstr='part', contains=[], title='Carbon'): ''' Function to analyze simple decoupling measurements. Loads the results and fits them to a simple exponential. Inputs: timestamp: in format yyyymmdd_hhmmss or hhmmss or None. measurement_name: list of measurement names List of parameters (order important for 'fixed') offset, amplitude, decay_constant,exponent,frequency ,phase ''' if timestamp != None: folder = toolbox.data_from_time(timestamp) else: folder = toolbox.latest_data(title) if partstr in folder: numberstart = folder.find(partstr) + len(partstr) numberofparts = int(folder[numberstart:len(folder)]) basis_str = folder[folder.rfind('\\') + 7:numberstart] else: numberofparts = 1 if ssro_calib_timestamp == None: ssro_calib_folder = toolbox.latest_data('SSRO') else: ssro_dstmp, ssro_tstmp = toolbox.verify_timestamp(ssro_calib_timestamp) ssro_calib_folder = toolbox.datadir + '/' + ssro_dstmp + '/' + ssro_tstmp + '_AdwinSSRO_SSROCalibration_111_1_sil18' print ssro_calib_folder fit_results = [] #for kk in range(numberofparts): for kk, cnts in enumerate(contains): ''' if partstr in folder: folder = toolbox.latest_data(basis_str+str(kk+1)) else: folder = toolbox.latest_data(basis_str) ''' folder = toolbox.latest_data(cnts) a = mbi.MBIAnalysis(folder) a.get_sweep_pts() a.get_readout_results(name='adwindata') a.get_electron_ROC(ssro_calib_folder) ax = a.plot_results_vs_sweepparam(ret='ax') if kk == 0: cum_sweep_pts = a.sweep_pts cum_p0 = a.p0 cum_u_p0 = a.u_p0 cum_pts = a.pts else: cum_sweep_pts = np.concatenate((cum_sweep_pts, a.sweep_pts)) cum_p0 = np.concatenate((cum_p0, a.p0)) cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0)) cum_pts += a.pts a.pts = cum_pts a.sweep_pts = cum_sweep_pts a.p0 = cum_p0 a.u_p0 = cum_u_p0 sorting_order = a.sweep_pts.argsort() a.sweep_pts.sort() a.p0 = a.p0[sorting_order] a.u_p0 = a.u_p0[sorting_order] ax = a.plot_results_vs_sweepparam(ret='ax') x = a.sweep_pts.reshape(-1)[:] y = a.p0.reshape(-1)[:] ax.plot(x, y) p0, fitfunc, fitfunc_str = common.fit_general_exponential_dec_cos( offset, amplitude, x0, decay_constant, exponent, frequency, phase) #plot the initial guess if show_guess: ax.plot(np.linspace(x[0], x[-1], 201), fitfunc(np.linspace(x[0], x[-1], 201)), ':', lw=2) fit_result = fit.fit1d(x, y, None, p0=p0, fitfunc=fitfunc, do_print=True, ret=True, fixed=fixed) ## plot data and fit as function of total time if plot_fit == True: plot.plot_fit1d(fit_result, np.linspace(x[0], x[-1], 1001), ax=ax, plot_data=False) fit_results.append(fit_result) if title == None: title = 'analyzed_result' plt.savefig(os.path.join(folder, title + '.pdf'), format='pdf') plt.savefig(os.path.join(folder, title + '.png'), format='png') if close_plot == True: plt.close() if return_freq == True: f0 = fit_result['params_dict']['f'] u_f0 = fit_result['error_dict']['f'] return f0, u_f0 if return_phase == True and return_amp == False: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] return phi0, u_phi0 if return_phase == True and return_amp == True: phi0 = fit_result['params_dict']['phi'] u_phi0 = fit_result['error_dict']['phi'] A = fit_result['params_dict']['A'] u_A = fit_result['error_dict']['A'] return phi0, u_phi0, A, u_A if return_results == True: return fit_results