Ejemplo n.º 1
0
def find_colour(spectrum, col_map_f='CIE 1931 2 Degree Standard Observer'):

    import colour

    cmfs = colour.MSDS_CMFS[col_map_f]
    illuminant = colour.SDS_ILLUMINANTS['D65']

    wavs = spectrum.wavelengths

    try:
        XYZ = colour.sd_to_XYZ(spectrum, cmfs, illuminant)
    except:
        XYZ = colour.sd_to_XYZ(
            spectrum.interpolate(colour.SpectralShape(min(wavs), max(wavs),
                                                      1)), cmfs, illuminant)

    RGB = colour.XYZ_to_sRGB(XYZ / 100)

    for i in range(0, 3, 1):
        if RGB[i] < 0:
            RGB[i] = 0
        if RGB[i] > 1:
            RGB[i] = 1

    return RGB
Ejemplo n.º 2
0
 def spectr_LED(abc, spd_red0, spd_green0, spd_blue0):
     sample_spd_data = {}
     a, b, c = abc[0], abc[1], abc[2]
     for lamb in np.arange(200, 800, 0.9):
         chip_3d = a * spd_red0[lamb] + b * spd_green0[
             lamb] + c * spd_blue0[lamb]
         sample_spd_data[lamb] = float(chip_3d)
     spd = colour.SpectralPowerDistribution('Sample', sample_spd_data)
     spd.interpolate(colour.SpectralShape(200, 800, 1))
     return spd
Ejemplo n.º 3
0
def open_spd(sample, name):
    sample_spd_data = {}
    with open(sample) as f:
        for iii in f:
            (key, val) = iii.split()
            key = float(key)
            val = float(val)
            key = round(key)
            val = round(val, 5)
            sample_spd_data[key] = float(val)
    spd = colour.SpectralPowerDistribution(name, sample_spd_data)
    clone_spd = spd.clone()
    clone_spd.interpolate(colour.SpectralShape(200, 800, 1))
    return clone_spd
Ejemplo n.º 4
0
def spectr_LED4(abca, spd_red0, spd_green0, spd_blue0, spd_yellow0):
    sample_spd_data = {}
    b1, b2, b3, a = abca[0], abca[1], abca[2], abca[3]
    chip_values = []
    for lamb in np.arange(200, 800, 0.9):
        chip_4d = b1 * spd_red0[lamb] + b2 * spd_green0[lamb] + b3 * spd_blue0[
            lamb] + a * spd_yellow0[lamb]
        sample_spd_data[lamb] = float(chip_4d)
        chip_values.append(chip_4d)
    max_del = max(chip_values)
    for sample in sample_spd_data:
        sample_spd_data[sample] = sample_spd_data[sample] / max_del
    spd = colour.SpectralPowerDistribution('Sample', sample_spd_data)
    spd.interpolate(colour.SpectralShape(200, 800, 1))
    return spd
def single_sd_colour_rendition_report():
    """
    Generates the *ANSI/IES TM-30-18 Colour Rendition Report*.
    """

    uploaded_file = st.sidebar.file_uploader(str())
    method = st.sidebar.selectbox('Method', ('Full', 'Intermediate', 'Simple'))
    date = st.sidebar.text_input(
        'Date', value=datetime.now().strftime("%b %d, %Y %H:%M:%S"))
    manufacturer = st.sidebar.text_input('Manufacturer', value='')
    model = st.sidebar.text_input('Model', value='')

    if uploaded_file is None:
        st.title('IES TM-30-18 Colour Rendition Report')

        st.markdown('This *Streamlit* app generates an '
                    '**ANSI/IES TM-30-18 Colour Rendition Report** using '
                    '[Colour](https://colour-science.org).')

        st.markdown(
            'Please use the sidebar to load the *CSV* file containing the '
            'light source spectral distribution.')

        return

    csv_path = tempfile.mkstemp()[1]
    with open(csv_path, 'w') as csv_file:
        csv_file.write(uploaded_file.getvalue().decode('utf-8'))

    sds = colour.read_sds_from_csv_file(csv_path)
    sd = sds[list(sds.keys())[0]]
    if sd.shape.interval not in [1, 5, 10, 20]:
        sd = sd.align(
            colour.SpectralShape(
                start=sd.shape.start, end=sd.shape.end, interval=1))

    figure, _axes = colour.plotting.plot_single_sd_colour_rendition_report(
        sd,
        method,
        date=date,
        manufacturer=manufacturer,
        model=model,
        transparent_background=False)

    st.pyplot(figure)
Ejemplo n.º 6
0
    def compute_color(self):
        self.sample_spd_data = dict(zip(self.raw_wl, self.raw_spec))
        self.spd = colour.SpectralDistribution(self.sample_spd_data,
                                               name=self.label)
        # Cloning the sample spectral power distribution.
        self.spd_interpolated = self.spd.clone()

        # Interpolating the cloned sample spectral power distribution.
        # Indeed, the algorithm for colour identification needs a spectra with a point each nanometer
        self.spd_interpolated.interpolate(colour.SpectralShape(370, 680, 1))

        self.cmfs = colour.STANDARD_OBSERVERS_CMFS[
            'CIE 1931 2 Degree Standard Observer']
        self.illuminant = colour.ILLUMINANTS_SDS['D65']
        self.XYZ = colour.sd_to_XYZ(self.spd_interpolated, self.cmfs,
                                    self.illuminant)
        self.RGB = colour.XYZ_to_sRGB(self.XYZ / 100)
        """
        We then come to the next obstacle...  The RGB values that we get from this process are often out of range - 
        meaning that they are either greater than 1.0, or even that they are negative!  The first case is fairly 
        straightforward, it means that the color is too bright for the display.  The second case means that the color 
        is too saturated and vivid for the display.  The display must compose all colors from some combination of 
        positive amounts of the colors of its red, green and blue phosphors.  The colors of these phosphors are not 
        perfectly saturated, they are washed out, mixed with white, to some extent.  So not all colors can be displayed 
        accurately.  As an example, the colors of pure spectral lines, all have some negative component.  
        Something must be done to put these values into the 0.0 - 1.0 range that can actually be displayed, 
        known as color clipping.
        
        In the first case, values larger than 1.0, ColorPy scales the color so that the maximum component is 1.0.  
        This reduces the brightness without changing the chromaticity.  The second case requires some change in 
        chromaticity.  By default, ColorPy will add white to the color, just enough to make all of the components 
        non-negative.  (You can also have ColorPy clamp the negative values to zero.  My personal, qualitative, 
        assessment is that adding white produces somewhat better results.  There is also the potential to develop a 
        better clipping function.)
        """
        if min(self.RGB) < 0:
            self.RGB += min(self.RGB)
        if max(self.RGB) > 1:
            self.RGB /= max(self.RGB)

        # TODO why can we get negative values and values > 1 ?
        self.RGB = np.abs(self.RGB)
        self.RGB = np.clip(self.RGB, 0, 1)
        self.xy = colour.XYZ_to_xy(self.XYZ)
Ejemplo n.º 7
0
def get_tristimulus_XYZs(Theta_I, Phi_I, Polarization, Data, observer,
                         illuminant):
    u_wls = np.array(Data['Wavelengths'])
    u_theta_Is = np.array(Data['thetaIs'])
    u_phi_Is = np.array(Data['phiIs'])
    u_pols = np.array(Data['Polarization'])
    u_theta_Vs = np.array(Data['thetaVs'])
    u_phi_Vs = np.array(Data['phiVs'])
    data = np.array(Data['data'])

    cmfs = clr.STANDARD_OBSERVERS_CMFS[observer]
    illuminant = clr.ILLUMINANTS_SDS[illuminant]
    tristimulus_XYZ_values = []
    color_values = []
    for theta_V in u_theta_Vs:
        tristimulus_XYZ_row = []
        color_values_row = []
        for phi_V in u_phi_Vs:
            spectrum = data[u_pols == Polarization, u_theta_Is == Theta_I,
                            u_phi_Is == Phi_I, :, u_theta_Vs == theta_V,
                            u_phi_Vs == phi_V]
            # spectrum = spectrum[0]/np.max(spectrum)
            spectrum = np.array([u_wls, spectrum[0]]).T
            spectrum = spectrum.tolist()
            spectrum = {line[0]: line[1] for line in spectrum}
            sd = clr.SpectralDistribution(spectrum)
            sd = sd.interpolate(clr.SpectralShape(380, 830, 1))
            # print(sd)
            XYZ = clr.sd_to_XYZ(sd, cmfs, illuminant)
            sRGB = clr.XYZ_to_sRGB(XYZ / 100)
            sRGB = sRGBColor(sRGB[0], sRGB[1], sRGB[2])
            RGB = list(sRGB.get_upscaled_value_tuple())
            for i in range(len(RGB)):
                if RGB[i] < 0:
                    RGB[i] = 0
                elif RGB[i] > 255:
                    RGB[i] = 255
            tristimulus_XYZ_row.append(XYZ)
            color_values_row.append(RGB)
        tristimulus_XYZ_values.append(tristimulus_XYZ_row)
        color_values.append(color_values_row)
    return tristimulus_XYZ_values, color_values
Ejemplo n.º 8
0
    def copute_color(self):
        self.sample_spd_data = dict(zip(self.raw_wl, self.raw_spec))
        self.spd = colour.SpectralDistribution(self.sample_spd_data,
                                               name=self.label)
        # Cloning the sample spectral power distribution.
        self.spd_interpolated = self.spd.clone()

        # Interpolating the cloned sample spectral power distribution.
        # Indeed, the algorithm for colour identification needs a spectra with a point each nanometer
        self.spd_interpolated.interpolate(colour.SpectralShape(400, 820, 1))

        self.cmfs = colour.STANDARD_OBSERVERS_CMFS[
            'CIE 1931 2 Degree Standard Observer']
        self.illuminant = colour.ILLUMINANTS_SDS['D65']
        self.XYZ = colour.sd_to_XYZ(self.spd_interpolated, self.cmfs,
                                    self.illuminant)
        self.RGB = colour.XYZ_to_sRGB(self.XYZ / 100)
        # TODO why can we get negative values and values > 1 ?
        self.RGB = np.abs(self.RGB)
        self.RGB = np.clip(self.RGB, 0, 1)
        self.xy = colour.XYZ_to_xy(self.XYZ)
Ejemplo n.º 9
0
plot_multi_lightness_functions(['CIE 1976', 'Glasser 1958'])

print('\n')

message_box('Plotting various blackbody spectral radiance.')
plot_blackbody_spectral_radiance(temperature=3500,
                                 blackbody='VY Canis Majoris')
plot_blackbody_spectral_radiance(temperature=5778, blackbody='The Sun')
plot_blackbody_spectral_radiance(temperature=12130, blackbody='Rigel')

print('\n')

message_box('Comparing theoretical and measured "Sun" spectral distributions.')
sd_ASTMG173 = SD_ASTMG173_ETR.copy()

sd_ASTMG173.interpolate(colour.SpectralShape(interval=5),
                        interpolator=colour.LinearInterpolator)

sd_blackbody = colour.sd_blackbody(5778, sd_ASTMG173.shape)
sd_blackbody.name = 'The Sun - 5778K'

sd_blackbody /= colour.sd_to_XYZ(sd_blackbody)[1]
sd_blackbody *= colour.sd_to_XYZ(sd_ASTMG173)[1]

plot_multi_sds([sd_ASTMG173, sd_blackbody], y_label='W / (sr m$^2$) / m')

print('\n')

message_box('Plotting various "blackbody" spectral distributions.')
sds_blackbody = [
    colour.sd_blackbody(i, colour.SpectralShape(100, 1500, 10))
Ejemplo n.º 10
0
def generate_documentation_plots(output_directory):
    """
    Generates documentation plots.

    Parameters
    ----------
    output_directory : unicode
        Output directory.
    """

    colour.utilities.filter_warnings()

    colour_style()

    np.random.seed(0)

    # *************************************************************************
    # "README.rst"
    # *************************************************************************
    arguments = {
        'tight_layout':
            True,
        'transparent_background':
            True,
        'filename':
            os.path.join(output_directory,
                         'Examples_Plotting_Visible_Spectrum.png')
    }
    plot_visible_spectrum('CIE 1931 2 Degree Standard Observer', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Examples_Plotting_Illuminant_F1_SD.png')
    plot_single_illuminant_sd('FL1', **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Examples_Plotting_Blackbodies.png')
    blackbody_sds = [
        colour.sd_blackbody(i, colour.SpectralShape(0, 10000, 10))
        for i in range(1000, 15000, 1000)
    ]
    plot_multi_sds(
        blackbody_sds,
        y_label='W / (sr m$^2$) / m',
        use_sds_colours=True,
        normalise_sds_colours=True,
        legend_location='upper right',
        bounding_box=(0, 1250, 0, 2.5e15),
        **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Examples_Plotting_Cone_Fundamentals.png')
    plot_single_cmfs(
        'Stockman & Sharpe 2 Degree Cone Fundamentals',
        y_label='Sensitivity',
        bounding_box=(390, 870, 0, 1.1),
        **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Examples_Plotting_Luminous_Efficiency.png')
    sd_mesopic_luminous_efficiency_function = (
        colour.sd_mesopic_luminous_efficiency_function(0.2))
    plot_multi_sds(
        (sd_mesopic_luminous_efficiency_function,
         colour.PHOTOPIC_LEFS['CIE 1924 Photopic Standard Observer'],
         colour.SCOTOPIC_LEFS['CIE 1951 Scotopic Standard Observer']),
        y_label='Luminous Efficiency',
        legend_location='upper right',
        y_tighten=True,
        margins=(0, 0, 0, .1),
        **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Examples_Plotting_BabelColor_Average.png')
    plot_multi_sds(
        colour.COLOURCHECKERS_SDS['BabelColor Average'].values(),
        use_sds_colours=True,
        title=('BabelColor Average - '
               'Spectral Distributions'),
        **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Examples_Plotting_ColorChecker_2005.png')
    plot_single_colour_checker(
        'ColorChecker 2005', text_parameters={'visible': False}, **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Examples_Plotting_Chromaticities_Prediction.png')
    plot_corresponding_chromaticities_prediction(2, 'Von Kries', 'Bianco',
                                                 **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Examples_Plotting_CCT_CIE_1960_UCS_Chromaticity_Diagram.png')
    plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS(['A', 'B', 'C'],
                                                            **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Examples_Plotting_Chromaticities_CIE_1931_Chromaticity_Diagram.png')
    RGB = np.random.random((32, 32, 3))
    plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931(
        RGB,
        'ITU-R BT.709',
        colourspaces=['ACEScg', 'S-Gamut'],
        show_pointer_gamut=True,
        **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Examples_Plotting_CRI.png')
    plot_single_sd_colour_rendering_index_bars(colour.ILLUMINANTS_SDS['FL2'],
                                               **arguments)

    # *************************************************************************
    # Documentation
    # *************************************************************************
    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_CVD_Simulation_Machado2009.png')
    plot_cvd_simulation_Machado2009(RGB, **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Single_Colour_Checker.png')
    plot_single_colour_checker('ColorChecker 2005', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Multi_Colour_Checkers.png')
    plot_multi_colour_checkers(['ColorChecker 1976', 'ColorChecker 2005'],
                               **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Single_SD.png')
    data = {
        500: 0.0651,
        520: 0.0705,
        540: 0.0772,
        560: 0.0870,
        580: 0.1128,
        600: 0.1360
    }
    sd = colour.SpectralDistribution(data, name='Custom')
    plot_single_sd(sd, **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Multi_SDs.png')
    data_1 = {
        500: 0.004900,
        510: 0.009300,
        520: 0.063270,
        530: 0.165500,
        540: 0.290400,
        550: 0.433450,
        560: 0.594500
    }
    data_2 = {
        500: 0.323000,
        510: 0.503000,
        520: 0.710000,
        530: 0.862000,
        540: 0.954000,
        550: 0.994950,
        560: 0.995000
    }
    spd1 = colour.SpectralDistribution(data_1, name='Custom 1')
    spd2 = colour.SpectralDistribution(data_2, name='Custom 2')
    plot_multi_sds([spd1, spd2], **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Single_CMFS.png')
    plot_single_cmfs('CIE 1931 2 Degree Standard Observer', **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Multi_CMFS.png')
    cmfs = ('CIE 1931 2 Degree Standard Observer',
            'CIE 1964 10 Degree Standard Observer')
    plot_multi_cmfs(cmfs, **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Single_Illuminant_SD.png')
    plot_single_illuminant_sd('A', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Multi_Illuminant_SDs.png')
    plot_multi_illuminant_sds(['A', 'B', 'C'], **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Visible_Spectrum.png')
    plot_visible_spectrum(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Single_Lightness_Function.png')
    plot_single_lightness_function('CIE 1976', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Multi_Lightness_Functions.png')
    plot_multi_lightness_functions(['CIE 1976', 'Wyszecki 1963'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Single_Luminance_Function.png')
    plot_single_luminance_function('CIE 1976', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Multi_Luminance_Functions.png')
    plot_multi_luminance_functions(['CIE 1976', 'Newhall 1943'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Blackbody_Spectral_Radiance.png')
    plot_blackbody_spectral_radiance(
        3500, blackbody='VY Canis Major', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Blackbody_Colours.png')
    plot_blackbody_colours(colour.SpectralShape(150, 12500, 50), **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Single_Colour_Swatch.png')
    RGB = ColourSwatch(RGB=(0.32315746, 0.32983556, 0.33640183))
    plot_single_colour_swatch(RGB, **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Multi_Colour_Swatches.png')
    RGB_1 = ColourSwatch(RGB=(0.45293517, 0.31732158, 0.26414773))
    RGB_2 = ColourSwatch(RGB=(0.77875824, 0.57726450, 0.50453169))
    plot_multi_colour_swatches([RGB_1, RGB_2], **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Single_Function.png')
    plot_single_function(lambda x: x ** (1 / 2.2), **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Multi_Functions.png')
    functions = {
        'Gamma 2.2': lambda x: x ** (1 / 2.2),
        'Gamma 2.4': lambda x: x ** (1 / 2.4),
        'Gamma 2.6': lambda x: x ** (1 / 2.6),
    }
    plot_multi_functions(functions, **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Image.png')
    path = os.path.join(colour.__path__[0], '..', 'docs', '_static',
                        'Logo_Medium_001.png')
    plot_image(colour.read_image(str(path)), **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Corresponding_Chromaticities_Prediction.png')
    plot_corresponding_chromaticities_prediction(1, 'Von Kries', 'CAT02',
                                                 **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Spectral_Locus.png')
    plot_spectral_locus(spectral_locus_colours='RGB', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Chromaticity_Diagram_Colours.png')
    plot_chromaticity_diagram_colours(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Chromaticity_Diagram.png')
    plot_chromaticity_diagram(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1931.png')
    plot_chromaticity_diagram_CIE1931(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1960UCS.png')
    plot_chromaticity_diagram_CIE1960UCS(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1976UCS.png')
    plot_chromaticity_diagram_CIE1976UCS(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram.png')
    A = colour.ILLUMINANTS_SDS['A']
    D65 = colour.ILLUMINANTS_SDS['D65']
    plot_sds_in_chromaticity_diagram([A, D65], **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1931.png')
    plot_sds_in_chromaticity_diagram_CIE1931([A, D65], **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1960UCS.png')
    plot_sds_in_chromaticity_diagram_CIE1960UCS([A, D65], **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1976UCS.png')
    plot_sds_in_chromaticity_diagram_CIE1976UCS([A, D65], **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Pointer_Gamut.png')
    plot_pointer_gamut(**arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_RGB_Colourspaces_In_Chromaticity_Diagram.png')
    plot_RGB_colourspaces_in_chromaticity_diagram(
        ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_RGB_Colourspaces_In_Chromaticity_Diagram_CIE1931.png')
    plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931(
        ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Colourspaces_In_'
        'Chromaticity_Diagram_CIE1960UCS.png')
    plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS(
        ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Colourspaces_In_'
        'Chromaticity_Diagram_CIE1976UCS.png')
    plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS(
        ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Chromaticities_In_'
        'Chromaticity_Diagram_Plot.png')
    RGB = np.random.random((128, 128, 3))
    plot_RGB_chromaticities_in_chromaticity_diagram(RGB, 'ITU-R BT.709',
                                                    **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Chromaticities_In_'
        'Chromaticity_Diagram_CIE1931.png')
    plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931(
        RGB, 'ITU-R BT.709', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Chromaticities_In_'
        'Chromaticity_Diagram_CIE1960UCS.png')
    plot_RGB_chromaticities_in_chromaticity_diagram_CIE1960UCS(
        RGB, 'ITU-R BT.709', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Chromaticities_In_'
        'Chromaticity_Diagram_CIE1976UCS.png')
    plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS(
        RGB, 'ITU-R BT.709', **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Ellipses_MacAdam1942_In_Chromaticity_Diagram.png')
    plot_ellipses_MacAdam1942_in_chromaticity_diagram(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_'
        'Chromaticity_Diagram_CIE1931.png')
    plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1931(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_'
        'Chromaticity_Diagram_CIE1960UCS.png')
    plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1960UCS(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_'
        'Chromaticity_Diagram_CIE1976UCS.png')
    plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1976UCS(**arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Single_CCTF.png')
    plot_single_cctf('ITU-R BT.709', **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Multi_CCTFs.png')
    plot_multi_cctfs(['ITU-R BT.709', 'sRGB'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Single_Munsell_Value_Function.png')
    plot_single_munsell_value_function('ASTM D1535-08', **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Multi_Munsell_Value_Functions.png')
    plot_multi_munsell_value_functions(['ASTM D1535-08', 'McCamy 1987'],
                                       **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Single_SD_Rayleigh_Scattering.png')
    plot_single_sd_rayleigh_scattering(**arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_The_Blue_Sky.png')
    plot_the_blue_sky(**arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_Colour_Quality_Bars.png')
    illuminant = colour.ILLUMINANTS_SDS['FL2']
    light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P']
    light_source = light_source.copy().align(colour.SpectralShape(360, 830, 1))
    cqs_i = colour.colour_quality_scale(illuminant, additional_data=True)
    cqs_l = colour.colour_quality_scale(light_source, additional_data=True)
    plot_colour_quality_bars([cqs_i, cqs_l], **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Single_SD_Colour_Rendering_Index_Bars.png')
    illuminant = colour.ILLUMINANTS_SDS['FL2']
    plot_single_sd_colour_rendering_index_bars(illuminant, **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Multi_SDs_Colour_Rendering_Indexes_Bars.png')
    light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P']
    plot_multi_sds_colour_rendering_indexes_bars([illuminant, light_source],
                                                 **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Single_SD_Colour_Quality_Scale_Bars.png')
    illuminant = colour.ILLUMINANTS_SDS['FL2']
    plot_single_sd_colour_quality_scale_bars(illuminant, **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Multi_SDs_Colour_Quality_Scales_Bars.png')
    light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P']
    plot_multi_sds_colour_quality_scales_bars([illuminant, light_source],
                                              **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_Planckian_Locus.png')
    plot_planckian_locus(**arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram.png')
    plot_planckian_locus_in_chromaticity_diagram(['A', 'B', 'C'], **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram_CIE1931.png')
    plot_planckian_locus_in_chromaticity_diagram_CIE1931(['A', 'B', 'C'],
                                                         **arguments)

    arguments['filename'] = os.path.join(
        output_directory,
        'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram_CIE1960UCS.png')
    plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS(['A', 'B', 'C'],
                                                            **arguments)
    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Colourspaces_Gamuts.png')
    plot_RGB_colourspaces_gamuts(['ITU-R BT.709', 'ACEScg', 'S-Gamut'],
                                 **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Plotting_Plot_RGB_Colourspaces_Gamuts.png')
    plot_RGB_colourspaces_gamuts(['ITU-R BT.709', 'ACEScg', 'S-Gamut'],
                                 **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Plotting_Plot_RGB_Scatter.png')
    plot_RGB_scatter(RGB, 'ITU-R BT.709', **arguments)

    # *************************************************************************
    # "tutorial.rst"
    # *************************************************************************
    arguments['filename'] = os.path.join(output_directory,
                                         'Tutorial_Visible_Spectrum.png')
    plot_visible_spectrum(**arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Tutorial_Sample_SD.png')
    sample_sd_data = {
        380: 0.048,
        385: 0.051,
        390: 0.055,
        395: 0.060,
        400: 0.065,
        405: 0.068,
        410: 0.068,
        415: 0.067,
        420: 0.064,
        425: 0.062,
        430: 0.059,
        435: 0.057,
        440: 0.055,
        445: 0.054,
        450: 0.053,
        455: 0.053,
        460: 0.052,
        465: 0.052,
        470: 0.052,
        475: 0.053,
        480: 0.054,
        485: 0.055,
        490: 0.057,
        495: 0.059,
        500: 0.061,
        505: 0.062,
        510: 0.065,
        515: 0.067,
        520: 0.070,
        525: 0.072,
        530: 0.074,
        535: 0.075,
        540: 0.076,
        545: 0.078,
        550: 0.079,
        555: 0.082,
        560: 0.087,
        565: 0.092,
        570: 0.100,
        575: 0.107,
        580: 0.115,
        585: 0.122,
        590: 0.129,
        595: 0.134,
        600: 0.138,
        605: 0.142,
        610: 0.146,
        615: 0.150,
        620: 0.154,
        625: 0.158,
        630: 0.163,
        635: 0.167,
        640: 0.173,
        645: 0.180,
        650: 0.188,
        655: 0.196,
        660: 0.204,
        665: 0.213,
        670: 0.222,
        675: 0.231,
        680: 0.242,
        685: 0.251,
        690: 0.261,
        695: 0.271,
        700: 0.282,
        705: 0.294,
        710: 0.305,
        715: 0.318,
        720: 0.334,
        725: 0.354,
        730: 0.372,
        735: 0.392,
        740: 0.409,
        745: 0.420,
        750: 0.436,
        755: 0.450,
        760: 0.462,
        765: 0.465,
        770: 0.448,
        775: 0.432,
        780: 0.421
    }

    sd = colour.SpectralDistribution(sample_sd_data, name='Sample')
    plot_single_sd(sd, **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Tutorial_SD_Interpolation.png')
    sd_copy = sd.copy()
    sd_copy.interpolate(colour.SpectralShape(400, 770, 1))
    plot_multi_sds(
        [sd, sd_copy], bounding_box=[730, 780, 0.25, 0.5], **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Tutorial_Sample_Swatch.png')
    sd = colour.SpectralDistribution(sample_sd_data)
    cmfs = colour.STANDARD_OBSERVERS_CMFS[
        'CIE 1931 2 Degree Standard Observer']
    illuminant = colour.ILLUMINANTS_SDS['D65']
    with domain_range_scale('1'):
        XYZ = colour.sd_to_XYZ(sd, cmfs, illuminant)
        RGB = colour.XYZ_to_sRGB(XYZ)
    plot_single_colour_swatch(
        ColourSwatch('Sample', RGB),
        text_parameters={'size': 'x-large'},
        **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Tutorial_Neutral5.png')
    patch_name = 'neutral 5 (.70 D)'
    patch_sd = colour.COLOURCHECKERS_SDS['ColorChecker N Ohta'][patch_name]
    with domain_range_scale('1'):
        XYZ = colour.sd_to_XYZ(patch_sd, cmfs, illuminant)
        RGB = colour.XYZ_to_sRGB(XYZ)
    plot_single_colour_swatch(
        ColourSwatch(patch_name.title(), RGB),
        text_parameters={'size': 'x-large'},
        **arguments)

    arguments['filename'] = os.path.join(output_directory,
                                         'Tutorial_Colour_Checker.png')
    plot_single_colour_checker(
        colour_checker='ColorChecker 2005',
        text_parameters={'visible': False},
        **arguments)

    arguments['filename'] = os.path.join(
        output_directory, 'Tutorial_CIE_1931_Chromaticity_Diagram.png')
    xy = colour.XYZ_to_xy(XYZ)
    plot_chromaticity_diagram_CIE1931(standalone=False)
    x, y = xy
    plt.plot(x, y, 'o-', color='white')
    # Annotating the plot.
    plt.annotate(
        patch_sd.name.title(),
        xy=xy,
        xytext=(-50, 30),
        textcoords='offset points',
        arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=-0.2'))
    render(
        standalone=True,
        limits=(-0.1, 0.9, -0.1, 0.9),
        x_tighten=True,
        y_tighten=True,
        **arguments)

    # *************************************************************************
    # "basics.rst"
    # *************************************************************************
    arguments['filename'] = os.path.join(output_directory,
                                         'Basics_Logo_Small_001_CIE_XYZ.png')
    RGB = colour.read_image(
        os.path.join(output_directory, 'Logo_Small_001.png'))[..., 0:3]
    XYZ = colour.sRGB_to_XYZ(RGB)
    colour.plotting.plot_image(
        XYZ, text_parameters={'text': 'sRGB to XYZ'}, **arguments)
Ejemplo n.º 11
0
message_box('"Mallett et al. (2019)" - Reflectance Recovery Computations')

illuminant = colour.SDS_ILLUMINANTS['D65']

XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
RGB = colour.XYZ_to_sRGB(XYZ, apply_cctf_encoding=False)
message_box('Recovering reflectance using "Mallett et al. (2019)" method '
            'from given "XYZ" tristimulus values:\n'
            '\n\tXYZ: {0}'.format(XYZ))
sd = colour.XYZ_to_sd(XYZ, method='Mallett 2019')
print(sd)
print(colour.recovery.RGB_to_sd_Mallett2019(RGB))
print(colour.sd_to_XYZ(sd, illuminant=illuminant) / 100)

print('\n')

message_box('Generating the "Mallett et al. (2019)" basis functions for the '
            '*Pal/Secam* colourspace:')
cmfs = (colour.MSDS_CMFS['CIE 1931 2 Degree Standard Observer'].copy().align(
    colour.SpectralShape(360, 780, 10)))
illuminant = colour.SDS_ILLUMINANTS['D65'].copy().align(cmfs.shape)

print(
    colour.recovery.spectral_primary_decomposition_Mallett2019(
        colour.models.RGB_COLOURSPACE_PAL_SECAM,
        cmfs,
        illuminant,
        optimisation_kwargs={'options': {
            'ftol': 1e-5
        }}))
Ejemplo n.º 12
0
print('\n')

message_box('Plotting various blackbody spectral radiance.')
blackbody_spectral_radiance_plot(temperature=3500,
                                 blackbody='VY Canis Majoris')
blackbody_spectral_radiance_plot(temperature=5778, blackbody='The Sun')
blackbody_spectral_radiance_plot(temperature=12130, blackbody='Rigel')

print('\n')

message_box('Comparing theoretical and measured "Sun" spectral distributions.')
# Arbitrary ASTM_G_173_ETR scaling factor calculated with
# :func:`colour.spectral_to_XYZ` definition.
ASTM_G_173_spd = ASTM_G_173_ETR.clone() * 1.37905559e+13

ASTM_G_173_spd.interpolate(colour.SpectralShape(steps=5), method='Linear')

blackbody_spd = colour.blackbody_spd(
    5778,
    ASTM_G_173_spd.shape)
blackbody_spd.name = 'The Sun - 5778K'

multi_spd_plot((ASTM_G_173_spd, blackbody_spd),
               y_label='W / (sr m$^2$) / m',
               legend_location='upper right')

print('\n')

message_box('Plotting various "blackbody" spectral power distributions.')
blackbody_spds = [
    colour.blackbody_spd(i, colour.SpectralShape(0, 10000, 10))
__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2019-2021 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = '*****@*****.**'
__status__ = 'Production'

__all__ = [
    'MITSUBA_SHAPE', 'slugify', 'format_spectrum',
    'export_AMPAS_training_data_bsdfs_files',
    'export_colorchecker_classic_bsdfs_files',
    'export_colorchecker_classic_support_bsdfs_file', 'export_emitters_files',
    'export_synthetic_LEDs', 'export_emitters_bt2020'
]

MITSUBA_SHAPE = colour.SpectralShape(360, 830, 5)


def slugify(a):
    return re.sub(r'\s|-|\.', '_',
                  re.sub(r'(?u)[^-\w.]', ' ',
                         str(a).strip()).strip().lower())


def format_spectrum(sd, decimals=15):
    return ', '.join('{1}:{2:0.{0}f}'.format(decimals, wavelength, value)
                     for wavelength, value in zip(sd.wavelengths, sd.values))


def export_AMPAS_training_data_bsdfs_files(bsdf_type='diffuse',
                                           ior=1.460,
Ejemplo n.º 14
0
 def colour_spectr(sample_spd_data, name):
     spd = colour.SpectralPowerDistribution(name, sample_spd_data)
     spd.interpolate(colour.SpectralShape(200, 800, 1))
     return spd
Ejemplo n.º 15
0
            0.83375293,
            0.90571451,
            0.70054168,
        ],
        [
            0.06321812,
            0.41898224,
            0.15190357,
            0.24591440,
            0.55301750,
            0.00657664,
        ],
        [
            0.00305180,
            0.11288624,
            0.11357290,
            0.12924391,
            0.00195315,
            0.21771573,
        ],
    ],
])
print(
    colour.msds_to_XYZ(
        msds,
        cmfs,
        illuminant,
        method="Integration",
        shape=colour.SpectralShape(400, 700, 60),
    ))
Ejemplo n.º 16
0
    740: 0.0000,
    760: 0.0000,
    780: 0.0000,
    800: 0.0000,
    820.9: 0.0000
}

base_sd = colour.SpectralDistribution(uniform_sd_data, name='Reference')
uniform_interpolated_sd = colour.SpectralDistribution(
    uniform_sd_data, name='Uniform - Sprague Interpolation')
uniform_pchip_interpolated_sd = colour.SpectralDistribution(
    uniform_sd_data, name='Uniform - Pchip Interpolation')
non_uniform_interpolated_sd = colour.SpectralDistribution(
    non_uniform_sd_data, name='Non Uniform - Cubic Spline Interpolation')

uniform_interpolated_sd.interpolate(colour.SpectralShape(interval=1))
uniform_pchip_interpolated_sd.interpolate(
    colour.SpectralShape(interval=1), interpolator=colour.PchipInterpolator)
non_uniform_interpolated_sd.interpolate(colour.SpectralShape(interval=1))

shape = base_sd.shape
x_limit_min, x_limit_max, y_limit_min, y_limit_max = [], [], [], []

plt.plot(base_sd.wavelengths,
         base_sd.values,
         'ro-',
         label=base_sd.name,
         linewidth=1)
plt.plot(uniform_interpolated_sd.wavelengths,
         uniform_interpolated_sd.values,
         label=uniform_interpolated_sd.name,
print("\n")

message_box("Plotting various blackbody spectral radiance.")
plot_blackbody_spectral_radiance(
    temperature=3500, blackbody="VY Canis Majoris"
)
plot_blackbody_spectral_radiance(temperature=5778, blackbody="The Sun")
plot_blackbody_spectral_radiance(temperature=12130, blackbody="Rigel")

print("\n")

message_box('Comparing theoretical and measured "Sun" spectral distributions.')
sd_ASTMG173 = SD_ASTMG173_ETR.copy()

sd_ASTMG173.interpolate(
    colour.SpectralShape(sd_ASTMG173.shape.start, sd_ASTMG173.shape.end, 5),
    interpolator=colour.LinearInterpolator,
)

sd_blackbody = colour.sd_blackbody(5778, sd_ASTMG173.shape)
sd_blackbody.name = "The Sun - 5778K"

sd_blackbody /= colour.sd_to_XYZ(sd_blackbody)[1]
sd_blackbody *= colour.sd_to_XYZ(sd_ASTMG173)[1]

plot_multi_sds([sd_ASTMG173, sd_blackbody], y_label="W / (sr m$^2$) / m")

print("\n")

message_box('Plotting various "blackbody" spectral distributions.')
sds_blackbody = [
Ejemplo n.º 18
0
    820.9: 0.0000}

base_spd = colour.SpectralPowerDistribution(
    'Reference',
    uniform_spd_data)
uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Uniform - Sprague Interpolation',
    uniform_spd_data)
uniform_pchip_interpolated_spd = colour.SpectralPowerDistribution(
    'Uniform - Pchip Interpolation',
    uniform_spd_data)
non_uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Non Uniform - Cubic Spline Interpolation',
    non_uniform_spd_data)

uniform_interpolated_spd.interpolate(colour.SpectralShape(interval=1))
uniform_pchip_interpolated_spd.interpolate(colour.SpectralShape(interval=1),
                                           method='Pchip')
non_uniform_interpolated_spd.interpolate(colour.SpectralShape(interval=1))

shape = base_spd.shape
x_limit_min, x_limit_max, y_limit_min, y_limit_max = [], [], [], []

pylab.plot(base_spd.wavelengths,
           base_spd.values,
           'ro-',
           label=base_spd.name,
           linewidth=2)
pylab.plot(uniform_interpolated_spd.wavelengths,
           uniform_interpolated_spd.values,
           label=uniform_interpolated_spd.name,
Ejemplo n.º 19
0
    740: 0.0000,
    760: 0.0000,
    780: 0.0000,
    800: 0.0000,
    820.9: 0.0000
}

base_spd = colour.SpectralPowerDistribution('Reference', uniform_spd_data)
uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Uniform - Sprague Interpolation', uniform_spd_data)
uniform_pchip_interpolated_spd = colour.SpectralPowerDistribution(
    'Uniform - Pchip Interpolation', uniform_spd_data)
non_uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Non Uniform - Cubic Spline Interpolation', non_uniform_spd_data)

uniform_interpolated_spd.interpolate(colour.SpectralShape(interval=1))
uniform_pchip_interpolated_spd.interpolate(
    colour.SpectralShape(interval=1), method='Pchip')
non_uniform_interpolated_spd.interpolate(colour.SpectralShape(interval=1))

shape = base_spd.shape
x_limit_min, x_limit_max, y_limit_min, y_limit_max = [], [], [], []

pylab.plot(
    base_spd.wavelengths,
    base_spd.values,
    'ro-',
    label=base_spd.name,
    linewidth=2)
pylab.plot(
    uniform_interpolated_spd.wavelengths,
Ejemplo n.º 20
0
    800: 0.0000,
    820.9: 0.0000,
}

sd_base = colour.SpectralDistribution(data_uniform, name="Reference")
uniform_interpolated_sd = colour.SpectralDistribution(
    data_uniform, name="Uniform - Sprague Interpolation")
uniform_pchip_interpolated_sd = colour.SpectralDistribution(
    data_uniform, name="Uniform - Pchip Interpolation")
non_uniform_interpolated_sd = colour.SpectralDistribution(
    data_non_uniform, name="Non Uniform - Cubic Spline Interpolation")

uniform_interpolated_sd.interpolate(
    colour.SpectralShape(
        uniform_interpolated_sd.shape.start,
        uniform_interpolated_sd.shape.end,
        1,
    ))
uniform_pchip_interpolated_sd.interpolate(
    colour.SpectralShape(
        uniform_pchip_interpolated_sd.shape.start,
        uniform_pchip_interpolated_sd.shape.end,
        1,
    ),
    interpolator=colour.PchipInterpolator,
)
non_uniform_interpolated_sd.interpolate(
    colour.SpectralShape(
        non_uniform_interpolated_sd.shape.start,
        non_uniform_interpolated_sd.shape.end,
        1,
Ejemplo n.º 21
0
    700: 0.2852,
    720: 0.0000,
    740: 0.0000,
    760: 0.0000,
    780: 0.0000,
    800: 0.0000,
    820.9: 0.0000
}

base_spd = colour.SpectralPowerDistribution('Reference', uniform_spd_data)
uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Uniform - Sprague Interpolation', uniform_spd_data)
non_uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Non Uniform - Cubic Spline Interpolation', non_uniform_spd_data)

uniform_interpolated_spd.interpolate(colour.SpectralShape(steps=1))
non_uniform_interpolated_spd.interpolate(colour.SpectralShape(steps=1))

shape = base_spd.shape
x_limit_min, x_limit_max, y_limit_min, y_limit_max = [], [], [], []

pylab.plot(base_spd.wavelengths,
           base_spd.values,
           'ro-',
           label=base_spd.name,
           linewidth=2)
pylab.plot(uniform_interpolated_spd.wavelengths,
           uniform_interpolated_spd.values,
           label=uniform_interpolated_spd.name,
           linewidth=2)
pylab.plot(non_uniform_interpolated_spd.wavelengths,
Ejemplo n.º 22
0
message_box('In-place arithmetical operation: adding an array.')
sd_clone += np.linspace(0, 1, len(sd_clone.wavelengths))
print(sd_clone.values)

print('\n')

message_box('In-place arithmetical operation: adding a spectral '
            'distribution.')
sd_clone += sd_clone
print(sd_clone.values)

print('\n')

message_box('Sample spectral distribution interpolation.')
sd_clone.interpolate(colour.SpectralShape(360, 780, 1))
print(sd_clone[666])

print('\n')

message_box('Sample spectral distribution extrapolation.')
sd_clone.extrapolate(colour.SpectralShape(340, 830))
print(sd_clone[340], sd_clone[360])

print('\n')

message_box('Sample spectral distribution align.')
sd_clone.align(colour.SpectralShape(400, 700, 5))
print(sd_clone[400], sd_clone[700])

print('\n')
Ejemplo n.º 23
0
message_box('Plotting various blackbody spectral radiance.')
plot_blackbody_spectral_radiance(
    temperature=3500, blackbody='VY Canis Majoris')
plot_blackbody_spectral_radiance(temperature=5778, blackbody='The Sun')
plot_blackbody_spectral_radiance(temperature=12130, blackbody='Rigel')

print('\n')

message_box('Comparing theoretical and measured "Sun" spectral distributions.')
# Arbitrary ASTM_G_173_ETR scaling factor calculated with
# :func:`colour.sd_to_XYZ` definition.
ASTM_G_173_sd = ASTM_G_173_ETR.copy() * 1.37905559e+13

ASTM_G_173_sd.interpolate(
    colour.SpectralShape(interval=5), interpolator=colour.LinearInterpolator)

blackbody_sd = colour.sd_blackbody(5778, ASTM_G_173_sd.shape)
blackbody_sd.name = 'The Sun - 5778K'

plot_multi_sds((ASTM_G_173_sd, blackbody_sd), y_label='W / (sr m$^2$) / m')

print('\n')

message_box('Plotting various "blackbody" spectral distributions.')
blackbody_sds = [
    colour.sd_blackbody(i, colour.SpectralShape(0, 10000, 10))
    for i in range(1000, 15000, 1000)
]

plot_multi_sds(
Ejemplo n.º 24
0
print('\n')

message_box('Plotting various blackbody spectral radiance.')
blackbody_spectral_radiance_plot(temperature=3500,
                                 blackbody='VY Canis Majoris')
blackbody_spectral_radiance_plot(temperature=5778, blackbody='The Sun')
blackbody_spectral_radiance_plot(temperature=12130, blackbody='Rigel')

print('\n')

message_box('Comparing theoretical and measured "Sun" spectral distributions.')
# Arbitrary ASTM_G_173_ETR scaling factor calculated with
# :func:`colour.spectral_to_XYZ` definition.
ASTM_G_173_spd = ASTM_G_173_ETR.copy() * 1.37905559e+13

ASTM_G_173_spd.interpolate(colour.SpectralShape(interval=5),
                           interpolator=colour.LinearInterpolator)

blackbody_spd = colour.blackbody_spd(5778, ASTM_G_173_spd.shape)
blackbody_spd.name = 'The Sun - 5778K'

multi_spd_plot((ASTM_G_173_spd, blackbody_spd),
               y_label='W / (sr m$^2$) / m',
               legend_location='upper right')

print('\n')

message_box('Plotting various "blackbody" spectral power distributions.')
blackbody_spds = [
    colour.blackbody_spd(i, colour.SpectralShape(0, 10000, 10))
    for i in range(1000, 15000, 1000)
Ejemplo n.º 25
0
illuminant_SPD = D65_SPD

np.set_printoptions(formatter={"float": "{:0.15f}".format}, threshold=np.nan)

colorspace = colour.models.BT709_COLOURSPACE

colorspace.use_derived_transformation_matrices(True)


RGB_to_XYZ_m = colorspace.RGB_to_XYZ_matrix
XYZ_to_RGB_m = colorspace.XYZ_to_RGB_matrix

# for performance use a larger interval.  Harder to solve, must raise tol

interval = 40
shape = colour.SpectralShape(380.0, 730.0, interval)

# spd via Meng-ish Burns-ish recovery
target_XYZ = colour.sRGB_to_XYZ([1,0,0])
spd = XYZ_to_spectral(target_XYZ, cmfs=CMFS.align(shape), illuminant=illuminant_SPD, interval=interval, tolerance=1e-8, max_refl=1.00)
print("red SPD is", spd.values)

target_XYZ = colour.sRGB_to_XYZ([0,1,0])
spd = XYZ_to_spectral(target_XYZ, cmfs=CMFS.align(shape), illuminant=illuminant_SPD, interval=interval, tolerance=1e-8, max_refl=1.00)
print("green SPD is", spd.values)


target_XYZ = colour.sRGB_to_XYZ([0,0,1])
spd = XYZ_to_spectral(target_XYZ, cmfs=CMFS.align(shape), illuminant=illuminant_SPD, interval=interval, tolerance=1e-8, max_refl=1.00)
print("blue SPD is", spd.values)
Ejemplo n.º 26
0
message_box('In-place arithmetical operation: adding an array.')
clone_spd += np.linspace(0, 1, len(clone_spd))
print(clone_spd.values)

print('\n')

message_box('In-place arithmetical operation: adding a spectral power '
            'distribution.')
clone_spd += clone_spd
print(clone_spd.values)

print('\n')

message_box('Sample spectral power distribution interpolation.')
clone_spd.interpolate(colour.SpectralShape(360, 780, 1))
print(clone_spd[666])

print('\n')

message_box('Sample spectral power distribution extrapolation.')
clone_spd.extrapolate(colour.SpectralShape(340, 830))
print(clone_spd[340], clone_spd[360])

print('\n')

message_box('Sample spectral power distribution align.')
clone_spd.align(colour.SpectralShape(400, 700, 5))
print(clone_spd[400], clone_spd[700])

print('\n')
Ejemplo n.º 27
0
             'from its spectral distribution.'))
print(colour.XYZ_to_xy(colour.sd_to_XYZ(illuminant, cmfs) / 100))

print('\n')

message_box(('Computing *CIE XYZ* tristimulus values for a single given '
             'wavelength in nm.'))
print(
    colour.wavelength_to_XYZ(
        546.1, colour.CMFS['CIE 1931 2 Degree Standard Observer']))

message_box(('Computing *CIE XYZ* tristimulus values from given '
             'multi-spectral image with shape (4, 3, 6).'))
msa = np.array([
    [[0.01367208, 0.09127947, 0.01524376, 0.02810712, 0.19176012, 0.04299992],
     [0.00959792, 0.25822842, 0.41388571, 0.22275120, 0.00407416, 0.37439537],
     [0.01791409, 0.29707789, 0.56295109, 0.23752193, 0.00236515, 0.58190280]],
    [[0.01492332, 0.10421912, 0.02240025, 0.03735409, 0.57663846, 0.32416266],
     [0.04180972, 0.26402685, 0.03572137, 0.00413520, 0.41808194, 0.24696727],
     [0.00628672, 0.11454948, 0.02198825, 0.39906919, 0.63640803, 0.01139849]],
    [[0.04325933, 0.26825359, 0.23732357, 0.05175860, 0.01181048, 0.08233768],
     [0.02484169, 0.12027161, 0.00541695, 0.00654612, 0.18603799, 0.36247808],
     [0.03102159, 0.16815442, 0.37186235, 0.08610666, 0.00413520, 0.78492409]],
    [[0.11682307, 0.78883040, 0.74468607, 0.83375293, 0.90571451, 0.70054168],
     [0.06321812, 0.41898224, 0.15190357, 0.24591440, 0.55301750, 0.00657664],
     [0.00305180, 0.11288624, 0.11357290, 0.12924391, 0.00195315, 0.21771573]],
])
print(
    colour.multi_sds_to_XYZ(msa, colour.SpectralShape(400, 700, 60), cmfs,
                            illuminant))