def make_thermal_coefficients(temperature_initial_date, temp_file, int_file, name, initial_cut=40, flasher=False, decimals=3):
    """

    :param temperature_initial_date:    initial timestamp for temperature, taken manually from ClimPilot
    :param temp_file:                   path to the file for the temperature
    :param int_file:                    path to the file for the current or intensity
    :param name:                        name of the event
    :return:
    """
    temperature_array = [25., 20., 15., 10., 5.]

    temperature, temperature_time, temperature_timestamp = read_file(temp_file, 'temp', temperature_initial_date)
    x, y, current, current_std, current_time, current_timestamp = read_file(int_file, 'time')
    statistic, systematic, total_error = comp.calculate_errors(current, current_std)

    new_time, new_current, new_current_errors, new_temperature = comp.give_matched_arrays(
        temperature_time=temperature_time, temperature=temperature, current_time=current_time, current=current,
        current_std=total_error, initial_cut=initial_cut)
    if flasher:
        mask, long_mask = comp.make_mask(temperature=new_temperature, cut=70)
    else:
        mask, long_mask = comp.make_mask(temperature=new_temperature)

    means, mean_errors, mean_error_prop = comp.compute_masked_values(mask_array=mask, current=new_current,
                                                                     current_error=new_current_errors)

    ax = mydp.plot_masked_intensity_and_temperature(mask_array=mask, time=new_time, current=new_current,
                                                    current_error=new_current_errors, temperature=new_temperature,
                                                    means=means, error_propagation=mean_error_prop, decimals=decimals, axes=None)
    figure_name = './Output/Thermal_Coefficients/{}_{}.png'.format(name, 'masked_intensity_and_temperature')
    plt.savefig(figure_name)

    ax1, ax2 = mydp.plot_full_intensity_and_temperature_vs_time(temperature_time=temperature_time,
                                                                temperature=temperature, current_time=current_time,
                                                                current=current, current_std=current_std,
                                                                initial_cut=50, axes=None)
    figure_name = './Output/Thermal_Coefficients/{}_{}.png'.format(name, 'full_intensity_and_temperature')
    plt.savefig(figure_name)

    tdf, rdf, rdf_error = comp.compute_relative_difference(current=means, current_error=mean_error_prop, temperature_array=temperature_array)
    slope, slope_error, intersect, intersect_error = comp.interpolate_thermal_coefficient(tdf, rdf)
    mean_slope, error_prop_slope, mean_intersect, error_prop_intersect = comp.get_thermal_coefficient(current_at_temperature=means,
                                                                                                      current_error_at_temperature=mean_error_prop,
                                                                                                      temperature_array=temperature_array)

    axes_array = mydp.plot_slope_for_thermal_coefficient(tdf=tdf, rdf=rdf, rdf_error=rdf_error, slopes=slope,
                                                         slopes_error=slope_error, intersects=intersect,
                                                         intersects_error=intersect_error, name=name, temperature_array=temperature_array, axes=None)

    coefficient = mean_slope * 100
    error = error_prop_slope * 100

    print(name)
    print('Thermal Coefficient: {} ± {}'.format(coefficient, error))

    return coefficient, error
Beispiel #2
0
def make_surface_homogeneity(path_to_the_file):
    """"""
    """ folder and plot_name came from one component of a file list which is a string type, divided into 2 strings """
    folder = path_to_the_file.split("/")[0]
    filename = path_to_the_file.split("/")[1]
    plot_name = filename.split('.')[0]

    x, y, current, current_std, current_time, current_timestamp = read_file(
        file, 'space')
    mat_current, mat_current_std = comp.create_data_grid(current,
                                                         current_std,
                                                         steps,
                                                         rel_label=True)
    """ interpolate matrix """
    interpolated_current = comp.interpolate_data_points(
        mat_current, points_array=[301, 301], interpolation='linear')
    """ make gaussian interpolation from interpolated data """
    params, fitted_gaus = comp.fit_2d_gaussian(interpolated_current,
                                               points_array=[300, 300])
    """ plot raw data """
    ax1 = mydp.plot_intensity_scan_xy_2D(mat_current, data_label=False)
    """ plot camera centered at x,y found by gaussian interpolation """
    mydp.draw_camera(axes=ax1,
                     linestyle='-',
                     linewidth=0.5,
                     camera_centre=[params[1], params[2]])
    """ Plot intensity contour from gauss interpolation """
    mydp.plot_intensity_contour(axes=ax1, data=fitted_gaus)
    """ Plot intensity contour from gauss interpolation """
    # mydp.plot_intensity_contour(axes=ax1, data=mat_current)

    ax1.text(0.95,
             0.75,
             """
            $x_{centre}^{camera}$ : %.1f mm
            $y_{centre}^{camera}$ : %.1f mm
            $\sigma_x$ : %.1f mm
            $\sigma_y$ : %.1f mm """ %
             (params[1], params[2], params[3], params[4]),
             fontsize=10,
             color='white',
             horizontalalignment='right',
             verticalalignment='bottom',
             transform=ax1.transAxes)

    ax1.set_xticks(np.linspace(xo, xf, steps))
    ax1.set_yticks(np.linspace(yo, yf, steps))

    plt.savefig(
        output_dir +
        '/Homogeneity/{}/Homogeneity_{}_relative_cnt_gaussian.png'.format(
            folder, plot_name),
        bbox_inches='tight')
Beispiel #3
0

# Getting the desired photo-sensitivity for the peak wavelength (1st approximation)
ph_wavelength, photosensitivity = read_pindiode_photo_sensitivity()

ph_wavelength_smooth = np.linspace(ph_wavelength.min(), ph_wavelength.max(), 1000)
photosensitivity_smooth = spline(ph_wavelength, photosensitivity, ph_wavelength_smooth)

pin_diode_wavelength = ph_wavelength_smooth[68]
pin_diode_pde = photosensitivity_smooth[68]

plt.plot(ph_wavelength_smooth, photosensitivity_smooth)
plt.xlabel("wavelength [nm]")
plt.ylabel("Photosensitivity [A/W]")

x, y, current, current_std, current_time, current_timestamp = read_file(path_to_file=file_flash, scan_type='time')

systematic_err = comp.calculate_systematic_error(current)
statistic_err = comp.calculate_statistic_error(current_std)

total_err = np.sqrt(systematic_err**2 + statistic_err**2)

factor = pin_diode_pde * illuminated_area
scaling = 1e-6 # to go to micro Watts

irradiance = (current / factor) / scaling
irradiance_err = (total_err[0] / factor) / scaling

initial_bin = 80
final_bin = 350
Beispiel #4
0
def plot_stability_in_time(file_list, rel_label):
    # file_list     : list of file paths
    # rel_label     : Boolean (True : compute relative intensity wrt the maximum -  False : just the absolute intensity)

    fig, ax = plt.subplots()
    xfmt = md.DateFormatter('%Y/%m/%d %H:%M:%S')
    ax.xaxis.set_major_formatter(xfmt)

    for i, file in enumerate(file_list):
        # folder and plot_name came from one component of a file list which is a string type, divided into 2 strings
        folder = file.split("/")[0]
        filename = file.split("/")[1]
        plot_name = filename.split('.')[0]

        x, y, current, current_std, timestamp = readout.read_file(
            file, 'space')

        if rel_label:
            string = 'relative'
            axis_label = 'Relative Intensity [%]'
            rel_current = current / np.max(current)
            error_ratio = current_std / current
            index_of_max = np.argmax(current)
            delta_rel_current = rel_current * np.sqrt(
                error_ratio**2 + error_ratio[index_of_max]**2)

            rel_current *= np.array(100)
            delta_rel_current *= np.array(np.abs(100))

            current = rel_current
            current_std = delta_rel_current
        else:
            string = 'absolute'
            axis_label = 'Intensity [nA]'

        plt.plot(timestamp,
                 current,
                 'k-',
                 linewidth='0.5',
                 label=plot_name,
                 color=xkcd_colors[i])
        plt.fill_between(timestamp,
                         current - current_std,
                         current + current_std,
                         color=xkcd_colors[i])

        del x, y, current, current_std, timestamp

    plt.ylabel(axis_label)
    plt.legend(bbox_to_anchor=(0, 1.10, 1, 0.2),
               loc="lower left",
               mode='expand',
               ncol=4,
               fontsize=10)
    plt.xlabel('Time')
    plt.title('Intensity in time : {}'.format(folder))
    plt.setp(ax.get_xticklabels(),
             rotation=45,
             ha="right",
             rotation_mode="anchor")
    plt.savefig('./Output/{}/Current_in_Time_runs.png'.format(folder),
                bbox_inches='tight')
    plt.show()
    plt.clf()
Beispiel #5
0
def plot_mean_differences_current_vs_channel(number_of_cells, file_list,
                                             rel_label):

    # For the mean :
    cells = np.arange(0, number_of_cells, 1)
    current_matrix = np.zeros((number_of_cells, len(file_list)))
    current_std_matrix = np.zeros((number_of_cells, len(file_list)))

    for i, file in enumerate(file_list):
        x, y, current, current_std, timestamp = readout.read_file(
            file, 'space')

        # folder and plot_name came from one component of a file list which is a string type, divided into 2 strings
        folder = file.split("/")[0]
        filename = file.split("/")[1]
        plot_name = filename.split('.')[0]

        if rel_label:
            string = 'relative'
            axis_label = 'Relative Intensity [%]'
            rel_current = current / np.max(current)
            error_ratio = current_std / current
            index_of_max = np.argmax(current)
            delta_rel_current = rel_current * np.sqrt(
                error_ratio**2 + error_ratio[index_of_max]**2)

            current = rel_current * 100
            current_std = delta_rel_current * np.abs(100)

        else:
            string = 'absolute'
            axis_label = 'Intensity [nA]'

        current_matrix[:, i] = current
        current_std_matrix[:, i] = current_std

        plt.scatter(cells,
                    current,
                    linewidth='0.3',
                    label=plot_name,
                    color=xkcd_colors[i])
        del x, y, current, current_std, timestamp

    mean = current_matrix.mean(axis=1)
    mean_std = current_matrix.std(axis=1)

    plt.plot(cells, mean, 'k-', linewidth='0.5', label='mean of runs')
    plt.fill_between(cells,
                     mean - mean_std,
                     mean + mean_std,
                     color=sns.xkcd_rgb['amber'])
    plt.legend(bbox_to_anchor=(0, 1.10, 1, 0.2),
               loc="lower left",
               mode='expand',
               ncol=4,
               fontsize=8)

    plt.ylabel(axis_label)
    plt.xlabel('Cell number')
    plt.title('Pixel Stability : {}'.format(folder))
    plt.savefig('./Output/{}/all_{}_mean_current_vs_channels.png'.format(
        folder, string),
                bbox_inches='tight')
    plt.show()
    plt.clf()
    del string

    # For the differences :
    string = ''
    for i, file in enumerate(file_list):
        x, y, current, current_std, timestamp = readout.read_file(
            file, 'space')

        # folder and plot_name came from one component of a file list which is a string type, divided into 2 strings
        folder = file.split("/")[0]
        filename = file.split("/")[1]
        plot_name = filename.split('.')[0]

        if rel_label:
            string += 'relative'
            axis_label = 'Relative - not much meaning'
            rel_current = current / np.max(current)
            error_ratio = current_std / current
            index_of_max = np.argmax(current)
            delta_rel_current = rel_current * np.sqrt(
                error_ratio**2 + error_ratio[index_of_max]**2)

            current = rel_current * 100
            current_std = delta_rel_current * np.abs(100)

        else:
            string += 'absolute'
            axis_label = 'Relative Difference wrt Mean [%]'

        differences = ((mean - current) / mean) * np.array(100)
        plt.plot(cells,
                 differences,
                 'k-',
                 linewidth='1.',
                 label=plot_name,
                 color=xkcd_colors[i])

    plt.legend(bbox_to_anchor=(0, 1.10, 1, 0.2),
               loc="lower left",
               mode='expand',
               ncol=4,
               fontsize=8)
    plt.ylabel(axis_label)
    plt.xlabel('Cell number')
    plt.title('Pixel Stability : {}'.format(folder))
    plt.savefig(
        './Output/{}/all_{}_differences_current_vs_channels.png'.format(
            folder, string),
        bbox_inches='tight')
    plt.show()
    plt.clf()
Beispiel #6
0
measured_distance = 5.6

detector_size = [30, 30]
#xx = np.array([-450., 450.])
#yy = np.array([-600., 600.])
xx = np.array([-437, 463])
yy = np.array([-681.7, 518.3])
#x_ticks = [150, 180, 210]
#y_ticks = [30, 60, 90]
extent = [-detector_size[0]/2 + xx.min(), detector_size[0]/2 + xx.max(), -detector_size[1]/2 + yy.min(), detector_size[1]/2 + yy.max()]
steps = 11

for cnt in range(0, 12):

    x, y, flash_current, flash_current_std, flash_current_time, flash_current_timestamp = read_file(flash[cnt], 'space', initial_temperature_time=None)
    flash_stat_err = calculate_statistic_error(flash_current_std)
    flash_sys_err = calculate_systematic_error(flash_current)
    flash_current_err = np.sqrt(flash_stat_err ** 2 + flash_sys_err ** 2)

    x, y, dark_current, dark_current_std, dark_current_time, dark_current_timestamp = read_file(dark[cnt], 'space', initial_temperature_time=None)
    dark_stat_err = calculate_statistic_error(dark_current_std)
    dark_sys_err = calculate_systematic_error(dark_current)
    dark_current_err = np.sqrt(dark_stat_err ** 2 + dark_sys_err ** 2)

    result = flash_current - dark_current
    result_err = np.sqrt(flash_current_err ** 2 + dark_current_err ** 2)

    flash_current = flash_current.reshape((steps, steps)).T
    flash_current_err = flash_current_err.reshape((steps, steps)).T
Beispiel #7
0
scaling = 1

detector_size = [30, 30]
#xx = np.array([-450., 450.])
#yy = np.array([-600., 600.])
xx = np.array([-437, 463])
yy = np.array([-681.7, 518.3])
#x_ticks = [150, 180, 210]
#y_ticks = [30, 60, 90]
extent = [-detector_size[0]/2 + xx.min(), detector_size[0]/2 + xx.max(), -detector_size[1]/2 + yy.min(), detector_size[1]/2 + yy.max()]
steps = 11


for i, file in enumerate(file_2019_04_27):
    x, y, current, current_std, current_time, current_timestamp = read_file(path_to_file=file,
                                                                            scan_type='space',
                                                                            initial_temperature_time=None)
    syst_err = comp.calculate_statistic_error(current_std)
    stat_err = comp.calculate_systematic_error(current)

    total_err = np.sqrt(stat_err**2 + syst_err**2)

    # finding the max. current and its error
    index = np.argmax(current)
    max_current = current[index]
    max_current_error = total_err[0][index]
    #print('{} ± {}'.format(max_current, max_current_error))

    current_values.append(max_current)
    current_errors.append(max_current_error)
Beispiel #8
0
space_Data = [file_list2, file_list3]
space_Data = [file_list3]
for file_list in space_Data:
    for file in file_list:

        """ folder and plot_name came from one component of a file list which is a string type, divided into 2 strings """
        folder = file.split("/")[0]
        filename = file.split("/")[1]
        plot_name = filename.split('.')[0]

        amplitude_vector = []
        frequency_vector = []
        shift_vector = []
        distance_vector = []

        x, y, current, current_std, current_time, current_timestamp = read_file(path_to_file=file,
                                                                                scan_type='space')

        statistic, systematic, total = comp.calculate_errors(mean=current,
                                                             std=current_std)

        # Transform current values to irradiance values in Watts / m^2
        irradiance = current/(photosensitivity * illuminated_area)
        irradiance_error = total/(photosensitivity * illuminated_area)
        irradiance_error = total

        x_center, y_center = 0.15, 0.15
        x_label = x_position = np.linspace(xo, xf, steps)
        x_position = x_position - x_center
        y_label = y_position = np.linspace(yo, yf, steps)
        y_position = y_position - y_center
coefficient_result.append(coef)
coeff_error_result.append(err)
names.append(name)
measured_wavelengths.append(nominal_wavelength)


# For the new "improved" setup

temperature_initial_date = '03/07/2019 22:46:10'
temp_file = '2019_07_03/Clim_Pilot_thermal_405nm_30s.csv'
int_file = '2019_07_03/thermal_405nm.txt'
name = 'LED M405L3'
nominal_wavelength = 405.0

time, timestamp, internal_current, internal_current_std, external_current, external_current_std, thermoresitor_temperature = read_file_of_diodes(int_file)
chamber_temperature, chamber_temperature_time, chamber_temperature_timestamp = read_file(temp_file, 'temp', temperature_initial_date)

internal_statistic, internal_systematic, internal_total_error = comp.calculate_errors(internal_current, internal_current_std)
external_statistic, external_systematic, external_total_error = comp.calculate_errors(external_current, external_current_std)

ax1, ax2 = mydp.plot_full_intensity_and_temperature_vs_time(temperature_time=time,
                                                temperature=thermoresitor_temperature, current_time=time,
                                                current=internal_current, current_std=internal_current_std,
                                                initial_cut=0, axes=None)
ax2.set_ylabel("Internal Current [nA]")

figure_name = './Output/Thermal_Coefficients/{}_{}_internal.png'.format(name, 'full_intensity_and_temperature')
plt.savefig(figure_name)
#plt.show()

ax1, ax2 = mydp.plot_full_intensity_and_temperature_vs_time(temperature_time=time,
def yield_thermal_coefficients(temperature_initial_date,
                               temperature_file,
                               current_file,
                               source_name,
                               temperature_array=[25., 20., 15., 10., 5.],
                               initial_cut=40,
                               flasher=False,
                               decimals=3,
                               scaling=1e-6,
                               output_dir=output_dir):
    """

    :param temperature_initial_date:
    :param temperature_file:
    :param current_file:
    :param source_name:
    :param temperature_array:
    :param initial_cut:
    :param flasher:
    :param decimals:
    :param scaling:
    :return:
    """

    temperature, temperature_time, temperature_timestamp = read_file(
        temperature_file, 'temp', temperature_initial_date)
    x, y, current, current_std, current_time, current_timestamp = read_file(
        current_file, 'time')
    current_errors = comp.calculate_errors_in_thermal_range(
        current, current_std)

    irradiance, irradiance_errors = comp.transform_from_current_to_irradiance(
        current, current_errors)

    irradiance = irradiance / scaling
    irradiance_errors = irradiance_errors / scaling

    del x, y, current, current_std, current_errors

    time, irradiance, irradiance_errors, temperature = comp.give_matched_arrays(
        temperature_time=temperature_time,
        temperature=temperature,
        current_time=current_time,
        current=irradiance,
        current_std=irradiance_errors,
        initial_cut=initial_cut)

    if flasher:
        mask, long_mask = comp.make_mask(temperature=temperature, cut=50)
    else:
        mask, long_mask = comp.make_mask(temperature=temperature)

    mean, error_on_mean, error_propagation = comp.compute_masked_values(
        mask_array=mask, data=irradiance, data_error=irradiance_errors)

    ax1 = mydp.plot_masked_intensity_and_temperature(
        mask_array=mask,
        time=time,
        data=irradiance,
        data_error=irradiance_errors,
        temperature=temperature,
        means=mean,
        error_propagation=error_propagation,
        decimals=decimals,
        y_units=r'$\mu W/m^2$',
        y_label=r'E [$\mu W/m^2$]',
        axes=None)
    figure_name = output_dir + '{}_{}.png'.format(
        source_name, 'irradiance_temperature_vs_time_masked')
    plt.savefig(figure_name)

    end_cut = -55
    ax2 = mydp.plot_full_intensity_and_temperature_vs_time(
        temperature_time=time[:end_cut],
        temperature=temperature[:end_cut],
        current_time=time[:end_cut],
        current=irradiance[:end_cut],
        current_std=irradiance_errors[:end_cut],
        initial_cut=50,
        axes=None)
    figure_name = output_dir + '{}_{}.png'.format(
        source_name, 'irradiance_temperature_vs_time_unmasked')
    plt.savefig(figure_name)

    tdf, rdf, rdf_error = comp.compute_relative_difference(
        data=mean,
        data_error=error_propagation,
        temperature_array=temperature_array)

    # y = m*x + b in array because we compute for different graphs
    m_array, m_err_array, b_array, b_err_array = comp.interpolate_thermal_coefficient(
        delta_temperature=tdf, relative_differences=rdf)
    # Here we get the average of each array
    slope, slope_err, intersect, intersect_err = comp.get_thermal_coefficient(
        data_at_temperature=mean,
        data_error_at_temperature=error_propagation,
        temperature_array=temperature_array)

    for i, line in enumerate(tdf):
        x_array = np.linspace(np.min(tdf[i]), np.max(tdf[i]), 1000)
        y_array = m_array[i] * x_array + b_array[i]

        fig, ax = plt.subplots()

        ax.errorbar(x=tdf[i],
                    y=rdf[i],
                    yerr=rdf_error[i],
                    label='Relative differences\n'
                    'with respect to {}$^\circ$C'.format(temperature_array[i]),
                    fmt='o',
                    color='black',
                    ecolor=sns.xkcd_rgb['amber'],
                    elinewidth=3,
                    capsize=4,
                    ms=2,
                    fillstyle='full')

        ax.plot(x_array,
                y_array,
                color=sns.xkcd_rgb['carolina blue'],
                label='Linear fit : m $\Delta$T + b \n'
                'm = {} ± {} %/$^\circ$C \n'
                'b = {} ± {} %'.format(
                    np.around(m_array[i], decimals=decimals),
                    np.around(m_err_array[i], decimals=decimals),
                    np.around(b_array[i], decimals=decimals),
                    np.around(b_err_array[i], decimals=decimals)))
        y_label = r'$1 - \frac{E_T}{E_{(T=%2.0f ^\circ C)}}$' % (
            temperature_array[i]) + ' [%]'
        ax.set_ylabel(y_label)
        ax.set_xlabel(r'$\Delta$T [$^\circ$C]')
        ax.legend(frameon=False)
        figure_name = output_dir + '{}_slope_wrt_to_{}.png'.format(
            source_name, temperature_array[i])
        plt.savefig(figure_name)

    thermal_coefficient = slope
    thermal_coefficient_error = slope_err

    print(source_name)
    print('Thermal Coefficient: {} ± {} %/C'.format(thermal_coefficient,
                                                    thermal_coefficient_error))

    return thermal_coefficient, thermal_coefficient_error