Esempio n. 1
0
def estimate_arc_reflection_model_params(wavelength, reflectance, porosity=0.1,
                                         wavelength_min=450,
                                         wavelength_max=1000):
    # Smooth.
    # N = 5
    # reflectance = np.convolve(reflectance, np.ones((N,)), mode='same') / N

    cax = np.logical_and(wavelength > wavelength_min,
                         wavelength < wavelength_max)
    idx_min_reflection = np.argmin(reflectance[cax])

    reflection_min = reflectance[cax][idx_min_reflection]
    wavelength_min_reflection = wavelength[cax][idx_min_reflection]
    n = refractive_index_porous_silica(wavelength_min_reflection, porosity=0.5)
    thickness_estimate = 0.25 * wavelength_min_reflection / n

    # thickness_estimate = 120

    reflection_from_arc = float(
        arc_reflection_model(np.array([wavelength_min_reflection]),
                             thickness_estimate,
                             fraction_abraded=0,
                             fraction_dust=0,
                             porosity=porosity))
    reflection_from_glass = float(
        arc_reflection_model(np.array([wavelength_min_reflection]),
                             thickness_estimate,
                             fraction_abraded=1,
                             fraction_dust=0,
                             porosity=porosity))

    # print('Reflection from glass: {}'.format(reflection_from_glass))
    # print('Reflection from arc: {}'.format(reflection_from_arc))
    # print('Reflection from sample: {}'.format(reflection_min))

    fraction_abraded = (reflection_min - reflection_from_arc) / (
            reflection_from_glass - reflection_from_arc)

    # if thickness_estimate < 135:
    #     thickness_estimate = 135
    return {'thickness': thickness_estimate,
            'fraction_abraded': float(fraction_abraded),
            'fraction_dust': 0.001,
            'porosity': porosity
            }
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
reflectance.

toddkarin
09/10/2020
"""

import numpy as np
from time import time

from pvarc.materials import refractive_index_glass, refractive_index_porous_silica
from pvarc.tmm import thin_film_reflectance_tmm
from pvarc import thin_film_reflectance

wavelength = np.linspace(200, 1250, 2000)
index_substrate = refractive_index_glass(wavelength)
index_film = refractive_index_porous_silica(wavelength)
aoi = 8
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,
    refractive_index_glass
from pvarc.metrics import solar_weighted_photon_reflectance

# Set thickness and porosity values.
thickness = np.arange(0, 196, 5).astype('float')
porosity = np.arange(0, 0.51, 0.025).astype('float')
swpr = np.zeros((len(thickness), len(porosity)))
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)
Esempio n. 6
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
Esempio n. 7
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
# Coating thickness to plot.
thickness_scan = np.array([0, 20, 40, 60, 80, 100, 120, 140, 160])
# aoi_scan = np.arange(70,-1,-10)
# aoi_scan = np.array([0,10,20,30,40,50,60,70])

for porosity in [0.15, 0.3]:

    plt.figure(0, figsize=(3.7, 3))
    plt.clf()
    ax = plt.axes()
    rect = ax.patch
    rect.set_facecolor('k')

    Rmat = np.zeros((len(wavelength), len(thickness_scan)))
    index_film = refractive_index_porous_silica(wavelength, porosity)
    index_film_smooth = refractive_index_porous_silica(wavelength_smooth,
                                                       porosity)
    index_substrate = refractive_index_glass(wavelength)
    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)):