Exemplo n.º 1
0
def arc_model_to_rgb(thickness, porosity, aoi=8):
    # Wavelength axis
    wavelength = np.arange(360, 801, 5).astype('float')

    # Choice of illuminant makes a very small change to the calculated RGB color.
    illuminant = 'LED-B3'

    # # Scan thickness and porosity.
    # thickness = np.arange(0, 196, 5).astype('float')
    # porosity = np.arange(0, 0.51, 0.1).astype('float')

    # col = np.zeros((3, len(thickness), len(porosity)))
    # col_hex = np.empty((len(thickness), len(porosity)), dtype='object')
    # xyY = np.zeros((3, len(thickness), len(porosity)))

    index_film = refractive_index_porous_silica(wavelength, porosity)
    index_substrate = refractive_index_glass(wavelength)

    # Calculate reflectance
    reflectance = thin_film_reflectance(index_film=index_film,
                                        index_substrate=index_substrate,
                                        film_thickness=thickness,
                                        aoi=aoi,
                                        wavelength=wavelength)
    reflectance_ref = thin_film_reflectance(index_film=index_film,
                                            index_substrate=index_substrate,
                                            film_thickness=0,
                                            aoi=aoi,
                                            wavelength=wavelength)

    rgb = spectrum_to_rgb(wavelength, reflectance, illuminant=illuminant)
    rgb_ref = spectrum_to_rgb(wavelength,
                              reflectance_ref,
                              illuminant=illuminant)

    # White balance
    rgb_wb = rgb / rgb_ref

    # Clamp
    rgb_wb[rgb_wb >= 1] = 1
    rgb_wb[rgb_wb < 0] = 0

    return rgb_wb
Exemplo n.º 2
0
    def arc_model_c(wavelength, thickness, fraction_abraded, fraction_dust,
                    porosity):
        index_film = refractive_index_porous_silica(wavelength=wavelength,
                                         porosity=porosity)

        index_substrate = refractive_index_glass(wavelength=wavelength)
        thin_film_R = thin_film_reflectance(
            index_film=index_film,
            index_substrate=index_substrate,
            film_thickness=thickness,
            wavelength=wavelength,
            aoi=aoi
        )
        #
        # thin_film_R = thin_film_reflection_fast(
        #     wavelength=wavelength,
        #     thickness=thickness,
        #     aoi=aoi,
        #     porosity=porosity)

        #
        # index_film = index_porous_silica(wavelength=wavelength,
        #                                  porosity=porosity)
        # thin_film_reflectance = thin_film_reflection(
        #     polarization='mixed',
        #     wavelength=wavelength,
        #     d_list=[np.inf, thickness, np.inf],
        #     index_film=index_film,
        #     index_substrate=index_glass,
        #     aoi=aoi)

        glass_reflectance = np.interp(wavelength, wavelength_calc,
                                      glass_reflectance_calc)

        reflectance = (1 - fraction_dust) * (
                fraction_abraded * glass_reflectance + (
                1 - fraction_abraded) * thin_film_R) + fraction_dust

        return 100 * reflectance
Exemplo n.º 3
0
film_thickness = 120
polarization = 'mixed'

start_time = time()
R_tmm = thin_film_reflectance_tmm(index_film=index_film,
                                  index_substrate=index_substrate,
                                  film_thickness=film_thickness,
                                  aoi=aoi,
                                  wavelength=wavelength,
                                  polarization=polarization)
time_tmm = time() - start_time
print('Elapsed time for TMM method: {:.5f} s'.format(time_tmm))
start_time = time()
R_explicit = thin_film_reflectance(index_film=index_film,
                                   index_substrate=index_substrate,
                                   film_thickness=film_thickness,
                                   aoi=aoi,
                                   wavelength=wavelength,
                                   polarization=polarization)
time_explicit = time() - start_time
print('Elapsed time for explicit method: {:.5f} s'.format(time_explicit))
print('Speed up: {:0.0f}x'.format(time_tmm / time_explicit))

max_error = np.max(np.abs(R_explicit - R_tmm))
print('Max error: {}'.format(max_error))

if max_error < 1e-10:
    print('Test passed.')

# # Plot data
# plt.figure(0)
# plt.clf()
wavelength = np.linspace(200, 1250, 200)

# Integration limits for SWPR
swpr_wavelength_min = 400
swpr_wavelength_max = 1100

for k in tqdm(range(len(porosity))):

    index_film = refractive_index_porous_silica(wavelength, porosity[k])
    index_substrate = refractive_index_glass(wavelength)

    for j in range(len(thickness)):
        # Calculate reflectance at rough.
        reflectance = thin_film_reflectance(index_film=index_film,
                                            index_substrate=index_substrate,
                                            film_thickness=thickness[j],
                                            aoi=8,
                                            wavelength=wavelength)

        swpr[j, k] = solar_weighted_photon_reflectance(
            wavelength,
            reflectance,
            wavelength_min=swpr_wavelength_min,
            wavelength_max=swpr_wavelength_max)

power_enhancement = swpr[0, 0] - swpr

plt.figure(6, figsize=(3.7, 3))
plt.clf()
plt.contourf(thickness,
             porosity * 100,
Exemplo n.º 5
0
def arc_reflection_model(wavelength,
                         thickness=125,
                         fraction_abraded=0,
                         porosity=0.3,
                         fraction_dust=0,
                         aoi=8,
                         n0=1.0003):
    """
    Return the reflection values for a model of an aged ARC. The reflection
    is a linear combination of reflection from a thin film of a variable
    thickness and the reflection from BK7 glass.

    Parameters
    ----------
    wavelength : ndarray

        wavelength in nm

    thickness

        thickness of ARC in nm.

    fraction_abraded

        fraction of coating loss. 1 corresponds to 100% of the coating area
        removed and only underlying glass is present, 0 corresponds to the
        coating covering the entire sample.

    fraction_dust

        fraction of module area covered by dust with reflectivity of 1. A
        value of 0 corresponds to no dust (clean sample), 1 to full dust
        coverage (reflectivity of 1).

    aoi

        angle of incidence in degrees.

    Returns
    -------

    reflectance : ndarray

        Reflectance of sample at the values of wavelength specified.

    """

    index_substrate = refractive_index_glass(wavelength)
    index_film = refractive_index_porous_silica(wavelength, porosity=porosity)
    glass_reflectance = single_interface_reflectance(
        n0=n0,
        n1=index_substrate,
        polarization='mixed',
        aoi=aoi)

    thin_film_R = thin_film_reflectance(index_film=index_film,
                                        index_substrate=index_substrate,
                                        film_thickness=thickness,
                                        aoi=aoi,
                                        wavelength=wavelength)

    reflectance = (1 - fraction_dust) * (
            fraction_abraded * glass_reflectance + (
            1 - fraction_abraded) * thin_film_R) + fraction_dust

    return reflectance
Exemplo n.º 6
0
def calculate_rgb_vs_thickness_porosity(
        camera='Ximea-MC050cg_combined_labeled.csv',
        light_source='LEDW7E_A01_intensity.csv',
        optical_system='MVL23M23.csv',
        thickness_max=186,
        thickness_step=0.4,
        porosity_max=0.5,
        porosity_step=0.01,
        aoi=0):
    # Wavelength axis
    wavelength = np.arange(300, 755, 5).astype('float')
    dwavelength = wavelength[1] - wavelength[0]

    # Scan thickness and porosity.
    thickness = np.arange(0, thickness_max, thickness_step).astype('float')
    porosity = np.arange(0, porosity_max, porosity_step).astype('float')

    # Initialize arrays.
    swpr = np.zeros((len(thickness), len(porosity)))
    rgb_wb = np.zeros((len(thickness), len(porosity), 3))

    # Load Camera QE
    qe_fpath = os.path.join(os.path.dirname(__file__), 'cameras',
                            camera)
    df = pd.read_csv(qe_fpath, skiprows=2)
    dfi = pd.DataFrame({'Wavelength': wavelength})
    for k in ['Red', 'Green', 'Blue']:
        dfi[k] = np.interp(wavelength, df['Wavelength'], df[k],
                           left=0, right=0)

    # Load Illuminant spectrum
    illum_fpath = os.path.join(os.path.dirname(__file__), 'sources',
                               light_source)
    df_illum = pd.read_csv(illum_fpath, skiprows=2)
    # illuminant_sd = ILLUMINANTS_SDS[sources[s]]
    # illuminant_conv = ILLUMINANTS['CIE 1931 2 Degree Standard Observer'][illuminant_name]

    illuminant_spectrum = np.interp(wavelength, df_illum['Wavelength'],
                                    df_illum['Intensity'], left=0, right=0)

    illuminant_spectrum_photon = illuminant_spectrum * wavelength

    # Load optical system
    optical_system_fpath = os.path.join(os.path.dirname(__file__), 'cameras',
                                        optical_system)
    df_optical_system = pd.read_csv(optical_system_fpath, skiprows=2)
    optical_system_transmission = 0.01 * np.interp(
        wavelength,
        df_optical_system['Wavelength'],
        df_optical_system['Transmission'],
        left=0, right=0)

    # Calculate RGB colors
    for k in tqdm(range(len(porosity))):

        index_film = refractive_index_porous_silica(wavelength, porosity[k])
        index_substrate = refractive_index_glass(wavelength)

        for j in range(len(thickness)):

            # Calculate reflectance
            reflectance = thin_film_reflectance(index_film=index_film,
                                                index_substrate=index_substrate,
                                                film_thickness=thickness[j],
                                                aoi=aoi,
                                                wavelength=wavelength)
            # for c in ['Blue', 'Green', 'Red']:
            #     np.sum(reflectance * illuminant_spectrum_photon * dfi[c] / 100) * dwavelength

            rgb = np.sum(
                reflectance[:, np.newaxis] * \
                optical_system_transmission[:, np.newaxis] * \
                illuminant_spectrum_photon[:, np.newaxis] * \
                np.array(dfi.iloc[:, 1:]) / 100,
                axis=0) * dwavelength

            swpr[j, k] = solar_weighted_photon_reflectance(wavelength,
                                                           reflectance)

            # Use first run through, with 0 nm thickness, (i.e. low-iron glass)
            # as a reference for white balance.
            if thickness[j] == 0:
                rgb_ref = rgb.copy()

            # White balance
            rgb_wb[j, k, :] = rgb / rgb_ref

    # x = rgb_wb[0, :, :] / np.sum(rgb_wb, axis=0)
    # y = rgb_wb[1, :, :] / np.sum(rgb_wb, axis=0)
    # z = rgb_wb[2, :, :] / np.sum(rgb_wb, axis=0)

    # t_grid, P_grid = np.meshgrid(thickness, porosity, indexing='ij')

    return thickness, porosity, rgb_wb, swpr
    index_substrate_smooth = refractive_index_glass(wavelength_smooth)

    def smoothit(y, N=10):
        return np.convolve(y, np.ones((N, )) / N, mode='valid')

    plt.plot(smoothit(source['wavelength'][1:-200]),
             smoothit(source['value'][1:-200]) / source['value'][1:-5].max() *
             5,
             'w--',
             label='LED')

    for j in range(len(thickness_scan)):
        # Calculate reflectance at rough.
        Rmat[:, j] = thin_film_reflectance(index_film=index_film,
                                           index_substrate=index_substrate,
                                           film_thickness=thickness_scan[j],
                                           aoi=8,
                                           wavelength=wavelength)
        # Calculate
        R_smooth = thin_film_reflectance(
            index_film=index_film_smooth,
            index_substrate=index_substrate_smooth,
            film_thickness=thickness_scan[j],
            aoi=8,
            wavelength=wavelength_smooth)

        # Calculate the spectral color
        col_list = {}
        for k in range(len(wavelength)):
            if wavelength[k] >= 340 and wavelength[k] <= 830:
                col_list['spec_{:1.0f}nm'.format(wavelength[k])] = Rmat[k, j]