Esempio n. 1
0
def save_DD_data():  
    from analysis.lib.m2.ssro import mbi; reload(mbi)
    base_folder_lt3 = analysis_params.data_settings['base_folder_lt3']
    lt3_folder = os.path.join(base_folder_lt3,'DDCalib')
    lt3_ssro_folder = os.path.join(base_folder_lt3,'SSROs')
    base_folder_lt4 = analysis_params.data_settings['base_folder_lt4']
    lt4_folder = os.path.join(base_folder_lt4,'DDCalib')
    lt4_ssro_folder = os.path.join(base_folder_lt4,'SSROs')

    file_b = tb.latest_data(contains = 'sweep_decoupling',folder= lt3_folder)
    file_a = tb.latest_data(contains = 'sweep_decoupling',folder =lt4_folder)
    ssro_b  = tb.latest_data(contains = 'SSROCalib', folder = lt3_ssro_folder)
    ssro_a  = tb.latest_data(contains = 'SSROCalib',  folder = lt4_ssro_folder)
    print file_b
    a = mbi.MBIAnalysis(file_b)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata',CR_after_check = True)
    a.get_electron_ROC(ssro_b)
    a.save('ssro_results')
   
    a = mbi.MBIAnalysis(file_a)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata',CR_after_check = True)
    a.get_electron_ROC(ssro_a)
    a.save('ssro_results')
Esempio n. 2
0
def load_mult_dat(timestamp, number_of_msmts, ssro_calib_folder=''):
   cum_pts = 0
   for kk in range(number_of_msmts):
       folder = toolbox.data_from_time(timestamp)
       a = mbi.MBIAnalysis(folder)
       a.get_sweep_pts()
       a.get_readout_results(name='measurement' + str(kk))
       a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder)
       cum_pts += a.pts

       if kk == 0:
           cum_sweep_pts = np.linspace(2.0, 2.5, 51)#a.sweep_pts
           cum_p0 = a.p0
           cum_u_p0 = a.u_p0
       else:
           cum_sweep_pts = np.concatenate((cum_sweep_pts, np.linspace(2.0+kk*(50)*10e-3, 2.5+kk*(50)*10e-3, 51)))
           cum_p0 = np.concatenate((cum_p0, a.p0))
           cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0))

   a.pts   = cum_pts
   a.sweep_pts = cum_sweep_pts
   a.p0    = cum_p0
   a.u_p0  = cum_u_p0

   return a, folder
def load_mult_dat(timestamps, number_of_msmts, ssro_calib_folders=['']):
   cum_pts = 0
   for tt in range(len(timestamps)):
    for kk in range(number_of_msmts[tt]):
      folder = toolbox.data_from_time(timestamps[tt])
      a = mbi.MBIAnalysis(folder)
      a.get_sweep_pts()
      a.get_readout_results(name='measurement' + str(kk))
      a.get_electron_ROC(ssro_calib_folder=ssro_calib_folders[tt])
      cum_pts += a.pts

      if kk == 0 and tt==0:
        cum_sweep_pts = np.linspace(2.0, 2.2, 51)#a.sweep_pts
        cum_p0 = a.p0
        cum_u_p0 = a.u_p0
      elif tt==0:
        cum_sweep_pts = np.concatenate((cum_sweep_pts, np.linspace(2.0+kk*(50)*4e-3, 2.2+kk*(50)*4e-3, 51)))
        cum_p0 = np.concatenate((cum_p0, a.p0))
        cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0))
      elif tt==1:  
        cum_sweep_pts = np.concatenate((cum_sweep_pts, np.linspace(2.0+(kk+150)*(50)*4e-3, 2.2+(kk+150)*(50)*4e-3, 51)))
        cum_p0 = np.concatenate((cum_p0, a.p0))
        cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0))

   a.pts   = cum_pts
   a.sweep_pts = cum_sweep_pts
   a.p0    = cum_p0
   a.u_p0  = cum_u_p0

   return a, folder
Esempio n. 4
0
def fit_correlation_parabolic(folder, ax, *args, **kw):
    which_correlation = kw.pop('which_correlation', 2)

    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_correlations(name='adwindata')
    a.plot_results_vs_sweepparam(ax=ax, mode='correlations')

    x = a.sweep_pts.reshape(-1)[:]
    y = a.normalized_correlations[:, which_correlation]

    x0 = fit.Parameter(args[0], 'x0')
    of = fit.Parameter(args[1], 'of')
    a = fit.Parameter(args[2], 'a')
    fitfunc_str = '(1-of) + a (x-x0)**2'

    def fitfunc_parabolic(x):
        return (1. - of()) + a() * (x - x0())**2

    fit_result = fit.fit1d(x,
                           y,
                           None,
                           p0=[of, a, x0],
                           fitfunc=fitfunc_parabolic,
                           fitfunc_str=fitfunc_str,
                           do_print=True,
                           ret=True)
    plot.plot_fit1d(fit_result,
                    np.linspace(x[0], x[-1], 201),
                    ax=ax,
                    plot_data=False,
                    print_info=False)

    return fit_result
Esempio n. 5
0
def phase_offset_after_LDE(contains='', **kw):
    '''
    gets data from a folder whose name contains the contains variable.
    Does or does not fit the data with a gaussian function
    '''

    ### folder choice
    if contains == '':
        contains = 'phase_offset_after_LDE'

    # older_than = kw.get('older_than',None) automatically handled by kws
    ### acquire data
    f = toolbox.latest_data(contains, **kw)
    a = mbi.MBIAnalysis(f)
    print 'this is the timestamp ', get_tstamp_from_folder(f)

    ro_array = ['positive', 'negative']
    x, y, y_u = get_pos_neg_data(a, adwindata_str='', ro_array=ro_array, **kw)
    y = np.round(y, decimals=2)
    y_u = np.round(y_u, decimals=2)
    # print el,x,y,y_u ### for debugging

    data = [0, 0, 0]
    ### put output string together
    for jj, res, res_u in zip(range(3), y, y_u):
        data[jj] = cp.deepcopy(str(res) + " +/- " + str(res_u))

    row_format = "{:>18}" * (len(x))

    headline_format = "{:>18}" * len(x)
    print headline_format.format(*x)
    print "-------------------------------------------------------------------------"
    print row_format.format(*data)
Esempio n. 6
0
def compile_xy_values_of_datasets(f_list, ssro_tstamp='112128', **kw):
    """
    besides returning all msmt values this function also returns 
    one data object in case one wants to review msmt params.
    """

    if ssro_tstamp == None:
        ssro_calib_folder = tb.latest_data('SSROCalib')
    else:
        ssro_dstmp, ssro_tstmp = tb.verify_timestamp(ssro_tstamp)
        ssro_calib_folder = tb.latest_data(ssro_tstmp)

    x = []
    y = []
    y_u = []
    for f in f_list:
        a = mbi.MBIAnalysis(f)
        a.get_sweep_pts()
        a.get_readout_results(name='adwindata')
        a.get_electron_ROC(ssro_calib_folder)

        x.extend(a.sweep_pts.reshape(-1))
        y.extend(a.p0.reshape(-1))
        y_u.extend(a.u_p0.reshape(-1))

    return x, y, y_u, a
Esempio n. 7
0
def load_mult_dat(tau, number_of_msmts, N_steps=4,ssro_calib_folder=''):
  cum_pts = 0
  for kk in range(number_of_msmts):
    folder = toolbox.latest_data(contains=str(tau), older_than='140424')
    # print folder
    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='measurement'+ str(kk))
    a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder)
    cum_pts += a.pts
       
    pts         = 11
    N_start    = (kk+0)     * (pts-1)*N_steps 
    N_end      = (kk+1+0) * (pts-1)*N_steps
    N_list     = np.linspace(N_start, N_end, pts)

    if kk == 0:
        cum_sweep_pts = np.linspace(N_start, N_end, 11)#a.sweep_pts
        cum_p0 = a.p0
        cum_u_p0 = a.u_p0
    else:
        cum_sweep_pts = np.concatenate((cum_sweep_pts, np.linspace(N_start,N_end,11)))
        cum_p0 = np.concatenate((cum_p0, a.p0))
        cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0))


  a.pts   = cum_pts
  a.sweep_pts = cum_sweep_pts
  a.p0    = cum_p0
  a.u_p0  = cum_u_p0

  return a, folder
Esempio n. 8
0
def epulse_fidelity(folder, ax, *args):
    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC()
    a.plot_results_vs_sweepparam(ax=ax, name='adwindata')

    x = a.sweep_pts.reshape(-1)[:]
    y = a.p0.reshape(-1)[:]

    of = fit.Parameter(args[0], 'of')
    fitfunc_str = '(1-of)'

    def fitfunc_fid(x):
        return (1. - of())

    fit_result = fit.fit1d(x,
                           y,
                           None,
                           p0=[of],
                           fitfunc=fitfunc_fid,
                           fitfunc_str=fitfunc_str,
                           do_print=True,
                           ret=True)
    plot.plot_fit1d(fit_result,
                    np.linspace(x[0], x[-1], 201),
                    ax=ax,
                    plot_data=False,
                    print_info=False)

    return fit_result
def load_mult_dat(timestamp):
   cum_pts = 0
   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()
       cum_pts += a.pts

       if kk == 0:
           cum_sweep_pts = a.sweep_pts
           cum_p0 = a.p0
           cum_u_p0 = a.u_p0
       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))

   a.pts   = cum_pts
   a.sweep_pts = cum_sweep_pts
   a.p0    = cum_p0
   a.u_p0  = cum_u_p0

   return a
Esempio n. 10
0
def fit_linear(folder, ax, value, *args):
    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC()
    a.plot_results_vs_sweepparam(ax=ax, name='adwindata')

    x = a.sweep_pts.reshape(-1)[:]
    y = a.p0.reshape(-1)[:]

    a = fit.Parameter(args[0], 'a')
    b = fit.Parameter(args[0], 'b')
    fitfunc_str = 'a x + b'

    def fitfunc(x):
        return a() * x + b()

    fit_result = fit.fit1d(x,
                           y,
                           None,
                           p0=[a, b],
                           fitfunc=fitfunc,
                           fitfunc_str=fitfunc_str,
                           do_print=True,
                           ret=True)
    plot.plot_fit1d(fit_result,
                    np.linspace(x[0], x[-1], 201),
                    ax=ax,
                    plot_data=False,
                    print_info=False)

    return fit_result
Esempio n. 11
0
def fit_population_vs_detuning(folder, ax, *args):
    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC(
    )  # a.get_N_ROC(0.97,0.03,0.96,0.01,0.93,0.01)#(0.99, 0.02, 0.94, 0.005)
    ax = a.plot_results_vs_sweepparam(ret='ax', name='adwindata')

    x = a.sweep_pts.reshape(-1)[:]
    y = a.p0.reshape(-1)[:]

    guess_a = 1
    guess_A = -0.8
    guess_F = 0.005
    guess_x0 = args[0]

    fit_result = fit.fit1d(x,
                           y,
                           rabi.fit_population_vs_detuning,
                           guess_a,
                           guess_A,
                           guess_F,
                           guess_x0,
                           fixed=[],
                           do_print=True,
                           ret=True)
    plot.plot_fit1d(fit_result,
                    np.linspace(a.sweep_pts[0], a.sweep_pts[-1], 201),
                    ax=ax,
                    plot_data=False)

    return fit_result
Esempio n. 12
0
def load_mult_dat(timestamp, 
      number_of_msmts,
      x_axis_start    = 2.0,
      x_axis_step     = 1.0,
      x_axis_pts_per_msmnt= 101,   
      ssro_calib_folder =''):
   ''' 
   function to load and combine multiple msmts. 
   '''
   cum_pts = 0
   for kk in range(number_of_msmts):
       folder = toolbox.data_from_time(timestamp)
       a = mbi.MBIAnalysis(folder)
       a.get_sweep_pts()
       a.get_readout_results(name='measurement' + str(kk))
       a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder)
       cum_pts += a.pts

       if kk == 0:
           cum_sweep_pts = np.linspace(x_axis_start, x_axis_start+x_axis_step, x_axis_pts_per_msmnt)#a.sweep_pts
           cum_p0 = a.p0
           cum_u_p0 = a.u_p0
       else:
           cum_sweep_pts = np.concatenate((cum_sweep_pts, np.linspace(x_axis_start+kk*x_axis_step, x_axis_start+(kk+1)*x_axis_step, x_axis_pts_per_msmnt)))
           cum_p0 = np.concatenate((cum_p0, a.p0))
           cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0))

   a.pts   = cum_pts
   a.sweep_pts = cum_sweep_pts
   a.p0    = cum_p0
   a.u_p0  = cum_u_p0

   return a, folder
Esempio n. 13
0
def get_CR_histos(
    contains='',
    timestamp=None,
):
    if timestamp != None:
        folder = toolbox.data_from_time(timestamp)
    else:
        folder = toolbox.latest_data(contains)

    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC()

    before, after = a.get_CR_before_after()

    fig = plt.figure()
    ax = plt.subplot()
    ax.hist(before,
            abs(max(before) - min(before) + 1),
            normed=True,
            label='before')
    ax.hist(after,
            abs(max(after) - min(after) + 1),
            normed=True,
            label='after')
    ax.set_title(a.default_plot_title)
    ax.set_xlabel('counts during CR check')
    ax.set_ylabel('probability')
    plt.legend()

    plt.show()
    plt.close('all')
Esempio n. 14
0
def fast_pi2():
    folder = toolbox.latest_data('cal_fast_pi_over_2')

    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC()
    #a.plot_results_vs_sweepparam(ax=ax, name='adwindata')

    x = a.sweep_pts
    y = a.p0.reshape(-1)
    u_y = a.u_p0.reshape(-1)
    n = a.sweep_name

    x2 = x[::2]
    y2 = y[1::2] - y[::2]
    u_y2 = np.sqrt(u_y[1::2]**2 + u_y[::2]**2)

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharex=True)
    ax1.errorbar(x2, y2, yerr=u_y2, fmt='o')
    ax1.set_xlabel(n)
    ax1.set_title('Difference btw. Pi/2-Pi and Pi/2' + '\n' + a.timestamp)
    ax1.set_ylabel('Difference')

    m = fit.Parameter((y[-1] - y[0]) / (x[-1] - x[0]), 'm')
    x0 = fit.Parameter(x2.mean(), 'x0')
    p0 = [m, x0]

    def ff(x):
        return m() * (x - x0())

    fitfunc_str = 'm * (x - x0)'

    fit_result = fit.fit1d(x2,
                           y2,
                           None,
                           p0=p0,
                           fitfunc=ff,
                           fitfunc_str=fitfunc_str,
                           do_print=True,
                           ret=True)

    ax2.errorbar(x2, y[0::2], yerr=u_y[0::2], fmt='o', label='Pi/2')
    ax2.errorbar(x2, y[1::2], yerr=u_y[1::2], fmt='o', label='Pi/2 - Pi')
    ax2.legend(frameon=True, framealpha=0.5)
    ax2.set_ylabel('P(0)')
    ax2.set_xlabel(n)
    if fit_result != False:
        ax2.axvline(x0(), c='k', lw=2)
        ax2.axhline(0.5, c='k', lw=2)
        ax2.set_title('X marks the spot')

        plot.plot_fit1d(fit_result,
                        np.linspace(x2[0], x2[-1], 201),
                        ax=ax1,
                        plot_data=False,
                        print_info=True)

    return x0(), 0
Esempio n. 15
0
def get_and_plot_data_nuc_RO(timestamp_list_pos, timestamp_list_neg, ssro_calib_folder):

    for ii, timestamp in enumerate(timestamp_list_pos):

        folder = toolbox.data_from_time(timestamp)
        a = mbi.MBIAnalysis(folder)
        a.get_sweep_pts()
        a.get_readout_results(name='adwindata')
        a.get_electron_ROC(ssro_calib_folder)
        a.x    = a.sweep_pts.reshape(-1)[:]
        a.sweep_pts = range(len(a.p0))

        folder = toolbox.data_from_time(timestamp_list_neg[ii])
        b = mbi.MBIAnalysis(folder)
        b.get_sweep_pts()
        b.get_readout_results(name='adwindata')
        b.get_electron_ROC(ssro_calib_folder)

        ### Combine positive/negative data
        a.p0 = ( (2*a.p0-1) - (2*b.p0-1))/2.
        a.u_p0 =  (a.u_p0**2 + a.u_p0**2)**0.5

        # if ii==0:
        #     ax = a.plot_results_vs_sweepparam(ret='ax', markersize = 4, save=False, fmt = 'o')
        #     ax.set_ylim(-1.05,1.05)
        #     ax.set_xlim(a.sweep_pts[0]-0.1,a.sweep_pts[-1]+0.1)
        #     ax.axhspan(0,1,fill=False,ls='dotted')
        #     ax.axhspan(-1,0,fill=False,ls='dotted')
        # else:
        #     a.plot_results_vs_sweepparam(ax= ax,  markersize = 4, save=False, fmt = 'o')
        #     ax.set_ylim(-1.05,1.05)

        if ii==0:
            p0_sum     = a.p0
            u_p0_sum   = a.u_p0**2
        else:
            p0_sum     = p0_sum + a.p0
            u_p0_sum   = u_p0_sum + a.u_p0**2

    a.p0   = p0_sum/len(timestamp_list_pos)
    a.u_p0 = (u_p0_sum**0.5) / len(timestamp_list_pos)

    a.p0   = a.p0.reshape(-1)[:]
    a.u_p0 = a.u_p0.reshape(-1)[:]
    return a, folder
def get_RO_results(folder, ssro_calib_folder):
    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC(ssro_calib_folder)
    y_a = ((a.p0.reshape(-1)[:]) - 0.5) * 2
    y_err_a = 2 * a.u_p0.reshape(-1)[:]

    return y_a, y_err_a
def get_data(name_contains,
             input_timestamp=None,
             input_id=None,
             ssro_calib_folder=''):
    '''
	Retrieves msmt data for a SINGLE loop in SimpleDecoupling, i.e. 'tot' = 1.
	Inputs: 
	- String containing an element of the file name
	- (Optional): timestamp. Default is latest data 

	Returns:
	- 'x': array with sweeped parameter values
	- 'y': array with msmt outcomes (corrected for SSRO fidelity)
	- 'yerr': array with msmt errors
	- 'folder': path of data file
	- (optional)'timestamp': timestamp corresponding to data. Returned by default unless a timestamp is specified
	- (optional) 'ssro_calib_folder': path of the corresponding ssro calibration file. If '', latest calibration is used 
	'''

    if input_timestamp != None:
        folder = toolbox.data_from_time(input_timestamp)
    else:
        timestamp, folder = toolbox.latest_data(name_contains,
                                                return_timestamp=True)
    a = mbi.MBIAnalysis(folder)

    #print 'DATA FOLDER & SSRO FOLDER:'
    #print folder

    #ax = a.plot_results_vs_sweepparam(ret='ax', )

    # Retrieve data & reshape
    if input_id != None:
        name = 'measurement' + str(input_id)
        adwingrp = a.adwingrp(name=name)
        a.adgrp = adwingrp
        sweep = a.adgrp.attrs['sweep_pts']
        x = sweep.reshape(-1)[:]
        a.get_readout_results(name=name)
        a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder)
        y = a.p0.reshape(-1)[:]
        yerr = a.u_p0.reshape(-1)[:]
    else:
        a.get_sweep_pts()
        a.get_readout_results(name='measurement0')
        a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder)
        x = a.sweep_pts.reshape(-1)[:]
        y = a.p0.reshape(-1)[:]
        yerr = a.u_p0.reshape(-1)[:]

    if input_timestamp != None:
        return x, y, yerr, folder
    else:
        return x, y, yerr, folder, timestamp
Esempio n. 18
0
def analyse_pulse_calibration(angle='_pi_1', timestamp=None, guess_x0=None):
    ### parameters
    if guess_x0 == None:
        if angle == '_pi_1':
            guess_x0 = 0.38
        elif angle == '_pi_o':
            guess_x0 = 0.24
        elif angle == '_pi_p1':
            guess_x0 = 0.67
            angle = '_pi_1'
        else:
            guess_x0 = 0.5
    msmt_type = 'sequence'

    guess_of = 0.973
    guess_a = 0.

    ### script
    if timestamp != None:
        folder = toolbox.data_from_time(timestamp)
    else:
        folder = toolbox.latest_data(angle)

    if msmt_type == 'sequence':
        a = sequence.SequenceAnalysis(folder)
        a.get_sweep_pts()
        a.get_readout_results('ssro')
        a.get_electron_ROC()
        ax = a.plot_result_vs_sweepparam(ret='ax')

        x = a.sweep_pts
        y = a.p0

    elif msmt_type == 'mbi':
        a = mbi.MBIAnalysis(folder)
        a.get_sweep_pts()
        a.get_readout_results(name='adwindata')
        a.get_electron_ROC()
        ax = a.plot_results_vs_sweepparam(name='adwindata', ret='ax')
        ax.set_ylim(-0.1, 1)

        x = a.sweep_pts.reshape(-1)[:]
        y = a.p0.reshape(-1)[:]

    else:
        raise Exception('Unknown msmt type')

    res = funcs.calibrate_pulse_amplitude(x, y, ax, guess_x0, guess_of,
                                          guess_a)
    plt.savefig(os.path.join(folder, 'pulse_calibration.pdf'), format='pdf')
    plt.savefig(os.path.join(folder, 'pulse_calibration.png'), format='png')
Esempio n. 19
0
def calibrate_epulse_rabi(folder, ax, *args, **kws):
    fit_x0 = kws.pop('fit_x0', True)
    fit_k = kws.pop('fit_k', True)
    double_ro = kws.pop('double_ro', 'False')
    guess_x0 = kws.pop('guess_x0', 0)

    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC()
    a.plot_results_vs_sweepparam(ax=ax, name='adwindata')

    x = a.sweep_pts.reshape(-1)[:]
    if double_ro == 'electron':
        y = a.p0[:, 0]
    elif double_ro == 'nitrogen':
        y = a.p0[:, 1]
    else:
        y = a.p0.reshape(-1)[:]

    f = fit.Parameter(args[0], 'f')
    A = fit.Parameter(args[1], 'A')
    x0 = fit.Parameter(guess_x0, 'x0')
    k = fit.Parameter(0, 'k')
    p0 = [f, A]
    if fit_x0:
        p0.append(x0)
    if fit_k:
        p0.append(k)

    fitfunc_str = '(1 - A) + A * exp(-kx) * cos(2pi f (x - x0))'

    def fitfunc(x):
        return (1.-A()) + A() * np.exp(-k()*x) * \
            np.cos(2*np.pi*f()*(x - x0()))

    fit_result = fit.fit1d(x,
                           y,
                           None,
                           p0=p0,
                           fitfunc=fitfunc,
                           fitfunc_str=fitfunc_str,
                           do_print=True,
                           ret=True)
    plot.plot_fit1d(fit_result,
                    np.linspace(x[0], x[-1], 201),
                    ax=ax,
                    plot_data=False,
                    print_info=False)

    return fit_result
Esempio n. 20
0
def get_data(name_contains):
    folder = toolbox.latest_data(name_contains)
    print folder
    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='measurement0')
    a.get_electron_ROC()
    #ax = a.plot_results_vs_sweepparam(ret='ax', )

    t_shift = 0
    # t_start=0
    # t_0=10

    x = a.sweep_pts.reshape(-1)[:]
    y = a.p0.reshape(-1)[:]
    return x, y, folder
Esempio n. 21
0
def fingerprint_loop(older_than=None,
                     newer_than=None,
                     contains='',
                     number=0,
                     filename='loop'):
    fig = figure(number, figsize=(10, 5))
    ax = fig.add_subplot(111)
    histdata_1521 = []
    histdata_1531 = []
    # ssro_calib_folders = ['d:\\measuring\\data\\20140504\\070533_AdwinSSRO_SSROCalibration_Hans_sil1']

    ## Data location ##
    while toolbox.latest_data(contains=contains,
                              older_than=older_than,
                              newer_than=newer_than,
                              raise_exc=False) != False:
        timestamp, folder = toolbox.latest_data(contains=contains,
                                                older_than=older_than,
                                                newer_than=newer_than,
                                                return_timestamp=True)
        ssro_calib_folder = toolbox.latest_data(
            contains='AdwinSSRO_SSROCalibration', older_than='20140502193810')
        ## Data location ##
        a = mbi.MBIAnalysis(folder)
        a.get_sweep_pts()
        a.get_readout_results(name='adwindata')
        a.get_electron_ROC(ssro_calib_folder)

        # ############
        # ## Plotting ###
        # # ############
        #     print folder
        x = a.sweep_pts.reshape(-1)[:]
        y = a.p0.reshape(-1)[:]
        y_error = a.u_p0.reshape(-1)[:]
        # ax.errorbar(x,y,y_error)
        older_than = str(int(timestamp) - 1)

        idx_1521 = np.argmin(abs(x - 15.21))
        idx_1531 = np.argmin(abs(x - 15.31))

        if y[idx_1521] < 0.8:
            histdata_1521.append(y[idx_1521])
            histdata_1531.append(y[idx_1531])
            ax.errorbar(x, y, y_error)
        print y_error
Esempio n. 22
0
def simple_plot(timestamp=None,
                measurement_name=['adwindata'],
                folder_name='CarbonPiCal',
                ssro_calib_timestamp=None,
                save=True,
                plot_fit=True):
    '''
	Function that makes a bar plot with errorbars of MBI type data 
	'''
    if timestamp == None:
        timestamp, folder = toolbox.latest_data(folder_name,
                                                return_timestamp=True)
    else:
        folder = toolbox.data_from_time(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_111_1_sil8'
        print ssro_calib_folder

    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC(ssro_calib_folder)

    x_labels = a.sweep_pts.reshape(-1)
    y = ((a.p0.reshape(-1)) - 0.5) * 2
    x = range(len(y))
    y_err = 2 * a.u_p0.reshape(-1)

    fig, ax = plt.subplots()
    rects = ax.errorbar(x, y, yerr=y_err)
    ax.set_xticks(x)
    ax.set_xticklabels(x_labels.tolist(), rotation=90)
    ax.set_ylim(-1.1, 1.1)
    ax.set_title(str(folder) + '/' + str(timestamp))
    ax.hlines([-1, 0, 1], x[0] - 1, x[-1] + 1, linestyles='dotted')

    if save and ax != None:
        try:
            fig.savefig(os.path.join(folder, 'simple_plot.png'))
        except:
            print 'Figure has not been saved.'
Esempio n. 23
0
def el_to_c_swap(contains='', input_el=['Z'], do_fit=False, **kw):
    '''
    gets data from a folder whose name contains the contains variable.
    Does or does not fit the data with a gaussian function
    '''

    ### folder choice
    if contains == '':
        contains = 'Swap_el_to_C'

    # older_than = kw.get('older_than',None) automatically handled by kws
    ### acquire data
    f = toolbox.latest_data(contains, **kw)
    a = mbi.MBIAnalysis(f)
    print 'this is the timestamp ', get_tstamp_from_folder(f)

    # data = np.empty([3,len(input_el)],dtype=str)
    data = []
    for i in range(len(input_el)):
        data.append([0, 0, 0])
    for ii, el in enumerate(input_el):
        # data.append([0,0,0])
        data_strings = []
        ro_str = 'el_state_' + el + '_'

        ro_array = ['positive', 'negative']
        x, y, y_u = get_pos_neg_data(a,
                                     adwindata_str=ro_str,
                                     ro_array=ro_array,
                                     **kw)
        y = np.round(y, decimals=2)
        y_u = np.round(y_u, decimals=2)
        # print el,x,y,y_u ### for debugging

        ### put output string together
        for jj, res, res_u in zip(range(3), y, y_u):
            data[ii][jj] = cp.deepcopy(str(res) + " +/- " + str(res_u))

    row_format = "{:>18}" * (len(x) + 1)
    headline_format = "{:>12}" + "{:>18}" * len(x)
    print headline_format.format("", *x)
    for el, row in zip(input_el, data):
        print "--------------------------------------------------------------------------------------------------"
        print row_format.format(el + ' |', *row)
Esempio n. 24
0
def get_PosNeg_data(name, **kw):

    ssro_calib_timestamp = kw.pop('ssro_calib_timestamp', None)
    older_than = kw.pop('older_than', None)

    data_dict = {'folders': [], 'sweep_pts': [], 'res': [], 'res_u': []}

    for ro in ['positive', 'negative']:
        search_string = ro + name
        data_dict['folders'].append(
            toolbox.latest_data(contains=search_string,
                                older_than=older_than,
                                raise_exc=False))

    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_sil8'
        # print ssro_calib_folder
    for i, f in enumerate(data_dict['folders']):
        a = mbi.MBIAnalysis(f)
        a.get_sweep_pts()
        a.get_readout_results(name='adwindata')
        a.get_electron_ROC(ssro_calib_folder)

        x_labels = a.sweep_pts.reshape(-1)
        if i == 0:
            data_dict['res'] = ((a.p0.reshape(-1)) - 0.5) * 2
            data_dict['res_u'] = 2 * a.u_p0.reshape(-1)
        else:
            y = ((a.p0.reshape(-1)) - 0.5) * 2
            y_u = 2 * a.u_p0.reshape(-1)
            data_dict['res'] = [
                y0 / 2 - y[ii] / 2 for ii, y0 in enumerate(data_dict['res'])
            ]
            data_dict['res_u'] = [
                np.sqrt(y0**2 + y_u[ii]**2) / 2
                for ii, y0 in enumerate(data_dict['res_u'])
            ]

    return x_labels, data_dict['res'], data_dict['res_u'], data_dict[
        'folders'][0]
Esempio n. 25
0
def fingerprint(timestamp=None,
                measurement_name=['adwindata'],
                show_guess=True):
    ''' Function to analyze simple fingerprint measurements. 
    Inputs:
    timestamp: in format yyyymmdd_hhmmss or hhmmss or None.
    measurement_name: list of measurement names
    '''

    if timestamp != None:
        folder = toolbox.data_from_time(timestamp)
    else:
        folder = toolbox.latest_data('DecouplingSequence')

    fit_results = []
    for k in range(0, len(measurement_name)):
        a = mbi.MBIAnalysis(folder)
        a.get_sweep_pts()
        a.get_readout_results(measurement_name[k])
        a.get_electron_ROC()
        ax = a.plot_results_vs_sweepparam(ret='ax')

        x = a.sweep_pts.reshape(-1)[:]
        y = a.p0.reshape(-1)[:]

        # p0, fitfunc, fitfunc_str = common.fit_decaying_cos(frequency,offset, amplitude, phase, decay_constant)

        #plot the initial guess
        # 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=True, ret=True,fixed=[3])

        # ## plot data and fit as function of total time
        # if plot_fit == True:
        #     plot.plot_fit1d(fit_result, np.linspace(0,x[-1],201), ax=ax, plot_data=False)

        # fit_results.append(fit_result)

        plt.savefig(os.path.join(folder, 'analyzed_result.pdf'), format='pdf')
        plt.savefig(os.path.join(folder, 'analyzed_result.png'), format='png')

    return
Esempio n. 26
0
def Zeno_get_2Q_values(timestamp=None,
                       folder=None,
                       folder_name='Zeno',
                       measurement_name=['adwindata'],
                       ssro_calib_timestamp=None):
    """
	Returns the relevant RO values for a given timestamp.
	"""

    if timestamp == None and folder == None:
        timestamp, folder = toolbox.latest_data(folder_name,
                                                return_timestamp=True)
    elif timestamp == None and folder != None:
        pass
    else:
        folder = toolbox.data_from_time(timestamp)

    if folder != None and timestamp == None:
        d, t = toolbox.get_date_time_string_from_folder(folder)
        timestamp = toolbox.timestamp_from_datetime(t)
    ### SSRO calibration
    if ssro_calib_timestamp == None:
        ssro_calib_folder = toolbox.latest_data('SSRO', older_than=timestamp)

    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'

    if 'Evotime' in folder:
        c1ms0 = float(
            folder[114:])  ##assign the frequency from the folder name
    else:
        c1ms0 = float(folder[-8:])
    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC(ssro_calib_folder)

    x_labels = a.sweep_pts.reshape(-1)
    y = ((a.p0.reshape(-1)) - 0.5) * 2
    y_err = 2 * a.u_p0.reshape(-1)

    return x_labels, c1ms0, y, y_err
Esempio n. 27
0
def calibrate_epulse_amplitude(folder, ax, *args, **kw):
    double_ro = kw.pop('double_ro', 'False')

    a = mbi.MBIAnalysis(folder)
    a.get_sweep_pts()
    a.get_readout_results(name='adwindata')
    a.get_electron_ROC()
    a.plot_results_vs_sweepparam(ax=ax, name='adwindata')

    x = a.sweep_pts.reshape(-1)[:]
    if double_ro == 'electron':
        y = a.p0[:, 0]
    elif double_ro == 'nitrogen':
        y = a.p0[:, 1]
    else:
        y = a.p0.reshape(-1)[:]

    x0 = fit.Parameter(args[0], 'x0')
    of = fit.Parameter(args[1], 'of')
    a = fit.Parameter(args[2], 'a')
    fitfunc_str = '(1-of) + a (x-x0)**2'

    def fitfunc_parabolic(x):
        return (1. - of()) + a() * (x - x0())**2

    fit_result = fit.fit1d(x,
                           y,
                           None,
                           p0=[of, a, x0],
                           fitfunc=fitfunc_parabolic,
                           fitfunc_str=fitfunc_str,
                           do_print=True,
                           ret=True)
    plot.plot_fit1d(fit_result,
                    np.linspace(x[0], x[-1], 201),
                    ax=ax,
                    plot_data=False,
                    print_info=False)

    return fit_result
def load_mult_dat_tag(tag,
                      older_than,
                      number_of_msmts,
                      ssro_calib_folder='',
                      start=3.0,
                      pts=51,
                      step_size=10e-3):
    cum_pts = 0
    for kk in range(number_of_msmts):
        folder = toolbox.latest_data(contains=tag,
                                     older_than=older_than,
                                     folder='d:\measuring\data')
        a = mbi.MBIAnalysis(folder)
        a.get_sweep_pts()
        a.get_readout_results(name='measurement' + str(kk))
        a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder)
        cum_pts += a.pts

        # print a.reps

        if kk == 0:
            cum_sweep_pts = np.linspace(start, start + (pts - 1) * step_size,
                                        pts)
            cum_p0 = a.p0
            cum_u_p0 = a.u_p0
        else:
            cum_sweep_pts = np.concatenate(
                (cum_sweep_pts,
                 np.linspace(
                     start + kk * (pts - 1) * step_size, start +
                     (pts - 1) * step_size + kk * (pts - 1) * step_size, pts)))
            cum_p0 = np.concatenate((cum_p0, a.p0))
            cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0))

    a.pts = cum_pts
    a.sweep_pts = cum_sweep_pts
    a.p0 = cum_p0
    a.u_p0 = cum_u_p0

    return a, folder
Esempio n. 29
0
def load_mult_dat(timestamp, ssro_calib_folder='', data_folder=None):
    ''' 
  function to load and combine multiple msmts. 
  '''
    cum_pts = 0
    kk = 0
    while True:
        folder = toolbox.data_from_time(timestamp, folder=data_folder)
        a = mbi.MBIAnalysis(folder)
        a.get_sweep_pts()
        try:
            a.get_readout_results(name='measurement' + str(kk))
        except:
            print 'found no more data, stopping the loop after {} datasets'.format(
                kk)
            break
        a.get_electron_ROC(ssro_calib_folder=ssro_calib_folder)
        cum_pts += a.pts

        if kk == 0:
            cum_p0 = a.p0
            cum_u_p0 = a.u_p0
        else:
            cum_p0 = np.concatenate((cum_p0, a.p0))
            cum_u_p0 = np.concatenate((cum_u_p0, a.u_p0))
        kk += 1

    print 'Number of datasets is', kk

    step = a.sweep_pts[-1] - a.sweep_pts[0]
    pts_per_msmt = len(a.sweep_pts)
    x_axis_start = a.sweep_pts[-1] - step * (kk)
    cum_sweep_pts = np.linspace(x_axis_start, a.sweep_pts[-1], cum_pts)

    a.pts = cum_pts
    a.sweep_pts = cum_sweep_pts
    a.p0 = cum_p0
    a.u_p0 = cum_u_p0

    return a, folder
Esempio n. 30
0
def tomo_analysis(contains="tomo", name="", **kw):
    # older_than = kw.get('older_than',None) automatically handled by kws
    ### acquire data
    f = toolbox.latest_data(contains, **kw)
    a = mbi.MBIAnalysis(f)

    ro_array = ['positive', 'negative']
    x, y, y_u = get_pos_neg_data(a,
                                 adwindata_str=name,
                                 ro_array=ro_array,
                                 **kw)
    x = ["".join(bases) for bases in x]

    xlabel = a.g.attrs['sweep_name']
    ylabel = "Expectation value"

    fig, ax = create_plot(f,
                          xlabel=xlabel,
                          ylabel=ylabel,
                          title='Delay feedback + tomography')

    fake_x = np.arange(len(x))
    rects = ax.bar(fake_x, y, yerr=y_u, align='center', ecolor='k')
    ax.set_xticks(fake_x)
    ax.set_xticklabels(x)
    ax.set_ylim(-1.0, 1.0)

    def autolabel(rects):
        for ii, rect in enumerate(rects):
            height = rect.get_height()
            plt.text(rect.get_x() + rect.get_width() / 2.,
                     1.02 * height,
                     str(round(y[ii], 2)) + '(' +
                     str(int(round(y_u[ii] * 100))) + ')',
                     ha='center',
                     va='bottom')

    autolabel(rects)

    save_and_close_plot(f)