def plot_sim_vs_Bx(spin_list=['C1'],Bx_list = [0],B_Field = 12, N =2,xlim=[0,100]): for ii in range(len(spin_list)): for b in range(len(Bx_list)): Bx = Bx_list[b] #print spin_list[ii] HF_par=[hf[spin_list[ii]]['par'] - hf[spin_list[ii]]['perp']*Bx/B_Field] HF_perp=[hf[spin_list[ii]]['perp'] + hf[spin_list[ii]]['par']*Bx/B_Field] tau_lst = np.linspace(xlim[0]*1e-6,xlim[1]*1e-6,960) tau_lst_us = np.linspace(xlim[0],xlim[1],960) if ii == 0: Mt = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,N,tau_lst) else: Mt=Mt*SC.dyn_dec_signal(HF_par,HF_perp,B_Field,N,tau_lst) #if ii == 0: FP_signal = ((Mt+1)/2) #else: # FP_signal = FP_signal*((Mt+1)/2) #ax.plot(tau_lst*1e6, FP_signal[0,:],'.-',lw=.8,label = 'spin_'+spin_list[ii]+'_Bx_'+str(Bx)) return FP_signal[0,:],tau_lst_us
def plot_sim_vs_Bx(spin_list=['C1'],Bx_list = [-0.7,0,0.7],B_Field = 304.12, N =32): for ii in range(len(spin_list)): print spin_list fig = figure(ii+1,figsize=(10,5)) ax = fig.add_subplot(111) # ax.title('Vary Bx for Spin '+ spin_list[ii]) start, end = ax.get_xlim() # ax.xaxis.set_ticks(np.arange(start, end, 0.1)) for b in range(len(Bx_list)): Bx = Bx_list[b] print spin_list[ii] HF_par = [10e3]#[hf[spin_list[ii]]['par'] - hf[spin_list[ii]]['perp']*Bx/B_Field] HF_perp = [100e3]#[hf[spin_list[ii]]['perp'] + hf[spin_list[ii]]['par']*Bx/B_Field] print Bx/B_Field print hf[spin_list[ii]]['par'] print hf[spin_list[ii]]['perp'] print HF_par print HF_perp tau_lst = np.linspace(10.e-6,24.5e-6,5000) Mt = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,N,tau_lst) FP_signal = ((Mt+1)/2) ax.plot(tau_lst*1e6, FP_signal[0,:],'-',lw=.8,label = 'spin_'+spin_list[ii]+'_Bx_'+str(Bx)) ax.set_xlabel('tau (us)') plt.legend(loc=4)
def fingerprint(disp_sim_spin = True,n_sim_spins = 13,xrange = [0,20],): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_par = [hf['C1']['par'],hf['C2']['par'],hf['C3']['par'], hf['C4']['par'], hf['C5']['par'], hf['C6']['par'], hf['C7']['par'], hf['C8']['par'], hf['C9']['par'], hf['C10']['par'], hf['C11']['par'], hf['C12']['par']] HF_perp = [hf['C1']['perp'],hf['C2']['perp'],hf['C3']['perp'], hf['C4']['perp'], hf['C5']['perp'], hf['C6']['perp'], hf['C7']['perp'], hf['C8']['perp'], hf['C9']['perp'], hf['C10']['perp'], hf['C11']['perp'], hf['C12']['perp']] #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 304.12 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,16,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## timestamp ='20140419_005744' if os.name =='posix': ssro_calib_folder = '//Users//Adriaan//Documents//teamdiamond//data//20140419//111949_AdwinSSRO_SSROCalibration_Hans_sil1' else: ssro_calib_folder = 'd:\\measuring\\data\\20140419\\111949_AdwinSSRO_SSROCalibration_Hans_sil1' a, folder = load_mult_dat(timestamp, number_of_msmts = 140, ssro_calib_folder=ssro_calib_folder) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35,5)) ax = a.default_ax(fig) # ax.set_xlim(15.0,15.5) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(start, end, 0.5)) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1))#, color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') plt.legend(loc=4) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.png'), format='png')
def fingerprint(disp_sim_spin = True,n_sim_spins = 2,xrange = [0,20],return_data = False): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'min') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,32,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## timestamp ='20141016_205842' ssro_calib_folder = 'D:\\measuring\\data\\20141016\\150451_AdwinSSRO_SSROCalibration_111_1_sil18' a, folder = load_mult_dat(timestamp, number_of_msmts = 40, ssro_calib_folder=ssro_calib_folder) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35,5)) ax = a.default_ax(fig) ax.set_xlim(4.9,5.1) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(xrange[0], xrange[1], (xrange[1]- xrange[0])/10.)) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') plt.legend(loc=4) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.png'), format='png') if return_data == True: return a.sweep_pts, a.p0
def fingerprint(disp_sim_spin = True): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_par = [hf['C1']['par'],hf['C2']['par'],hf['C3']['par'], hf['C4']['par'], hf['C5']['par'], hf['C6']['par'], hf['C7']['par'], hf['C8']['par'], hf['C9']['par'], hf['C10']['par'], hf['C11']['par'], hf['C12']['par']] HF_perp = [hf['C1']['perp'],hf['C2']['perp'],hf['C3']['perp'], hf['C4']['perp'], hf['C5']['perp'], hf['C6']['perp'], hf['C7']['perp'], hf['C8']['perp'], hf['C9']['perp'], hf['C10']['perp'], hf['C11']['perp'], hf['C12']['perp']] #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 304.12 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,64,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## timestamps = ['20140417_194335', '20140419_140807'] ssro_calib_folders = ['d:\\measuring\\data\\20140419\\111949_AdwinSSRO_SSROCalibration_Hans_sil1', 'd:\\measuring\\data\\20140419\\123556_AdwinSSRO_SSROCalibration_Hans_sil1'] a, folder = load_mult_dat(timestamps, number_of_msmts = [150, 100], ssro_calib_folders=ssro_calib_folders) ########### # Plotting ### ########### fig = a.default_fig(figsize=(35,5)) ax = a.default_ax(fig) # ax.set_xlim(15.0,15.5) ax.set_xlim(0,20) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(start, end, 0.5)) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, len(HF_par))) for tt in range(len(HF_par)): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(len(HF_par)): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') plt.legend(loc=4) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_short.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_short.png'), format='png')
def fingerprint(disp_sim_spin = True): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_par = [hf['C1']['par'],hf['C2']['par'],hf['C3']['par'], hf['C4']['par'], hf['C5']['par'], hf['C6']['par'], hf['C7']['par'], hf['C8']['par'], hf['C9']['par'], hf['C10']['par'], hf['C11']['par'], hf['C12']['par']] HF_perp = [hf['C1']['perp'],hf['C2']['perp'],hf['C3']['perp'], hf['C4']['perp'], hf['C5']['perp'], hf['C6']['perp'], hf['C7']['perp'], hf['C8']['perp'], hf['C9']['perp'], hf['C10']['perp'], hf['C11']['perp'], hf['C12']['perp']] #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 304.12 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,64,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## timestamps = ['20160108_004236', '20160108_004236'] ssro_calib_folders = ['d:\\measuring\\data\\20160107\\172632_AdwinSSRO_SSROCalibration_Pippin_SIL1', 'd:\\measuring\\data\\20160107\\172632_AdwinSSRO_SSROCalibration_Pippin_SIL1'] a, folder = load_mult_dat(timestamps, number_of_msmts = [100, 100], ssro_calib_folders=ssro_calib_folders) ########### # Plotting ### ########### fig = a.default_fig(figsize=(35,5)) ax = a.default_ax(fig) # ax.set_xlim(15.0,15.5) ax.set_xlim(0,20) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(start, end, 0.5)) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, len(HF_par))) for tt in range(len(HF_par)): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(len(HF_par)): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') plt.legend(loc=4) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_short.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_short.png'), format='png')
def fingerprint(disp_sim_spin = True,n_sim_spins = 8,xrange = [0,20]): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'min') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,64,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## timestamp ='20141016_234534' ssro_calib_folder = 'D:\\measuring\\data\\20141016\\150451_AdwinSSRO_SSROCalibration_111_1_sil18' a, folder = load_mult_dat(timestamp, number_of_msmts = 50, ssro_calib_folder=ssro_calib_folder) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35,5)) ax = a.default_ax(fig) # ax.set_xlim(15.0,15.5) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(xrange[0], xrange[1], (xrange[1]- xrange[0])/10)) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') plt.legend(loc=4) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.png'), format='png')
def fingerprint_single(disp_sim_spin=True, n_sim_spins=2, xrange=[0, 20], tag='', step_size=10e-3, older_than=None, return_data=False): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms='min') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0, 72e-6, 10000) Mt16 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 32, tau_lst) FP_signal16 = ((Mt16 + 1) / 2) ## Data location ## print older_than timestamp, ssro_calib_folder = toolbox.latest_data(contains='AdwinSSRO', older_than=older_than, return_timestamp=True) print ssro_calib_folder a, folder = load_mult_dat_tag(tag, older_than, number_of_msmts=18, ssro_calib_folder=ssro_calib_folder) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35, 5)) ax = a.default_ax(fig) ax.set_xlim(4.9, 5.1) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks( np.arange(xrange[0], xrange[1], (xrange[1] - xrange[0]) / 10.)) ax.set_ylim(-0.05, 1.05) y = a.p0 ax.plot(a.sweep_pts, y, '.-g', lw=0.4, label='data', marker='o', ms=3) #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst * 1e6, FP_signal16[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt, :] fin_signal = (tot_signal + 1) / 2.0 ax.plot(tau_lst * 1e6, fin_signal, ':g', lw=.8, label='tot') lgd = plt.legend(loc=4) plt.show(block=False) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint.pdf'), format='pdf', bbox_extra_artists=(lgd, ), bbox_inches='tight') plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint.png'), format='png', bbox_extra_artists=(lgd, ), bbox_inches='tight') if return_data == True: return a.sweep_pts, a.p0
def fingerprint_contrast_concatenate(disp_sim_spin=True, n_sim_spins=2, pts=51, start_1=3.0, start_2=3.0 + 45 * 50 * 10e-3, step_size=10e-3, tau_larmor=False, name='', xrange=[0, 20], tag_p='', tag_n='', older_than=None, return_data=False, do_plot=True, load_from_data=False, Nr_of_pulses=None, save_folder=None, figsize=(20, 5)): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms='plus') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) t_L = 1 / (1.0705e3 * B_Field) * 1e6 tau_lst = np.linspace(0, 72e-6, 10000) Mt16 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, Nr_of_pulses, tau_lst) FP_signal16 = ((Mt16 + 1) / 2) ## Data location ## if load_from_data == False: ssro_calib_folder = folder = toolbox.latest_data( contains='AdwinSSRO_SSROCalibration_111_1_sil18', older_than=older_than, folder='d:\measuring\data') a1, folder = load_mult_dat_tag(tag_p + '0', older_than, number_of_msmts=50, pts=pts, start=start_1, step_size=step_size, ssro_calib_folder=ssro_calib_folder) b1, folder_b1 = load_mult_dat_tag(tag_n + '0', older_than, number_of_msmts=50, pts=pts, start=start_1, step_size=step_size, ssro_calib_folder=ssro_calib_folder) a2, folder = load_mult_dat_tag(tag_p + '45', older_than, number_of_msmts=50, pts=pts, start=start_2, step_size=step_size, ssro_calib_folder=ssro_calib_folder) b2, folder_b2 = load_mult_dat_tag(tag_n + '45', older_than, number_of_msmts=50, pts=pts, start=start_2, step_size=step_size, ssro_calib_folder=ssro_calib_folder) print folder_b2 print folder_b1 ############### ## Plotting ### ############### y = np.concatenate(((a1.p0 - b1.p0), (a2.p0 - b2.p0))) x = np.concatenate((a1.sweep_pts, a2.sweep_pts)) y_err = np.concatenate(((np.sqrt(a1.u_p0**2 + b1.u_p0**2)), (np.sqrt(a2.u_p0**2 + b2.u_p0**2)))) data = {} data['x'] = x data['y'] = y data['y_err'] = y_err print y_err # pickle.dump(data, open( 'sil18_fingerprint_ms_min_N'+str(Nr_of_pulses)+'.p', 'wb' ) ) np.savetxt( 'sil18_fingerprint_incl_errorbar_ms_plus_N' + str(Nr_of_pulses) + '.txt', (np.c_[x], y, y_err)) # print 'shapes' # print np.transpose(x[0:10]) # print np.array(y[0:10]) # x = np.arange(0,10,1) # y = x**2 # pickle.dump(data, open( 'sil18_fingerprint_ms_plus_N'+str(Nr_of_pulses)+'.p', 'wb' ) ) # np.savetxt('sil18_fingerprint_ms_plus_N'+str(Nr_of_pulses)+'.txt',(np.c_[x],y)) else: # data = pickle.load( open( 'sil18_fingerprint_ms_plus_N'+str(Nr_of_pulses)+'.p', 'rb' ) ) # x = data['x'] # y = data['y'] x, y, y_err = np.loadtxt('sil18_fingerprint_incl_errorbar_ms_plus_N' + str(Nr_of_pulses) + '.txt') print y_err folder = save_folder if tau_larmor == True: x = x / t_L y = (y + 1) / 2. y_err = y_err / 2. folder = save_folder if do_plot == True: fig, ax = plt.subplots(figsize=figsize) ax.set_xlim(4.9, 5.1) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks( np.arange(xrange[0], xrange[1] + 0.1, (xrange[1] - xrange[0]) / 4.)) # ax.set_ylim(-1.05,1.05) ax.set_ylim(-0.05, 1.05) ax.yaxis.set_ticks([0, 0.5, 1]) # ax.plot(x, y, '.-b', lw=1,label = 'data',marker = 'o') #N = 16 # ax.plot(x, y, '.-k', lw=0.4,label = 'data') #N = 16 # ax.plot(x, (y+1)/2., '.-b', lw=1,label = 'data', marker = 'o', ms = 8) #N = 16 ax.plot(x, y, '.-k', lw=0.4, label='data', marker='o', ms=3, markeredgecolor='m') #N = 16 ax.set_xlabel('tau (us)') if tau_larmor == True: ax.set_xlabel('tau/tau_larmor') ax.set_ylabel('Fidelity') # ax.plot(a1.sweep_pts, (a1.p0-b1.p0), '.-b', lw=0.4,label = 'data') #N = 16 # ax.plot(a2.sweep_pts, (a2.p0-b2.p0), '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): # print tt if tau_larmor == False: ax.plot(tau_lst * 1e6, Mt16[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) if tau_larmor == True: ax.plot(tau_lst * 1e6 / t_L, Mt16[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt, :] fin_signal = (tot_signal + 1) / 2.0 ax.plot(tau_lst * 1e6, fin_signal, ':g', lw=.8, label='tot') # ax.vlines([5.5,6.5],-1.1,1.1,color = '0.5',lw = 1,linestyles = '-') # plt.axvspan(5.5,6.5, facecolor='c', alpha=0.1) # lgd = plt.legend(loc=4) plt.show(block=False) # ax.vlines([5.5,6.5],-1.1,1.1,color = '0.5',lw = 1,linestyles = '-') # plt.axvspan(5.5,6.5, facecolor='m', alpha=0.1) print folder try: # plt.savefig(os.path.join(folder, 'contrast_150924.pdf'), # format='pdf',bbox_inches='tight') # plt.savefig(os.path.join(folder, 'contrast_150924.png'), # format='png',bbox_inches='tight') plt.savefig(os.path.join(folder, name + '.pdf'), format='pdf', bbox_inches='tight') plt.savefig(os.path.join(folder, name + '.png'), format='png', bbox_inches='tight') except: print 'Figure has not been saved' if return_data == True: return x, (y + 1) / 2.
def fingerprint(disp_sim_spin = True, RO = 'x'): ################### ## Data location ## ################### if RO == '-x': timestamp ='20140730_140911' # for the -x msmt elif RO == 'x': timestamp ='20140730_134956' # for the +x msmt timestamp = '20140730_184039' ssro_calib_folder = 'D:\\measuring\data\\20140730\\115839_AdwinSSRO_SSROCalibration_Hans_sil1' a, folder = fp_funcs.load_mult_dat(timestamp, number_of_msmts = 80, x_axis_step = 0.5, x_axis_pts_per_msmnt= 51, ssro_calib_folder=ssro_calib_folder) ####################### # Add simulated spins # ####################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'min') B_Field = 304.49 tau_lst = np.linspace(0, 72e-6, 10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,16,tau_lst) FP_signal16 = ((Mt16+1)/2) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35,5)) ax = a.default_ax(fig) ax.set_xlim(0,40) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(start, end, 0.5)) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, len(HF_par))) for tt in range(len(HF_par)): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(len(HF_par)): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') plt.legend(loc=4) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.png'), format='png')
def fit_fingerprints(spin_dict, Bx_list, Bz, N, sweep_parameter, name_contains, nr_ids=1, timestamp=None, data_stamps=None, ssro_calib_folder='', **kw): """ Overlaps fingerprint DD data with simulations so that spin bath characteristics can be manually fitted. Inputs: - spin_dict*: dictionary containing dictionaries representing the coupled C-spins. Each spin dictionary should contain another dictionary with entries 'par' and 'perp', representing the parallel and perpendicular hyperfine component (in Hz) - Bx_list*: list containing values for perpendicular component of static field. - Bz: parallel component of static field (in G) - N: number of pulses in XY decoupling scheme - sweep_parameter: string indicating which simulation should be multiply plotted. Must be identical to the name of one of the asterisk-marked input parameters. If 'None': plots all coupled spins for a single Bx value (STILL NEEDS TO BE IMPLEMENTED) EXAMPLE 1: if sweep_parameter = 'Bx_list', all separate values in Bx_list are simulated & plotted for all spins in spin_dict EXAMPLE 2: if sweep_parameter = 'spin_dict', each spin in spin_dict is separately simulated & plotted for the given Bx - name_contains: string containing an element of the file name - (Optional) Timestamp: to import data from a specific time. Overrules 'name_contains' - (Optional) data_stamps: dictionary containing info of multiple hdf5 files with data. See function 'get_data_multiple_files' above. If provided, then data is imported from corresponding timestamps (i.e. 'name_contains' and 'timestamp' are overruled) - (Optional) ssro_calib_folder: for data from a single file, specify the corresponding ssro_calib_folder. If '', latest calibration is used - (Optional) kw: plot formatting & saving parameters. Can be one of the following: -- xlim -- ylim -- add_stitching_pts: if True, adds stitching points to fingerprint """ # Check errors if sweep_parameter != 'spin_dict' and sweep_parameter != 'Bx_list' and sweep_parameter != None: raise Exception('No sweeping parameter selected!') # Retrieve measurement data if data_stamps != None: x, y, yerr, folder, all_stitching_points = get_data_multiple_files( data_stamps) elif timestamp != None: if nr_ids == 1: x, y, yerr, folder = get_data(name_contains, input_timestamp=timestamp, ssro_calib_folder=ssro_calib_folder) else: # multiple loops in SimpleDecoupling x, y, yerr, folder, all_stitching_points = get_data_multiple_msmts( name_contains, nr_ids, input_timestamp=timestamp, ssro_calib_folder=ssro_calib_folder) else: if nr_ids == 1: x, y, yerr, folder, timestamp = get_data( name_contains, input_timestamp=timestamp, ssro_calib_folder=ssro_calib_folder) else: x, y, yerr, folder, timestamp, all_stitching_points = get_data_multiple_msmts( name_contains, nr_ids, input_timestamp=timestamp, ssro_calib_folder=ssro_calib_folder) # Plot measurement data if 'figsize' in kw: figsize = kw.pop('figsize') fig = plt.figure(figsize=figsize) else: fig = plt.figure(figsize=(25, 6)) ax = fig.add_subplot(111) plt.errorbar(x, y, yerr=yerr, fmt='o', color='RoyalBlue') ymin, ymax = ax.get_ylim() # Add stitching points as vertical lines (if they exist) add_stitching_pts = kw.pop('add_stitching_pts', True) if len(all_stitching_points) != 0 and add_stitching_pts: plt.vlines(all_stitching_points, ymin, ymax, linestyles='dashed', label='stitching_points') for val in all_stitching_points: plt.text(val, 1., str(val)) # Set general parameters spin_names = spin_dict.keys() ################## ## SWEEP NR OF SPINS ## ################## if sweep_parameter == 'spin_dict': # Check if only 1 value of Bx exists if len(Bx_list) > 1: raise Exception( "You're sweeping spin_dict has more than 1 value for Bx. Cannot do it." ) else: Bx = Bx_list[0] for s in range(len(spin_dict)): name = spin_names[s] label = '%s: par = %s KHz, perp = %s KHz' % ( spin_names[s], spin_dict[name]['par'] * 1e-3, spin_dict[name]['perp'] * 1e-3) # Compute hyperfine components HF_par = [ spin_dict[name]['par'] - spin_dict[name]['perp'] * Bx / Bz ] HF_perp = [ spin_dict[name]['perp'] + spin_dict[name]['par'] * Bx / Bz ] # Perform simulation tau_list = x * 1e-6 Mt = SC.dyn_dec_signal(HF_par, HF_perp, Bz, N, tau_list) FP_signal = ((Mt + 1) / 2) # Plot simulation result ax.plot(x, FP_signal[0, :], '.-', lw=.8, label=label) ################## ## SWEEP Bx ## ################## elif sweep_parameter == 'Bx_list': for b in range(len(Bx_list)): Bx = Bx_list[b] label = 'Bx = %s G with %s spins' % (Bx, len(spin_dict)) for s in range(len(spin_dict)): name = spin_names[s] label = '%s: par = %s KHz, perp = %s KHz' % ( spin_names[s], spin_dict[name]['par'] * 1e-3, spin_dict[name]['perp'] * 1e-3) # Compute hyperfine components HF_par = [ spin_dict[name]['par'] - spin_dict[name]['perp'] * Bx / Bz ] HF_perp = [ spin_dict[name]['perp'] + spin_dict[name]['par'] * Bx / Bz ] # Perform simulation tau_list = x * 1e-6 if s == 0: Mt = SC.dyn_dec_signal(HF_par, HF_perp, Bz, N, tau_list) else: Mt = Mt * SC.dyn_dec_signal(HF_par, HF_perp, Bz, N, tau_list) FP_signal = ((Mt + 1) / 2) ax.plot(x, FP_signal[0, :], '.-', lw=.8, label=label) ################## ## PLOT CURRENT VALUES ## ################## # NOTE: DOESN'T WORK YET! (30-04-2015) # elif sweep_parameter == None: # label = '%s spin(s) ' # Plot formatting if 'xlim' in kw: xlim = kw.pop('xlim') plt.xlim([xlim[0], xlim[1]]) if 'ylim' in kw: ylim = kw.pop('ylim') plt.ylim([ylim[0], ylim[1]]) plt.ylabel(r'Signal normalized to 1', fontsize=25) plt.xlabel('tau (us)', fontsize=25) plt.tick_params(axis='x', labelsize=25) plt.tick_params(axis='y', labelsize=25) plt.title(timestamp) plt.legend(loc=4) # Save fit plt.savefig(os.path.join(folder, 'SimpleDecoupling_Fingerprint.png')) return
def fingerprint(disp_sim_spin=True, xlim=None): ################### ## Data location ## ################### timestamp = '20140730_145444' # for the -x msmt timestamp = '20140730_142833' # for the +x msmt timestamp = '20140730_213811' ssro_calib_folder = 'D:\\measuring\data\\20140730\\115839_AdwinSSRO_SSROCalibration_Hans_sil1' a, folder = fp_funcs.load_mult_dat(timestamp, number_of_msmts=80, x_axis_step=0.5, x_axis_pts_per_msmnt=51, ssro_calib_folder=ssro_calib_folder) ####################### # Add simulated spins # ####################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms='min') B_Field = 304.49 tau_lst = np.linspace(0, 72e-6, 10000) Mt16 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 32, tau_lst) FP_signal16 = ((Mt16 + 1) / 2) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35, 5)) ax = a.default_ax(fig) if xlim == None: ax.set_xlim(0, 40) else: ax.set_xlim(xlim) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(start, end, 0.5)) ax.set_ylim(-0.05, 1.05) ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4, label='data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, len(HF_par))) for tt in range(len(HF_par)): ax.plot(tau_lst * 1e6, FP_signal16[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(len(HF_par)): tot_signal = tot_signal * Mt16[tt, :] fin_signal = (tot_signal + 1) / 2.0 ax.plot(tau_lst * 1e6, fin_signal, ':g', lw=.8, label='tot') plt.legend(loc=4) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint.png'), format='png')
def fingerprint(disp_sim_spin = True,x_range = [0,20],n_sim_spins= 13): ################### # Add simulated spins # ################### if disp_sim_spin == True: # HF_par = [hf['C1']['par'],hf['C2']['par'],hf['C3']['par'], hf['C4']['par'], hf['C5']['par'], hf['C6']['par'], hf['C7']['par'], hf['C8']['par'], hf['C9']['par'], hf['C10']['par'], hf['C11']['par'], hf['C12']['par'], hf['C13']['par']] # HF_perp = [hf['C1']['perp'],hf['C2']['perp'],hf['C3']['perp'], hf['C4']['perp'], hf['C5']['perp'], hf['C6']['perp'], hf['C7']['perp'], hf['C8']['perp'], hf['C9']['perp'], hf['C10']['perp'], hf['C11']['perp'], hf['C12']['perp'], hf['C13']['perp']] HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'plus', NV = 'Hans') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 304.12 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,32,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## timestamps =['20140418_185913', '20140419_233953'] if os.name =='posix': ssro_calib_folders = ['//Users//Adriaan//Documents//teamdiamond//data//20140419//111949_AdwinSSRO_SSROCalibration_Hans_sil1', '//Users//Adriaan//Documents//teamdiamond//data//20140419//123556_AdwinSSRO_SSROCalibration_Hans_sil1'] else: ssro_calib_folders = ['d:\\measuring\\data\\20140419\\111949_AdwinSSRO_SSROCalibration_Hans_sil1', 'd:\\measuring\\data\\20140419\\123556_AdwinSSRO_SSROCalibration_Hans_sil1'] a, folder = load_mult_dat(timestamps = timestamps, number_of_msmts = [90,90], ssro_calib_folders =ssro_calib_folders) ############ ## Plotting ### ############ fig = a.default_fig(figsize=(20,5)) ax = a.default_ax(fig) ax.set_xlim(x_range) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(start, end, 2)) # ax.set_xlim(xrange) ax.set_ylim(-0.05,1.05) ax.yaxis.set_ticks([0,0.5,1]) # ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.5,label = 'data') colormap = plt.cm.rainbow import matplotlib as mpl; reload(mpl) mpl.rcParams['pdf.fonttype'] = 42 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colormap(tt/float(n_sim_spins))) # plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.9, n_sim_spins)]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.5) #N = 16 ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.png'), format='png') plt.show(block = False)
def fingerprint(disp_sim_spin=True, x_range=[12.3, 21.5], n_sim_spins=13): ################### # Add simulated spins # ################### if disp_sim_spin == True: # HF_par = [hf['C1']['par'],hf['C2']['par'],hf['C3']['par'], hf['C4']['par'], hf['C5']['par'], hf['C6']['par'], hf['C7']['par'], hf['C8']['par'], hf['C9']['par'], hf['C10']['par'], hf['C11']['par'], hf['C12']['par'], hf['C13']['par']] # HF_perp = [hf['C1']['perp'],hf['C2']['perp'],hf['C3']['perp'], hf['C4']['perp'], hf['C5']['perp'], hf['C6']['perp'], hf['C7']['perp'], hf['C8']['perp'], hf['C9']['perp'], hf['C10']['perp'], hf['C11']['perp'], hf['C12']['perp'], hf['C13']['perp']] HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms='plus', NV='Hans') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 304.12 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0, 72e-6, 10000) Mt16 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 32, tau_lst) FP_signal16 = ((Mt16 + 1) / 2) ## Data location ## timestamps = ['20140418_185913', '20140419_233953'] if os.name == 'posix': ssro_calib_folders = [ '//Users//Adriaan//Documents//teamdiamond//data//20140419//111949_AdwinSSRO_SSROCalibration_Hans_sil1', '//Users//Adriaan//Documents//teamdiamond//data//20140419//123556_AdwinSSRO_SSROCalibration_Hans_sil1' ] else: ssro_calib_folders = [ 'd:\\measuring\\data\\20140419\\111949_AdwinSSRO_SSROCalibration_Hans_sil1', 'd:\\measuring\\data\\20140419\\123556_AdwinSSRO_SSROCalibration_Hans_sil1' ] a, folder = load_mult_dat(timestamps=timestamps, number_of_msmts=[90, 90], ssro_calib_folders=ssro_calib_folders) ############ ## Plotting ### ############ fig = a.default_fig(figsize=(15, 5)) ax = a.default_ax(fig) ax.set_xlim(x_range) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(14, 22, 2)) # ax.set_xlim(xrange) ax.set_ylim(-0.05, 1.05) ax.yaxis.set_ticks([0, 0.5, 1]) # ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16 ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.5, label='data') colormap = plt.cm.rainbow import matplotlib as mpl reload(mpl) mpl.rcParams['pdf.fonttype'] = 42 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst * 1e6, FP_signal16[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colormap(tt / float(n_sim_spins))) # plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.9, n_sim_spins)]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt, :] fin_signal = (tot_signal + 1) / 2.0 ax.plot(tau_lst * 1e6, fin_signal, ':g', lw=.8, label='tot') ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.5) #N = 16 ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) folder = r'D:\measuring\data\Analyzed figures\Fingerprints' print folder plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint.png'), format='png') plt.show(block=False)
def plot_all(disp_sim_spin=True, xrange=[2.5, 52.5], n_sim_spins=8, load_data=True): if load_data == False: data = {} data['x_64'], data['y_64'] = fingerprint_contrast_concatenate( disp_sim_spin=True, n_sim_spins=0, pts=51, start_1=3.0, start_2=3 + 45 * 50 * 4e-3, step_size=4e-3, xrange=[2.5, 52.5], tag_p='Hermite_Fingerprint_msp1_111_1_sil18_64-x', tag_n='Hermite_Fingerprint_msp1_111_1_sil18_64x', older_than='20150726090000', return_data=True, do_plot=False) data['x_128'], data['y_128'] = fingerprint_contrast_concatenate( disp_sim_spin=True, n_sim_spins=0, pts=21, start_1=3.0, start_2=3 + 45 * 20 * 4e-3, step_size=4e-3, xrange=[2.5, 52.5], tag_p='Hermite_Fingerprint_msp1_111_1_sil18_128-x', tag_n='Hermite_Fingerprint_msp1_111_1_sil18_128x', older_than='20150726090000', return_data=True, do_plot=False) data['x_4'], data['y_4'] = fingerprint_contrast_concatenate( disp_sim_spin=True, n_sim_spins=0, pts=51, start_1=3.0, start_2=3 + 45 * 50 * 10e-3, step_size=10e-3, xrange=[2.5, 52.5], tag_p='Hermite_Fingerprint_msp1_111_1_sil18_4-x', tag_n='Hermite_Fingerprint_msp1_111_1_sil18_4x', older_than='20150726090000', return_data=True, do_plot=False) data['x_8'], data['y_8'] = fingerprint_contrast_concatenate( disp_sim_spin=True, n_sim_spins=0, pts=51, start_1=3.0, start_2=3 + 45 * 50 * 10e-3, step_size=10e-3, xrange=[2.5, 52.5], tag_p='Hermite_Fingerprint_msp1_111_1_sil18_8-x', tag_n='Hermite_Fingerprint_msp1_111_1_sil18_8x', older_than='20150726090000', return_data=True, do_plot=False) data['x_16'], data['y_16'] = fingerprint_contrast_concatenate( disp_sim_spin=True, n_sim_spins=0, pts=51, start_1=3.0, start_2=3 + 45 * 50 * 10e-3, step_size=10e-3, xrange=[2.5, 52.5], tag_p='Hermite_Fingerprint_msp1_111_1_sil18_16-x', tag_n='Hermite_Fingerprint_msp1_111_1_sil18_16x', older_than='20150726090000', return_data=True, do_plot=False) data['x_32'], data['y_32'] = fingerprint_contrast_concatenate( disp_sim_spin=True, n_sim_spins=0, pts=51, start_1=3.0, start_2=3 + 45 * 50 * 10e-3, step_size=10e-3, xrange=[2.5, 52.5], tag_p='Hermite_Fingerprint_msp1_111_1_sil18_32-x', tag_n='Hermite_Fingerprint_msp1_111_1_sil18_32x', older_than='20150726090000', return_data=True, do_plot=False) pickle.dump(data, open("fingerprinting_msp1.p", "wb")) else: data = pickle.load(open("fingerprinting_msp1.p", "rb")) ############### ## Plotting ### ############### xrange = xrange fig = plt.figure(figsize=(10, 35)) ax4 = plt.subplot(511) ax8 = plt.subplot(512, sharex=ax4) ax16 = plt.subplot(513, sharex=ax4) ax32 = plt.subplot(514, sharex=ax4) ax64 = plt.subplot(515, sharex=ax4) for ax in [ax4, ax8, ax16, ax32, ax64]: ax.set_xlim(xrange) start, end = ax.get_xlim() # ax.xaxis.set_ticks() ax.set_ylim(-0.05, 1.05) ax64.xaxis.set_ticks( np.arange(xrange[0], xrange[1], (xrange[1] - xrange[0]) / 10.)) ax4.plot(data['x_4'], data['y_4'], '.-k', lw=0.4, marker='o', ms=0.5, label='data') #N = 16 ax8.plot(data['x_8'], data['y_8'], '.-k', lw=0.4, marker='o', ms=0.5, label='data8') #N = 16 ax16.plot(data['x_16'], data['y_16'], '.-k', lw=0.4, marker='o', ms=0.5, label='data16') #N = 16 ax32.plot(data['x_32'], data['y_32'], '.-k', lw=0.4, marker='o', ms=0.5, label='data32') #N = 16 ax64.plot(data['x_64'], data['y_64'], '.-k', lw=0.4, marker='o', ms=0.5, label='data64') #N = 16 if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms='plus') B_Field = 403.555 tau_lst = np.linspace(0, 72e-6, 10000) colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): Mt4 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 4, tau_lst) FP_signal4 = ((Mt4 + 1) / 2) ax4.plot(tau_lst * 1e6, FP_signal4[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) ax4.set_title('N = 4') Mt8 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 8, tau_lst) FP_signal8 = ((Mt8 + 1) / 2) ax8.plot(tau_lst * 1e6, FP_signal8[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) ax8.set_title('N = 8') Mt16 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 16, tau_lst) FP_signal16 = ((Mt16 + 1) / 2) ax16.plot(tau_lst * 1e6, FP_signal16[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) ax16.set_title('N = 16') Mt32 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 32, tau_lst) FP_signal32 = ((Mt32 + 1) / 2) ax32.plot(tau_lst * 1e6, FP_signal32[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) ax32.set_title('N = 32') Mt64 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 64, tau_lst) FP_signal64 = ((Mt64 + 1) / 2) ax64.plot(tau_lst * 1e6, FP_signal64[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) ax64.set_title('N = 64') plt.xlabel('tau (us)') plt.setp(ax4.get_xticklabels(), visible=False) plt.setp(ax8.get_xticklabels(), visible=False) plt.setp(ax16.get_xticklabels(), visible=False) plt.setp(ax32.get_xticklabels(), visible=False) lgd = ax4.legend(bbox_to_anchor=(1.01, -0.5), loc='lower left', borderaxespad=0.) # lgd = plt.legend(loc=4) plt.show(block=False) folder = r'D:\measuring\data\LT2_Data\Fingerprinting' plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint_all_msp1.pdf'), format='pdf', bbox_extra_artists=(lgd, ), bbox_inches='tight') plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint_all_msp1.png'), format='png', bbox_extra_artists=(lgd, ), bbox_inches='tight')
def fingerprint_contrast(disp_sim_spin=True, n_sim_spins=2, pts=51, xrange=[0, 20], tag_p='', tag_n='', older_than=None, return_data=False): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms='min') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0, 72e-6, 10000) Mt16 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, 32, tau_lst) FP_signal16 = ((Mt16 + 1) / 2) ## Data location ## ssro_calib_folder = folder = toolbox.latest_data( contains='AdwinSSRO_SSROCalibration_111_1_sil18', older_than=older_than, folder='d:\measuring\data') a, folder = load_mult_dat_contrast(tag_p, older_than, number_of_msmts=50, pts=pts, ssro_calib_folder=ssro_calib_folder) b, folder_b = load_mult_dat_contrast(tag_n, older_than, number_of_msmts=50, pts=pts, ssro_calib_folder=ssro_calib_folder) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35, 5)) ax = a.default_ax(fig) ax.set_xlim(4.9, 5.1) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks( np.arange(xrange[0], xrange[1], (xrange[1] - xrange[0]) / 10.)) ax.set_ylim(-1.05, 1.05) y = (a.p0 - b.p0) print a.sweep_pts ax.plot(a.sweep_pts, y, '.-k', lw=0.4, label='data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst * 1e6, FP_signal16[tt, :], '-', lw=.8, label='spin' + str(tt + 1), color=colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt, :] fin_signal = (tot_signal + 1) / 2.0 ax.plot(tau_lst * 1e6, fin_signal, ':g', lw=.8, label='tot') plt.legend(loc=4) plt.show(block=False) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint_contrast.pdf'), format='pdf') plt.savefig(os.path.join(folder, str(disp_sim_spin) + 'fingerprint_contrast.png'), format='png') if return_data == True: return a.sweep_pts, (y + 1) / 2.
def fingerprint_compare(disp_sim_spin = True): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_par = [30e3, 27e3,-62.5e3] HF_orth =[80e3,28.5e3,132e3] #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 304.12 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,30e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_orth,B_Field,16,tau_lst) FP_signal16 = ((Mt16+1)/2) Mt32 = SC.dyn_dec_signal(HF_par,HF_orth,B_Field,32,tau_lst) FP_signal32 = ((Mt32+1)/2) ## Data location ## timestamps_16 = ['20140407_223450', '20140407_223801', '20140407_224119', '20140407_224446', '20140407_231158','20140407_225215', '20140407_225614', '20140407_230023', '20140407_231645', '20140407_232118', '20140407_232603', '20140407_233057', '20140407_233605', '20140407_234654', '20140408_111324', '20140408_111725', '20140408_112126', '20140408_112529', '20140408_112930', '20140408_113614', '20140408_114015', '20140408_114416', '20140408_114818', '20140408_115220', '20140408_115622', '20140408_120024', '20140408_120426', '20140408_120825', '20140408_130753']#, timestamps_32 = ['20140417_110229','20140417_110529','20140417_110827','20140417_111123','20140417_111421','20140417_111716', '20140417_112017','20140417_112315','20140417_112613','20140417_112914','20140417_113214','20140417_113517', '20140417_113817','20140417_114122','20140417_114424','20140417_114727','20140417_115034','20140417_115338', '20140417_115644','20140417_115953','20140417_120300','20140417_120607','20140417_120915','20140417_121224', '20140417_121535','20140417_121847','20140417_122159','20140417_122511','20140417_122511','20140417_122824', '20140417_123137','20140417_123453','20140417_123808','20140417_124125','20140417_124444','20140417_124803', '20140417_125124','20140417_125444','20140417_125807','20140417_130129'] #with 32 pulses a = load_mult_dat(timestamps_16) b = load_mult_dat(timestamps_32) ############ ## Plotting ### ############ # N = 16 fig = a.default_fig(figsize=(18,4)) ax = a.default_ax(fig) ax.set_xlim(0,23) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-b', lw=1,label = 'data') #N = 16 ax.plot(tau_lst*1e6, FP_signal16[0,:] ,'--',lw=.5,label = 'spin1') ax.plot(tau_lst*1e6, FP_signal16[1,:] ,'--',lw=.5,label = 'spin2') ax.plot(tau_lst*1e6, FP_signal16[2,:] ,'--',lw=.5,label = 'spin3') plt.legend(loc=4) fig = b.default_fig(figsize=(18,4)) ax = b.default_ax(fig) ax.set_xlim(0,23) ax.set_ylim(-0.05,1.05) ax.plot(b.sweep_pts, b.p0, '.-b', lw=1,label = 'data' ) ax.plot(tau_lst*1e6, FP_signal32[0,:] ,'--',lw=.5,label = 'spin1') ax.plot(tau_lst*1e6, FP_signal32[1,:] ,'--',lw=.5,label = 'spin2') ax.plot(tau_lst*1e6, FP_signal32[2,:] ,'--',lw=.5,label = 'spin3') plt.legend(loc=4) fig = b.default_fig(figsize=(18,4)) ax = b.default_ax(fig) ax.set_xlim(0,23) ax.set_ylim(-0.05,1.05) ax.plot(a.sweep_pts, a.p0, '.-b', lw=1,label = 'N=16') ax.plot(b.sweep_pts, b.p0, '.-r', lw=1,label = 'N=32') plt.legend(loc=4)
def plot_all(disp_sim_spin = True,xrange = [2.5,52.5], n_sim_spins = 8,load_data = True): if load_data == False: data = {} data['x_64'] , data['y_64'] = fingerprint_contrast_concatenate(disp_sim_spin = True,n_sim_spins = 0,pts = 51,start_1 = 3.0, start_2 = 3+45*50*4e-3, step_size = 4e-3, xrange = [2.5,52.5],tag_p = 'Hermite_Fingerprint_msp1_111_1_sil18_64-x',tag_n = 'Hermite_Fingerprint_msp1_111_1_sil18_64x', older_than = '20150726090000',return_data = True, do_plot= False) data['x_128'] ,data['y_128'] = fingerprint_contrast_concatenate(disp_sim_spin = True,n_sim_spins = 0,pts = 21,start_1 = 3.0, start_2 = 3+45*20*4e-3, step_size = 4e-3, xrange = [2.5,52.5],tag_p = 'Hermite_Fingerprint_msp1_111_1_sil18_128-x',tag_n = 'Hermite_Fingerprint_msp1_111_1_sil18_128x', older_than = '20150726090000',return_data = True, do_plot= False) data['x_4'], data['y_4']= fingerprint_contrast_concatenate(disp_sim_spin = True,n_sim_spins = 0,pts = 51,start_1 = 3.0, start_2 = 3+45*50*10e-3, step_size = 10e-3, xrange = [2.5,52.5],tag_p = 'Hermite_Fingerprint_msp1_111_1_sil18_4-x',tag_n = 'Hermite_Fingerprint_msp1_111_1_sil18_4x', older_than = '20150726090000',return_data = True, do_plot= False) data['x_8'], data['y_8']= fingerprint_contrast_concatenate(disp_sim_spin = True,n_sim_spins = 0,pts = 51,start_1 = 3.0, start_2 = 3+45*50*10e-3, step_size = 10e-3, xrange = [2.5,52.5],tag_p = 'Hermite_Fingerprint_msp1_111_1_sil18_8-x',tag_n = 'Hermite_Fingerprint_msp1_111_1_sil18_8x', older_than = '20150726090000',return_data = True, do_plot= False) data['x_16'] , data['y_16'] = fingerprint_contrast_concatenate(disp_sim_spin = True,n_sim_spins = 0,pts = 51,start_1 = 3.0, start_2 = 3+45*50*10e-3, step_size = 10e-3, xrange = [2.5,52.5],tag_p = 'Hermite_Fingerprint_msp1_111_1_sil18_16-x',tag_n = 'Hermite_Fingerprint_msp1_111_1_sil18_16x', older_than = '20150726090000',return_data = True, do_plot= False) data['x_32'] , data['y_32'] = fingerprint_contrast_concatenate(disp_sim_spin = True,n_sim_spins = 0,pts = 51,start_1 = 3.0, start_2 = 3+45*50*10e-3, step_size = 10e-3, xrange = [2.5,52.5],tag_p = 'Hermite_Fingerprint_msp1_111_1_sil18_32-x',tag_n = 'Hermite_Fingerprint_msp1_111_1_sil18_32x', older_than = '20150726090000',return_data = True, do_plot= False) pickle.dump(data, open( "fingerprinting_msp1.p", "wb" ) ) else: data = pickle.load( open( "fingerprinting_msp1.p", "rb" ) ) ############### ## Plotting ### ############### xrange = xrange fig = plt.figure(figsize=(10,35)) ax4 = plt.subplot(511) ax8 = plt.subplot(512, sharex=ax4) ax16 = plt.subplot(513, sharex=ax4) ax32 = plt.subplot(514, sharex=ax4) ax64 = plt.subplot(515, sharex=ax4) for ax in [ax4,ax8,ax16,ax32,ax64]: ax.set_xlim(xrange) start, end = ax.get_xlim() # ax.xaxis.set_ticks() ax.set_ylim(-0.05,1.05) ax64.xaxis.set_ticks(np.arange(xrange[0], xrange[1], (xrange[1]- xrange[0])/10.)) ax4.plot(data['x_4'], data['y_4'], '.-k', lw=0.4,marker = 'o', ms = 0.5,label = 'data') #N = 16 ax8.plot(data['x_8'], data['y_8'], '.-k', lw=0.4,marker = 'o', ms = 0.5,label = 'data8') #N = 16 ax16.plot(data['x_16'], data['y_16'], '.-k', lw=0.4,marker = 'o', ms = 0.5,label = 'data16') #N = 16 ax32.plot(data['x_32'], data['y_32'], '.-k', lw=0.4,marker = 'o', ms = 0.5,label = 'data32') #N = 16 ax64.plot(data['x_64'], data['y_64'], '.-k', lw=0.4,marker = 'o', ms = 0.5,label = 'data64') #N = 16 if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'plus') B_Field = 403.555 tau_lst = np.linspace(0,72e-6,10000) colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): Mt4 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,4,tau_lst) FP_signal4 = ((Mt4+1)/2) ax4.plot(tau_lst*1e6, FP_signal4[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) ax4.set_title('N = 4') Mt8 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,8,tau_lst) FP_signal8 = ((Mt8+1)/2) ax8.plot(tau_lst*1e6, FP_signal8[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) ax8.set_title('N = 8') Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,16,tau_lst) FP_signal16 = ((Mt16+1)/2) ax16.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) ax16.set_title('N = 16') Mt32 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,32,tau_lst) FP_signal32 = ((Mt32+1)/2) ax32.plot(tau_lst*1e6, FP_signal32[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) ax32.set_title('N = 32') Mt64 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,64,tau_lst) FP_signal64 = ((Mt64+1)/2) ax64.plot(tau_lst*1e6, FP_signal64[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) ax64.set_title('N = 64') plt.xlabel('tau (us)') plt.setp(ax4.get_xticklabels(), visible=False) plt.setp(ax8.get_xticklabels(), visible=False) plt.setp(ax16.get_xticklabels(), visible=False) plt.setp(ax32.get_xticklabels(), visible=False) lgd = ax4.legend(bbox_to_anchor=(1.01,-0.5),loc='lower left',borderaxespad = 0.) # lgd = plt.legend(loc=4) plt.show(block = False) folder = r'D:\measuring\data\LT2_Data\Fingerprinting' plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_all_msp1.pdf'), format='pdf',bbox_extra_artists = (lgd,),bbox_inches='tight') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_all_msp1.png'), format='png',bbox_extra_artists = (lgd,),bbox_inches='tight')
def fingerprint_contrast_concatenate(disp_sim_spin = True,n_sim_spins = 2,pts = 51,start_1 = 3.0, start_2 = 3.0+45*50*10e-3, step_size = 10e-3, xrange = [0,20],tag_p = '',tag_n = '', older_than = None,return_data = False, do_plot = True, load_from_data = False, Nr_of_pulses = None, save_folder = None): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'plus') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,Nr_of_pulses,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## if load_from_data == False: ssro_calib_folder = folder = toolbox.latest_data(contains = 'AdwinSSRO_SSROCalibration_111_1_sil18', older_than = older_than,folder = 'd:\measuring\data') a1, folder = load_mult_dat_tag(tag_p+'0',older_than, number_of_msmts = 50,pts = pts, start=start_1, step_size=step_size,ssro_calib_folder=ssro_calib_folder) b1, folder_b1 = load_mult_dat_tag(tag_n+'0', older_than, number_of_msmts = 50,pts = pts, start=start_1, step_size=step_size,ssro_calib_folder=ssro_calib_folder) a2, folder = load_mult_dat_tag(tag_p+'45',older_than, number_of_msmts = 50,pts = pts, start=start_2, step_size=step_size,ssro_calib_folder=ssro_calib_folder) b2, folder_b2 = load_mult_dat_tag(tag_n+'45', older_than, number_of_msmts = 50,pts = pts, start=start_2, step_size=step_size,ssro_calib_folder=ssro_calib_folder) print folder_b2 print folder_b1 ############### ## Plotting ### ############### y = np.concatenate(((a1.p0-b1.p0),(a2.p0-b2.p0))) x = np.concatenate((a1.sweep_pts, a2.sweep_pts)) data = {} data['x'] = x data['y'] = y print 'shapes' print np.transpose(x[0:10]) print np.array(y[0:10]) # x = np.arange(0,10,1) # y = x**2 # pickle.dump(data, open( 'sil18_fingerprint_ms_plus_N'+str(Nr_of_pulses)+'.p', 'wb' ) ) np.savetxt('sil18_fingerprint_ms_plus_N'+str(Nr_of_pulses)+'.txt',(np.c_[x],y)) else: # data = pickle.load( open( 'sil18_fingerprint_ms_plus_N'+str(Nr_of_pulses)+'.p', 'rb' ) ) # x = data['x'] # y = data['y'] x,y = np.loadtxt('sil18_fingerprint_ms_plus_N'+str(Nr_of_pulses)+'.txt') folder = save_folder if do_plot == True: fig,ax = plt.subplots(figsize=(35,5)) ax.set_xlim(4.9,5.1) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(xrange[0], xrange[1], (xrange[1]- xrange[0])/10.)) ax.set_ylim(-1.05,1.05) ax.plot(x, y, '.-k', lw=0.4,label = 'data') #N = 16 # ax.plot(a1.sweep_pts, (a1.p0-b1.p0), '.-b', lw=0.4,label = 'data') #N = 16 # ax.plot(a2.sweep_pts, (a2.p0-b2.p0), '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') lgd = plt.legend(loc=4) plt.show(block = False) print folder try: plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_contrast.pdf'), format='pdf',bbox_extra_artists = (lgd,),bbox_inches='tight') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint_contrast.png'), format='png',bbox_extra_artists = (lgd,),bbox_inches='tight') except: print 'Figure has not been saved' if return_data == True: return x, (y+1)/2.
def fingerprint_single(disp_sim_spin = True,n_sim_spins = 2,xrange = [0,20],tag = '', step_size = 10e-3, older_than = None,return_data = False): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'min') #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,32,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## print older_than timestamp, ssro_calib_folder = toolbox.latest_data(contains = 'AdwinSSRO', older_than = older_than,return_timestamp = True) print ssro_calib_folder a, folder = load_mult_dat_tag(tag,older_than, number_of_msmts = 18, ssro_calib_folder=ssro_calib_folder) ############### ## Plotting ### ############### fig = a.default_fig(figsize=(35,5)) ax = a.default_ax(fig) ax.set_xlim(4.9,5.1) ax.set_xlim(xrange) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(xrange[0], xrange[1], (xrange[1]- xrange[0])/10.)) ax.set_ylim(-0.05,1.05) y = a.p0 ax.plot(a.sweep_pts, y, '.-k', lw=0.4,label = 'data') #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt in range(n_sim_spins): ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1), color = colors[tt]) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') lgd = plt.legend(loc=4) plt.show(block = False) print folder plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.pdf'), format='pdf',bbox_extra_artists = (lgd,),bbox_inches='tight') plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.png'), format='png',bbox_extra_artists = (lgd,),bbox_inches='tight') if return_data == True: return a.sweep_pts, a.p0
def fit_fingerprints(spin_dict, Bx_list, Bz, N, sweep_parameter, name_contains, nr_ids = 1, timestamp = None, data_stamps = None, ssro_calib_folder = '', **kw ): """ Overlaps fingerprint DD data with simulations so that spin bath characteristics can be manually fitted. Inputs: - spin_dict*: dictionary containing dictionaries representing the coupled C-spins. Each spin dictionary should contain another dictionary with entries 'par' and 'perp', representing the parallel and perpendicular hyperfine component (in Hz) - Bx_list*: list containing values for perpendicular component of static field. - Bz: parallel component of static field (in G) - N: number of pulses in XY decoupling scheme - sweep_parameter: string indicating which simulation should be multiply plotted. Must be identical to the name of one of the asterisk-marked input parameters. If 'None': plots all coupled spins for a single Bx value (STILL NEEDS TO BE IMPLEMENTED) EXAMPLE 1: if sweep_parameter = 'Bx_list', all separate values in Bx_list are simulated & plotted for all spins in spin_dict EXAMPLE 2: if sweep_parameter = 'spin_dict', each spin in spin_dict is separately simulated & plotted for the given Bx - name_contains: string containing an element of the file name - (Optional) Timestamp: to import data from a specific time. Overrules 'name_contains' - (Optional) data_stamps: dictionary containing info of multiple hdf5 files with data. See function 'get_data_multiple_files' above. If provided, then data is imported from corresponding timestamps (i.e. 'name_contains' and 'timestamp' are overruled) - (Optional) ssro_calib_folder: for data from a single file, specify the corresponding ssro_calib_folder. If '', latest calibration is used - (Optional) kw: plot formatting & saving parameters. Can be one of the following: -- xlim -- ylim -- add_stitching_pts: if True, adds stitching points to fingerprint """ # Check errors if sweep_parameter != 'spin_dict' and sweep_parameter != 'Bx_list' and sweep_parameter != None: raise Exception('No sweeping parameter selected!') # Retrieve measurement data if data_stamps != None: x, y, yerr, folder, all_stitching_points = get_data_multiple_files(data_stamps) elif timestamp != None: if nr_ids == 1: x, y, yerr, folder = get_data(name_contains, input_timestamp = timestamp, ssro_calib_folder = ssro_calib_folder) else: # multiple loops in SimpleDecoupling x, y, yerr, folder, all_stitching_points = get_data_multiple_msmts(name_contains, nr_ids, input_timestamp = timestamp, ssro_calib_folder = ssro_calib_folder) else: if nr_ids == 1: x, y, yerr, folder, timestamp = get_data(name_contains, input_timestamp = timestamp, ssro_calib_folder = ssro_calib_folder) else: x, y, yerr, folder, timestamp, all_stitching_points = get_data_multiple_msmts(name_contains, nr_ids, input_timestamp = timestamp, ssro_calib_folder = ssro_calib_folder) # Plot measurement data if 'figsize' in kw: figsize = kw.pop('figsize') fig = plt.figure(figsize = figsize) else: fig = plt.figure(figsize=(25,6)) ax = fig.add_subplot(111) plt.errorbar(x,y,yerr = yerr, fmt = 'o',color='RoyalBlue') ymin, ymax = ax.get_ylim() # Add stitching points as vertical lines (if they exist) add_stitching_pts = kw.pop('add_stitching_pts', True) if len(all_stitching_points) != 0 and add_stitching_pts: plt.vlines(all_stitching_points, ymin, ymax, linestyles = 'dashed', label = 'stitching_points') for val in all_stitching_points: plt.text(val, 1., str(val)) # Set general parameters spin_names = spin_dict.keys() ################## ## SWEEP NR OF SPINS ## ################## if sweep_parameter == 'spin_dict': # Check if only 1 value of Bx exists if len(Bx_list) > 1: raise Exception("You're sweeping spin_dict has more than 1 value for Bx. Cannot do it.") else: Bx = Bx_list[0] for s in range(len(spin_dict)): name = spin_names[s] label = '%s: par = %s KHz, perp = %s KHz' % (spin_names[s], spin_dict[name]['par'] *1e-3, spin_dict[name]['perp']*1e-3 ) # Compute hyperfine components HF_par = [ spin_dict[name]['par'] - spin_dict[name]['perp'] * Bx/Bz] HF_perp = [ spin_dict[name]['perp'] + spin_dict[name]['par'] * Bx/Bz] # Perform simulation tau_list = x * 1e-6 Mt = SC.dyn_dec_signal(HF_par, HF_perp, Bz, N, tau_list) FP_signal = ((Mt + 1)/2) # Plot simulation result ax.plot(x, FP_signal[0,:], '.-', lw=.8, label = label) ################## ## SWEEP Bx ## ################## elif sweep_parameter == 'Bx_list': for b in range(len(Bx_list)): Bx = Bx_list[b] label = 'Bx = %s G with %s spins' % ( Bx, len(spin_dict) ) for s in range(len(spin_dict)): name = spin_names[s] label = '%s: par = %s KHz, perp = %s KHz' % (spin_names[s], spin_dict[name]['par'] *1e-3, spin_dict[name]['perp']*1e-3 ) # Compute hyperfine components HF_par = [ spin_dict[name]['par'] - spin_dict[name]['perp'] * Bx/Bz] HF_perp = [ spin_dict[name]['perp'] + spin_dict[name]['par'] * Bx/Bz] # Perform simulation tau_list = x * 1e-6 if s == 0: Mt = SC.dyn_dec_signal(HF_par, HF_perp, Bz, N, tau_list) else: Mt = Mt * SC.dyn_dec_signal(HF_par, HF_perp, Bz, N, tau_list) FP_signal = ((Mt + 1)/2) ax.plot(x, FP_signal[0,:], '.-', lw=.8, label = label) ################## ## PLOT CURRENT VALUES ## ################## # NOTE: DOESN'T WORK YET! (30-04-2015) # elif sweep_parameter == None: # label = '%s spin(s) ' # Plot formatting if 'xlim' in kw: xlim = kw.pop('xlim') plt.xlim( [xlim[0], xlim[1]] ) if 'ylim' in kw: ylim = kw.pop('ylim') plt.ylim( [ylim[0], ylim[1]] ) plt.ylabel(r'Signal normalized to 1',fontsize=25) plt.xlabel('tau (us)',fontsize=25) plt.tick_params(axis='x', labelsize=25) plt.tick_params(axis='y', labelsize=25) plt.title(timestamp) plt.legend(loc = 4) # Save fit plt.savefig(os.path.join(folder, 'SimpleDecoupling_Fingerprint.png')) return
def fingerprint(disp_sim_spin=True, n_sim_spins=5, N=32, xrange=[0, 20], carbons=[1, 2, 3, 4, 5]): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms='min', carbon_spins=carbons) #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_L = 1 / (1.0705e3 * B_Field) * 1e6 print tau_L tau_lst = np.linspace(0, 72e-6, 10000) Mt16 = SC.dyn_dec_signal(HF_par, HF_perp, B_Field, N, tau_lst) FP_signal16 = ((Mt16 + 1) / 2) ## Data location ## save_folder_str = 'D:/Dropbox/QEC LT/Decoupling memory/Fingerprints/N=' + str( N) if N == 32: timestamp = '20141016_205842' ssro_calib_folder = 'D:\\measuring\\data\\20141016\\150451_AdwinSSRO_SSROCalibration_111_1_sil18' a, folder = load_mult_dat(timestamp, number_of_msmts=40, ssro_calib_folder=ssro_calib_folder) elif N == 64: timestamp = '20141016_234534' ssro_calib_folder = 'D:\\measuring\\data\\20141016\\150451_AdwinSSRO_SSROCalibration_111_1_sil18' a, folder = load_mult_dat(timestamp, number_of_msmts=50, ssro_calib_folder=ssro_calib_folder) else: raise Exception('Only N=32 or N=64') print tau_L carbon_relabel = {} carbon_relabel['1'] = '2' carbon_relabel['2'] = '1' carbon_relabel['3'] = '4' carbon_relabel['5'] = '3' carbon_relabel['6'] = '5' ############### ## Plotting ### ############### first_tau = int(np.ceil(xrange[0] / tau_L)) * tau_L last_tau = int(np.ceil(xrange[1] / tau_L)) * tau_L last_tau_nr = int(np.ceil(xrange[1] / tau_L)) fig = a.default_fig(figsize=(16, 4)) ax = a.default_ax(fig) # ax.set_xlim(15.0,15.5) ax.set_title('') ax.set_xlabel(r'$\tau$ $(\mu s)$', fontsize=20) ax.set_ylabel(r'$\langle$X$\rangle$', fontsize=20) ax.set_xlim(xrange) #ax.hlines(0.,xrange[0],xrange[1],linestyles='dotted',linewidth = 1.5) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(np.ceil(xrange[0]), xrange[1], 1)) ax.vlines(first_tau, 0.1, 2, linestyles='dotted', linewidth=1.5) for tau_value in np.arange(first_tau + tau_L, last_tau, tau_L): ax.vlines(tau_value, -2, 2, linestyles='dotted', linewidth=1.5) ax.tick_params(axis='x', which='major', labelsize=15) ax.tick_params(axis='y', which='major', labelsize=15) #ax.set_xticklabels(range(1,last_tau_nr+1)) ax.set_ylim(-1.05, 1.05) handles = [] ax.plot(a.sweep_pts, a.p0 * 2 - 1, '.-k', lw=0.4) #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt, carbon_nr in enumerate(carbons): h = ax.plot(tau_lst * 1e6, FP_signal16[tt, :] * 2 - 1, '-', lw=.8, label='C' + carbon_relabel[str(carbon_nr)], color=colors[tt]) handles.append(h) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt, :] fin_signal = (tot_signal + 1) / 2.0 ax.plot(tau_lst * 1e6, fin_signal, ':g', lw=.8, label='tot') #handles, labels = ax.get_legend_handles_labels() #order= [i[0] for i in sorted(enumerate(labels), key=lambda x:x[1])] #handles = handles[order] #labels = labels[order] # sort both labels and handles by labels #labels, handles = zip(*sorted(zip(labels, handles), key=lambda t: t[0])) #ax.legend(handles, labels) plt.legend(loc='lower left', frameon=False, fontsize=15, columnspacing=0.2, handletextpad=0.0) print folder plt.savefig(save_folder_str + 'fingerprint.pdf', format='pdf', bbox_inches='tight') plt.savefig(save_folder_str + 'fingerprint.png', format='png')
def fingerprint(disp_sim_spin = True,n_sim_spins = 5,N=32,xrange = [0,20],carbons=[1,2,3,4,5]): ################### # Add simulated spins # ################### if disp_sim_spin == True: HF_perp, HF_par = fp_funcs.get_hyperfine_params(ms = 'min',carbon_spins=carbons) #msmp1_f from hdf5 file # msm1 from hdf5 file # ZFG g_factor from hdf5file B_Field = 403.555 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor) tau_L = 1/(1.0705e3*B_Field)*1e6 print tau_L tau_lst = np.linspace(0,72e-6,10000) Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,N,tau_lst) FP_signal16 = ((Mt16+1)/2) ## Data location ## save_folder_str = 'D:/Dropbox/QEC LT/Decoupling memory/Fingerprints/N=' + str(N) if N==32: timestamp ='20141016_205842' ssro_calib_folder = 'D:\\measuring\\data\\20141016\\150451_AdwinSSRO_SSROCalibration_111_1_sil18' a, folder = load_mult_dat(timestamp, number_of_msmts = 40, ssro_calib_folder=ssro_calib_folder) elif N==64: timestamp ='20141016_234534' ssro_calib_folder = 'D:\\measuring\\data\\20141016\\150451_AdwinSSRO_SSROCalibration_111_1_sil18' a, folder = load_mult_dat(timestamp, number_of_msmts = 50, ssro_calib_folder=ssro_calib_folder) else: raise Exception('Only N=32 or N=64') print tau_L carbon_relabel = {} carbon_relabel['1'] = '2' carbon_relabel['2'] = '1' carbon_relabel['3'] = '4' carbon_relabel['5'] = '3' carbon_relabel['6'] = '5' ############### ## Plotting ### ############### first_tau = int(np.ceil(xrange[0]/tau_L))*tau_L last_tau = int(np.ceil(xrange[1]/tau_L))*tau_L last_tau_nr = int(np.ceil(xrange[1]/tau_L)) fig = a.default_fig(figsize=(16,4)) ax = a.default_ax(fig) # ax.set_xlim(15.0,15.5) ax.set_title('') ax.set_xlabel(r'$\tau$ $(\mu s)$',fontsize = 20) ax.set_ylabel(r'$\langle$X$\rangle$',fontsize = 20) ax.set_xlim(xrange) #ax.hlines(0.,xrange[0],xrange[1],linestyles='dotted',linewidth = 1.5) start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(np.ceil(xrange[0]), xrange[1], 1)) ax.vlines(first_tau,0.1,2,linestyles='dotted',linewidth=1.5) for tau_value in np.arange(first_tau+tau_L, last_tau, tau_L): ax.vlines(tau_value,-2,2,linestyles='dotted',linewidth=1.5) ax.tick_params(axis='x', which='major', labelsize=15) ax.tick_params(axis='y', which='major', labelsize=15) #ax.set_xticklabels(range(1,last_tau_nr+1)) ax.set_ylim(-1.05,1.05) handles = [] ax.plot(a.sweep_pts, a.p0*2-1, '.-k', lw=0.4) #N = 16 if disp_sim_spin == True: colors = cm.rainbow(np.linspace(0, 1, n_sim_spins)) for tt, carbon_nr in enumerate(carbons): h = ax.plot(tau_lst*1e6, FP_signal16[tt,:]*2-1 ,'-',lw=.8,label = 'C' + carbon_relabel[str(carbon_nr)], color = colors[tt]) handles.append(h) if False: tot_signal = np.ones(len(tau_lst)) for tt in range(n_sim_spins): tot_signal = tot_signal * Mt16[tt,:] fin_signal = (tot_signal+1)/2.0 ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot') #handles, labels = ax.get_legend_handles_labels() #order= [i[0] for i in sorted(enumerate(labels), key=lambda x:x[1])] #handles = handles[order] #labels = labels[order] # sort both labels and handles by labels #labels, handles = zip(*sorted(zip(labels, handles), key=lambda t: t[0])) #ax.legend(handles, labels) plt.legend(loc='lower left',frameon=False,fontsize=15,columnspacing=0.2,handletextpad=0.0) print folder plt.savefig(save_folder_str+'fingerprint.pdf', format='pdf',bbox_inches='tight') plt.savefig(save_folder_str+'fingerprint.png', format='png')