示例#1
0
def bias(path, show_plot, save_plot):
    #BIAS
    x = []
    y = []
    dy = []
    line = 1
    measured_values = []
    markers = ['.', ',', 'x', '+', 'v', '^', '<', '>', 's', 'd']
    plt.clf()
    plt.cla()
    with open(path + '/data/bias.csv', 'r') as csvfile:
        plots = csv.reader(csvfile, delimiter=',')
        next(csvfile)
        for row in plots:
            measured_values.append(float(row[2]))
            if line % 3 == 0:
                set_value = float(row[0])
                x.append(set_value)
                y.append(np.average(measured_values))
                dy.append(np.std(measured_values, ddof=1) / 3**0.5)
                #print([set_value,np.average(measured_values),np.std(measured_values,ddof=1)])
                measured_values = []
            line += 1
        plt.scatter(x, y)
        p, c = np.polyfit(x, y, 1, w=dy, cov=True)
        e = np.sqrt(np.diag(c))
        slope = sci_not(p[0], e[0])
        offset = sci_not(p[1], e[1])
        plt.plot(
            np.array(x),
            offset[0] * 10**offset[2] + np.array(x) * slope[0] * 10**slope[2])
        slope = sci_not(p[0], e[0], True)
        offset = sci_not(p[1], e[1], True)
        slope_str = '(' + str(slope[0]) + '\\pm' + str(slope[1]) + ')e' + str(
            slope[2]) if slope[2] != 0 else str(slope[0]) + '\\pm' + str(
                slope[1])
        offset_str = '(' + str(offset[0]) + '\\pm' + str(
            offset[1]) + ')e' + str(offset[2]) if offset[2] != 0 else str(
                offset[0]) + '\\pm' + str(offset[1])
        med_std = sci_not(dy[2] * 3**0.5, dy[2] * 3**0.5, True)
        std_str = str(med_std[0]) + 'e' + str(
            med_std[2]) if med_std[2] != 0 else str(med_std[0])
        out = '$' + slope_str + '$ & $' + offset_str + '$ & ' + std_str + '\\\\ \\hline'
        #print(out)
    plt.legend()
    plt.xlabel('Set (V)')
    plt.ylabel('Measurement (V)')
    #plt.axis([-11, 11, -0.004, 0.003])
    plt.title('Bias Output')

    if show_plot == 'y':
        plt.show()
    if save_plot == 'y':
        plt.savefig(path + '/plot/bias.png')
    if show_plot == 'n':
        print('Not showing plot')
    if save_plot == 'n':
        print('not saving plot')
    return out
示例#2
0
def current(path, ave_time, num_points, show_plot, save_plot):
    out = ''
    #CURRENT
    range_values = [1, 10, 100, 1000, 50e3]
    plt.clf()
    plt.cla()
    for range_value in range_values:
        plt.close()
        for channel in range(4):
            #channel=2
            x = []
            xo = []
            y = []
            yo = []
            dy = []
            dyo = []
            markers = [',', 'x', '+', 'v', '^', '<', '>', 's', 'd']
            line = 0
            with open(
                    path + '/data/' + ave_time + 'ms_current' + str(channel) +
                    '.csv', 'r') as csvfile:
                plots = csv.reader(csvfile, delimiter=',')
                next(csvfile)
                line += 1
                next(csvfile)
                line += 1
                for row in plots:
                    if len(row) > 1:
                        if row[5] == 'start':
                            input = float(row[0]) * (1e6)
                            mean = float(row[3])
                            std = float(row[4])
                            rng = float(row[1])
                            if rng == range_value:
                                if line % num_points < num_points:
                                    x.append(input)
                                    y.append(mean)
                                    dy.append(std / num_points**0.5)
                                if range_value != 50e3:
                                    if input < range_value:
                                        xo.append(input)
                                        yo.append(mean)
                                        dyo.append(std / num_points**0.5)
                                else:
                                    if input < range_value * 0.8:
                                        xo.append(input)
                                        yo.append(mean)
                                        dyo.append(std / num_points**0.5)
                    line += 1
            p, c = np.polyfit(xo, yo, 1, w=dyo, cov=True)
            e = np.sqrt(np.diag(c))
            slope = sci_not(p[0], e[0], True)
            offset = sci_not(p[1], e[1], True)
            #print([p[1],e[1]])
            slope_str = '(' + str(slope[0]) + '\\pm' + str(
                slope[1]) + ')e' + str(slope[2]) if slope[2] != 0 else str(
                    slope[0]) + '\\pm' + str(slope[1])
            offset_str = '(' + str(offset[0]) + '\\pm' + str(
                offset[1]) + ')e' + str(offset[2]) if offset[2] != 0 else str(
                    offset[0]) + '\\pm' + str(offset[1])
            med_std = sci_not(dyo[round(len(dyo) / 2)] * num_points**0.5,
                              dyo[round(len(dyo) / 2)] * num_points**0.5, True)
            std_str = str(med_std[0]) + 'e' + str(
                med_std[2]) if med_std[2] != 0 else str(med_std[0])
            if channel != 3:
                temp_out = str(channel) + ' & ' + str(
                    range_value
                ) + ' & $' + slope_str + '$ & $' + offset_str + '$ & ' + std_str + ' \\\\ \\hline'
                #print(temp_out)
                out += temp_out + '\n'
            else:
                temp_out = str(channel) + ' & ' + str(
                    range_value
                ) + ' & $' + slope_str + '$ & $' + offset_str + '$ & ' + std_str + ' \\\\ \\Xhline{3\\arrayrulewidth}'
                #print(temp_out)
                out += temp_out + '\n'

            slope = sci_not(p[0], e[0])
            offset = sci_not(p[1], e[1])

            plt.plot(
                np.array(x), offset[0] * 10**offset[2] +
                np.array(x) * slope[0] * 10**slope[2])
            plt.scatter(x,
                        y,
                        marker=markers[channel],
                        label='channel' + str(channel))

        plt.legend()
        plt.xlabel('Input (\u03bcA)')
        plt.ylabel('Measurement (\u03bcA)')
        plt.title('Ave. Time ' + ave_time + 'ms, ' + 'Range ' +
                  str(int(range_value)))
        if show_plot == 'y':
            plt.show()

        if save_plot == 'y':
            plt.savefig(path + '/plot/' + ave_time + 'ms_range' +
                        str(int(range_value)) + '.png')

    if show_plot == 'n':
        print('Not showing plot')
    if save_plot == 'n':
        print('not saving plot')
    return out
示例#3
0
def scan(path, axis):
    i = 0
    x = 0
    y = -1
    out = ''
    size = 401
    fluxrr_pd = []
    sensrr_d = []

    epics_arr = []
    Gs = []
    contrasts = []

    #colnames=['X', 'Y', 'Z','PD','A','B','C','D']
    #data = pd.read_csv(path+'/scan_0.005mm.csv', names=colnames, header=None)
    #print(data.describe())
    with open(path + '/scan_0.005mm.csv', 'r') as csvfile:
        plots = csv.reader(csvfile, delimiter=',')

        for row in plots:
            x_epics = float(row[0])
            y_epics = float(row[1])
            z_epics = float(row[2])
            pd = float(row[3])
            A = float(row[4]) / 1e6
            B = float(row[5]) / 1e6
            C = float(row[6]) / 1e6
            D = float(row[7]) / 1e6
            sum = A + B + C + D

            #calculate the flux from the photodiode
            flux_pd = pd * 1e9 / 266.4e-9
            #append the flux measurement got from a pixel and append to a list
            fluxrr_pd.append(flux_pd)
            #calculate the sensitivity of diamond detector
            sens_d = 0.99122 * sum * 266.4e-9 / pd
            #append value to list
            sensrr_d.append(sens_d)

            #append all position data into a list and calculate the contrasts at each pixel
            if axis == 'z':
                epics_arr.append(z_epics)
                G = (z_epics) * sum / ((C + D) - (A + B))
                Gs.append(G)
                contrasts.append(((C + D) - (A + B)) / (A + B + C + D))
            elif axis == 'x':
                epics_arr.append(x_epics)
                G = (x_epics) * sum / ((A + D) - (B + C))
                Gs.append(G)
                contrasts.append(((A + D) - (B + C)) / sum)

            i += 1

    #calculate the mean flux from photodiode and sensitivty of diamond
    flux_pd = np.mean(fluxrr_pd)
    sens_d = np.mean(sensrr_d)
    #print them out
    print('pd flux: ' + str(flux_pd) + ' +/- ' +
          str(np.std(fluxrr_pd) / (len(fluxrr_pd)**0.5)))
    print('diamond sensitivity: ' + str(sens_d) + ' +/- ' +
          str(np.std(sensrr_d) / (len(sensrr_d)**0.5)))

    epics_sqr_arr = []
    contrasts_sqr = []

    #slice 1 dimensional array into 2 dimensional array by rows
    for i in range(size):
        epics_sqr_arr.append(epics_arr[i * size:(i + 1) * size])
        contrasts_sqr.append(contrasts[i * size:(i + 1) * size])

    if axis == 'z':
        #rotate matrix so it's sliced by columns
        epics_sqr_arr = np.rot90(epics_sqr_arr)
        contrasts_sqr = np.rot90(contrasts_sqr)
    #no need to do this for the x arrays because it's already sliced by rows which is what we want

    epics_sqr_arr_cropped = []
    contrasts_sqr_cropped = []

    #set offset for every column
    limits = 0.5
    for i in range(size):
        offset = 0
        for j in range(size):
            if contrasts_sqr[i][j] < limits and contrasts_sqr[i][
                    j] > -1 * limits:

                offset = epics_sqr_arr[i][j] + 0.003
                #print(offset)
                break
        epics_sqr_arr[i] = np.array(epics_sqr_arr[i]) - offset

    #crop z data and align
    for i in range(len(epics_sqr_arr)):
        epics_sqr_arr_cropped.append([])
        contrasts_sqr_cropped.append([])
        count = 0
        for j in range(len(epics_sqr_arr[i])):
            #lim=0.1001
            lim = 0.1001
            if epics_sqr_arr[i][j] > -1 * lim and epics_sqr_arr[i][j] < 1 * lim:
                epics_sqr_arr_cropped[i].append(epics_sqr_arr[i][j])
                contrasts_sqr_cropped[i].append(contrasts_sqr[i][j])
        epics_sqr_arr_cropped[i] = np.array(epics_sqr_arr_cropped[i])
        contrasts_sqr[i] = np.array(contrasts_sqr[i])

    epics_arr_average = []
    contrasts_average = []
    contrasts_stds = []
    #create 1 dimensional array of each row averaged
    epics_sqr_arr_cropped_temp = np.rot90(epics_sqr_arr_cropped, 3)
    contrasts_sqr_cropped_temp = np.rot90(contrasts_sqr_cropped, 3)
    for i in range(len(epics_sqr_arr_cropped_temp)):
        limits = 0.015
        if np.median(
                epics_sqr_arr_cropped_temp[i]) >= -1 * limits and np.median(
                    epics_sqr_arr_cropped_temp[i]) <= limits:
            epics_arr_average.append(np.median(epics_sqr_arr_cropped_temp[i]))
            contrasts_average.append(np.mean(contrasts_sqr_cropped_temp[i]))

            contrasts_stds.append(np.std(contrasts_sqr_cropped_temp[i]))
    #create color gradient
    color = []
    half = int(size / 2)
    for i in range(half):
        color.append((i / half, 0, 50 / 255, 0.1))
    for i in range(size - half):
        color.append((1, float(i) / (size - half), 50 / 255, 0.1))

    #plot each column
    for i in range(size):
        plt.scatter(np.array(epics_sqr_arr_cropped[i]),
                    contrasts_sqr_cropped[i],
                    c=color[i])
    plt.scatter(epics_arr_average, contrasts_average, c='blue')

    p, c = np.polyfit(epics_arr_average,
                      contrasts_average,
                      1,
                      w=contrasts_stds,
                      cov=True)
    e = np.sqrt(np.diag(c))
    #print([p,c,e])
    #print([p[0],e[0]])

    slope = sci_not(p[0], e[0], True)
    offset = sci_not(p[1], e[1], True)
    slope_str = '(' + str(slope[0]) + '+/-' + str(slope[1]) + ')e' + str(
        slope[2]) if slope[2] != 0 else str(slope[0]) + '+/-' + str(slope[1])

    slope = sci_not(p[0], e[0])
    offset = sci_not(p[1], e[1])
    plt.plot(np.array(epics_arr_average),
             offset[0] * float(10)**offset[2] +
             np.array(epics_arr_average) * slope[0] * float(10)**slope[2],
             label='Gz: ' + slope_str)
    #plt.scatter(np.array(x_epics_sqr_arr[i])-25.05,x_contrasts_sqr[i],c=color[i])
    labels = None
    if axis == 'z':
        labels = ('Gz', 'Z')
    elif axis == 'x':
        labels = ('Gx', 'X')
    print(labels[0] + ': ' + slope_str)
    plt.xlabel(labels[1] + " position (mm)")
    plt.ylabel(labels[1] + " contrast")
    plt.legend()
    plt.show()
示例#4
0
            measured_values.append(float(row[1]))
            if line % 3 == 0:
                set_value=float(row[0])
                x.append(set_value)
                y.append(np.average(measured_values))
                dy.append(np.std(measured_values,ddof=1)/3**0.5)
                #print([set_value,np.average(measured_values),np.std(measured_values,ddof=1)])
                measured_values=[]
            line+=1
        plt.scatter(x,y, marker=markers[channel],label='channel'+str(channel))
        #plt.errorbar(x,y,yerr=dy,fmt='none', marker=markers[channel],label='channel'+str(channel))
        p, c = np.polyfit(x, y, 1, w=dy, cov=True)
        e = np.sqrt(np.diag(c))
        #print([p,c,e])
        #print([p[0],e[0]])
        slope=sci_not(p[0],e[0])
        offset=sci_not(p[1],e[1])
        plt.plot(np.array(x),offset[0]*float(10)**offset[2]+np.array(x)*slope[0]*float(10)**slope[2])
        slope=sci_not(p[0],e[0],True)
        offset=sci_not(p[1],e[1],True)
        slope_str= '('+str(slope[0])+'\\pm'+str(slope[1])+')e'+str(slope[2]) if slope[2] != 0 else str(slope[0])+'\\pm'+str(slope[1])
        offset_str= '('+str(offset[0])+'\\pm'+str(offset[1])+')e'+str(offset[2]) if offset[2] != 0 else str(offset[0])+'\\pm'+str(offset[1])
        med_std=sci_not(dy[2]*3**0.5,dy[2]*3**0.5,True)
        std_str= str(med_std[0])+'e'+str(med_std[2]) if med_std[2] != 0 else str(med_std[0])
        print(str(channel)+' & $'+slope_str+'$ & $'+offset_str+'$ & '+std_str+'\\\\ \\hline')

plt.legend()
plt.xlabel('Set (V)')
plt.ylabel('Measurement (V)')
#plt.axis([-11, 11, -0.004, 0.003])
plt.title('DAC Output')
示例#5
0
                                y.append(mean)
                                dy.append(std/num_points**0.5)
                            if range_value!=50e3:
                                if input < range_value:
                                    xo.append(input)
                                    yo.append(mean)
                                    dyo.append(std/num_points**0.5)
                            else:
                                if input < range_value*0.8:
                                    xo.append(input)
                                    yo.append(mean)
                                    dyo.append(std/num_points**0.5)
                line+=1
        p, c = np.polyfit(xo, yo, 1, w=dyo, cov=True)
        e = np.sqrt(np.diag(c))
        slope=sci_not(p[0],e[0],True)
        offset=sci_not(p[1],e[1],True)
        #print([p[1],e[1]])
        slope_str= '('+str(slope[0])+'\\pm'+str(slope[1])+')e'+str(slope[2]) if slope[2] != 0 else str(slope[0])+'\\pm'+str(slope[1])
        offset_str= '('+str(offset[0])+'\\pm'+str(offset[1])+')e'+str(offset[2]) if offset[2] != 0 else str(offset[0])+'\\pm'+str(offset[1])
        med_std=sci_not(dyo[round(len(dyo)/2)]*num_points**0.5,dyo[round(len(dyo)/2)]*num_points**0.5,True)
        std_str= str(med_std[0])+'e'+str(med_std[2]) if med_std[2] != 0 else str(med_std[0])
        if channel!=3:
            print(str(channel)+' & '+str(range_value)+' & $'+slope_str+'$ & $'+offset_str+'$ & '+std_str+' \\\\ \\hline')
        else:
            print(str(channel)+' & '+str(range_value)+' & $'+slope_str+'$ & $'+offset_str+'$ & '+std_str+' \\\\ \\Xhline{3\\arrayrulewidth}')
        #\\\\ \\Xhline{3\\arrayrulewidth}

        slope=sci_not(p[0],e[0])
        offset=sci_not(p[1],e[1])