コード例 #1
0
def fit_linewidth(folder=None, threshold=0.01, delta=0.03, **kw):

    print folder
    show_plots = kw.pop(
        'show_plots', True
    )  #if the keyword show_plots exists, set to the given value, otherwise default is True
    a = cga.cavity_analysis(folder)
    print a.f
    a.get_x_pts()  #the x points of the laser of voltage scan
    a.get_data()

    #x_datas contains nr_repetitions copies of a.x_pts
    x_datas = np.full((a.nr_scans, len(a.x_pts)), a.x_pts)

    single_scan_lw = np.zeros(a.nr_scans)
    u_single_scan_lw = np.zeros(a.nr_scans)

    #new_delays = np.zeros(len(a.sweep_pts)*len(a.nr_scans))
    name = ''  #reps_0_1_10_11_20_21_30_31_40_41'

    print a.nr_scans
    print x_datas
    print a.data

    for i in np.arange(a.nr_scans):
        single_scan_lw[i], u_single_scan_lw[i] = cf.fit_piezo_plots(
            folder,
            x_datas[i],
            a.data[i],
            show_plots=True,
            threshold=threshold,
            averaging=False)

    return single_scan_lw, u_single_scan_lw  #SvD: you want to return not the index i, but the whole array
コード例 #2
0
def lengthscan_analysis(folder, **kw):
    do_get_peaks = kw.pop('do_get_peaks', False)

    a = cga.cavity_analysis(folder)
    x, y = a.get_lengthscan_data()

    fig, ax = plt.subplots()
    ax.set_title(folder)
    ax.set_xlabel('length tuning voltage (V)')
    ax.set_ylabel('PD signal (V)')
    plt.plot(x, y)

    if do_get_peaks:
        minimum_peak_height = kw.pop('minimum_peak_height',
                                     0.4 * max(a.y_data))
        minimum_peak_distance = kw.pop('minimum_peak_distance', 60)
        a.peak_xs = np.array([])
        a.peak_ys = np.array([])

        indices = peakdetect.detect_peaks(a.y_data,
                                          mph=minimum_peak_height,
                                          mpd=minimum_peak_distance)

        for ii in indices:
            a.peak_xs = np.append(a.peak_xs, a.x_data[ii])
            a.peak_ys = np.append(a.peak_ys, a.y_data[ii])

        ax.plot(a.peak_xs, a.peak_ys, '+', mfc=None, mec='r', mew=2, ms=8)

    fig.savefig(a.folder + '/PDsignal_vs_length_tuning_voltage.png')
    plt.show()

    a.finish()

    if do_get_peaks:
        return a.peak_xs
コード例 #3
0
def fit_3_lorentzians(indexmax,
                      date,
                      g_a1,
                      g_A1,
                      g_x01,
                      g_gamma1,
                      g_dx,
                      g_A2,
                      folder=None,
                      fixed=[],
                      threshold=0.01,
                      delta=0.03,
                      **kw):
    print folder
    show_plots = kw.pop(
        'show_plots', True
    )  #if the keyword show_plots exists, set to the given value, otherwise default is True
    a = cga.cavity_analysis(folder)
    print a.f
    a.get_x_pts()  #the x points of the laser of voltage scan
    a.get_data()

    #x_datas contains nr_repetitions copies of a.x_pts
    #x_datas = np.full((a.nr_scans,len(a.x_pts)),a.x_pts)

    single_scan_lw = np.zeros(a.nr_scans)
    u_single_scan_lw = np.zeros(a.nr_scans)

    #new_delays = np.zeros(len(a.sweep_pts)*len(a.nr_scans))
    name = ''  #reps_0_1_10_11_20_21_30_31_40_41'

    #Now we check to see that we have the correct voltage and amplitude points.
    #    print a.x_pts
    #    print a.data

    #We want to analyze only one of the peaks that pops up for the linewidth. So we select a portion of the data and do the analysis on this
    #First we have to find the length of the data
    print('Length of Data')
    print len(a.x_pts)

    #The entire range of the data
    x = a.x_pts
    y = a.data[0]
    print len(x)
    print len(y)

    #Plot the entire range of the data
    fig, ax = plt.subplots(figsize=(14, 8))
    ax.plot(x, y)
    ax.set_xlabel("Voltage (V)]", fontsize=14)
    ax.set_ylabel("Intensity (a.u.)", fontsize=14)

    ax.set_title('Raw' + filename + date)
    plt.savefig(os.path.join(folder, filename + '_' + date + '.png'))

    #Selecting one peak of the data for the proper fit
    #indexmax=y.argmax(axis=0)
    #print indexmax
    #indexmax=30
    dataleft = indexmax - (0.05 * len(x))
    dataright = indexmax + (0.05 * len(x))
    x = x[dataleft:dataright]
    y = y[dataleft:dataright]
    print len(x)
    print len(y)

    #x = 1.e3*np.a.x_pts[0]#[3000:] # multiplied by factor 1.e3  to get ms
    #y = np.a#[3000:]

    #Plot just one of the peaks
    fig, ax = plt.subplots(figsize=(8, 4))
    ax.plot(x, y)
    ax.set_xlabel("Voltage (V)]", fontsize=14)
    ax.set_ylabel("Intensity (a.u.)", fontsize=14)
    #ax.set_xlim(x[0],x[-1])
    #X_min_freq = g_x01-ax.get_xlim()[0]
    #X_max_freq = g_x01+ax.get_xlim()[-1]
    #xticklabels = np.linspace(X_min_freq,X_max_freq,n_xticks)
    #ax.set_xticks(xticks)

    ax.set_title('Select Data' + filename + date)
    plt.savefig(
        os.path.join(folder, filename + 'Select Data' + '_' + date + '.png'))

    print 'fitting data to 3 lorentzians'
    p0, fitfunc, fitfunc_str = common.fit_3lorentz_symmetric(
        g_a1, g_A1, g_x01, g_gamma1, g_dx, g_A2)
    fit_result = fit.fit1d(x,
                           y,
                           None,
                           p0=p0,
                           fitfunc=fitfunc,
                           do_print=True,
                           ret=True,
                           fixed=fixed)

    #    # x01 = fit_result['params_dict']['x01']
    dx = fit_result['params_dict']['dx']
    gamma1 = fit_result['params_dict']['gamma1']
    #    # gamma2 = fit_result['params_dict']['gamma2']
    u_gamma1 = fit_result['error_dict']['gamma1']
    #    # u_gamma2 = fit_result['error_dict']['gamma2']

    scaling = EOM_freq / dx  #scale the known EOM freq with the separation here.
    linewidth = gamma1 * scaling  #scale the linewidth to get linewidht in frequency
    u_linewidth = u_gamma1 * scaling
    linewidth_string = 'gamma = ' + str(round(linewidth, 2)) + '+-' + str(
        round(u_linewidth, 3)) + 'GHz'
    print linewidth_string

    #Plotting

    fig, ax = plt.subplots(figsize=(8, 4))
    plot.plot_fit1d(fit_result,
                    np.linspace(x[0], x[-1], len(x)),
                    ax=ax,
                    label='Fit',
                    show_guess=True,
                    plot_data=True,
                    color='red',
                    data_linestyle='-',
                    print_info=False)
    ax.set_xlabel("Frequency [GHz]", fontsize=14)
    ax.set_ylabel("Intensity (a.u.)", fontsize=14)
    ax.set_xlim(x[0], x[-1])
    print ax.set_xlim(x[0], x[-1])
    xticks = np.linspace(ax.get_xlim()[0], ax.get_xlim()[-1], n_xticks)
    #rescaling for x-axis in GHz
    X_min_freq = ax.get_xlim()[0] * scaling
    X_max_freq = ax.get_xlim()[-1] * scaling
    print g_x01 * scaling
    print X_min_freq
    print X_max_freq
    print scaling

    xticklabels = np.linspace(X_min_freq, X_max_freq, n_xticks)

    xticklabels_round = []
    for j in xticklabels:
        round_ = round(j, 3)
        xticklabels_round = np.append(xticklabels_round, round_)

    ax.set_xticks(xticks)
    ax.set_xticklabels(xticklabels_round)

    ax.set_title('Fitted' + filename + date + '\n' + linewidth_string)
    plt.savefig(os.path.join(folder, filename + '_' + date + '_fit.png'))
コード例 #4
0
def fit_sweep_msync_delays(folder = tb.latest_data('141702'),threshold=0.01,delta=0.05):
    a = cga.cavity_analysis(folder)
    print a.f
    a.get_x_pts() #the x points of the laser of voltage scan
    a.get_sweep_pts() #the sweep points  (here: delays)
    a.get_sweep_data()

    #x_datas contains nr_repetitions copies of a.x_pts
    x_datas = np.full((a.nr_repetitions,len(a.x_pts)),a.x_pts)  

    selected_reps = np.arange(a.nr_repetitions)#np.array([0,5,10,15])#np.arange(a.nr_repetitions)#np.array([0,1,10,11,20,21,30,31,40,41]) #

    avg_lws = np.zeros(len(a.sweep_pts))
    u_avg_lws = np.zeros(len(a.sweep_pts))
    peak_range=np.zeros([len(a.sweep_pts),len(selected_reps)])
    nr_peaks=np.zeros([len(a.sweep_pts),len(selected_reps)])
 
    #new_delays = np.zeros(len(a.sweep_pts)*len(a.nr_scans))
    name = ''#reps_0_1_10_11_20_21_30_31_40_41'


    for i,pt in enumerate(a.sweep_pts):
        for j,rep in enumerate(selected_reps):
            peak_range[i,j],nr_peaks[i,j]=cf.determine_peak_range(folder,a.sweep_data[i,j],a.x_pts,delta,tag=str(pt)+'_'+str(rep),show_plot=False)

    avg_peak_range = np.average(peak_range,axis=1)
    u_avg_peak_range = np.std(peak_range,axis=1)
    avg_nr_peaks = np.average(nr_peaks,axis=1)
    u_avg_nr_peaks = np.std(nr_peaks,axis=1)


    print avg_peak_range
    print u_avg_peak_range

    print avg_nr_peaks
    print u_avg_nr_peaks

    #plot and save peak range vs sync delay
    fig,ax = plt.subplots(figsize=(6,4.7))
    ax.errorbar(a.sweep_pts, avg_peak_range, fmt='o', yerr=u_avg_peak_range)
    # ax.legend()
    ax.set_xlabel('sync delay (ms)',fontsize=14)
    ax.set_ylabel('average peak range (V)',fontsize=14)
    ax.tick_params(axis = 'both', which = 'major',labelsize = 14)
    ax.set_xlim(a.sweep_pts[0],a.sweep_pts[-1])
    ax.set_ylim(0,max(avg_peak_range)+max(u_avg_peak_range))

    ax.set_title(folder +'\n'+'peakrange_vs_delays'+name )

    fig.savefig(folder +'/'+'peakrange_vs_delays'+name+'.png')
    plt.show()
    plt.close()


    #plot and save nr peaks vs sync delay
    fig,ax = plt.subplots(figsize=(6,4.7))
    ax.errorbar(a.sweep_pts, avg_nr_peaks, fmt='o', yerr=u_avg_nr_peaks)
    # ax.legend()
    ax.set_xlabel('sync delay (ms)',fontsize=14)
    ax.set_ylabel('average nr peaks',fontsize=14)
    ax.tick_params(axis = 'both', which = 'major',labelsize = 14)
    ax.set_xlim(a.sweep_pts[0],a.sweep_pts[-1])
    ax.set_ylim(0,max(avg_nr_peaks)+max(u_avg_nr_peaks))

    ax.set_title(folder +'\n'+'nrpeaks_vs_delays'+name)

    fig.savefig(folder +'/'+'nrpeaks_vs_delays'+name+'.png')
    plt.show()
    plt.close()

    #closed the file
    a.finish()

    return avg_peak_range, u_avg_peak_range, avg_nr_peaks, u_avg_nr_peaks