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) ] multi_spd_plot(blackbody_spds,
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 # :def:`colour.spectral_to_XYZ` definition. ASTM_G_173_spd = ASTM_G_173_ETR.clone() * 1.37905559e13 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=u"W / (sr m²) / 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)] multi_spd_plot( blackbody_spds, y_label=u"W / (sr m²) / m", use_spds_colours=True, normalise_spds_colours=True, legend_location="upper right",
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)) for i in range(1000, 15000, 1000)] multi_spd_plot(blackbody_spds,
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Showcases blackbody / planckian radiator computations. """ import colour from colour.utilities.verbose import message_box message_box('Blackbody / Planckian Radiator Computations') message_box(('Computing the spectral radiance of a blackbody at wavelength ' '500 nm and temperature 5500 kelvin degrees.')) print(colour.planck_law(500 * 1e-9, 5500)) print('\n') message_box(('Computing the spectral power distribution of a blackbody at ' 'temperature 5500 kelvin degrees and converting to "CIE XYZ" ' 'tristimulus values.')) cmfs = colour.STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'] blackbody_spd = colour.blackbody_spd(5500, cmfs.shape) print(blackbody_spd) XYZ = colour.spectral_to_XYZ(blackbody_spd, cmfs) print(XYZ)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Showcases blackbody / planckian radiator computations. """ from __future__ import division, unicode_literals import colour from colour.utilities.verbose import message_box message_box('Blackbody / Planckian Radiator Computations') message_box(('Computing the spectral radiance of a blackbody at wavelength ' '500 nm and temperature 5500 kelvin degrees.')) print(colour.planck_law(500 * 1e-9, 5500)) print('\n') message_box(('Computing the spectral power distribution of a blackbody at ' 'temperature 5500 kelvin degrees and converting to "CIE XYZ" ' 'tristimulus values.')) cmfs = colour.STANDARD_OBSERVERS_CMFS.get( 'CIE 1931 2 Degree Standard Observer') blackbody_spd = colour.blackbody_spd(5500, cmfs.shape) print(blackbody_spd) XYZ = colour.spectral_to_XYZ(blackbody_spd, cmfs) print(XYZ)
def LED_3D(l_red, l_green, l_blue, T, h, spd3_name, image): def aprocsimate_CIA(l0, l05): sample_spd_data = {} for lamb in np.arange(200, 800, 0.9): g = np.exp(-((lamb - l0) / l05)**2) Phi_led = (g + 2 * g**5) / 3 sample_spd_data[lamb] = float(Phi_led) return sample_spd_data def colour_spectr(sample_spd_data, name): spd = colour.SpectralPowerDistribution(name, sample_spd_data) spd.interpolate(colour.SpectralShape(200, 800, 1)) return spd spd_red0 = aprocsimate_CIA(l_red[0], l_red[1]) spd_green0 = aprocsimate_CIA(l_green[0], l_green[1]) spd_blue0 = aprocsimate_CIA(l_blue[0], l_blue[1]) spd_red = colour_spectr(spd_red0, 'red') spd_green = colour_spectr(spd_green0, 'green') spd_blue = colour_spectr(spd_blue0, 'blue') blackbody_spd = colour.blackbody_spd(T) cmfs = colour.STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'] # # # # Calculating the sample spectral power distribution *CIE XYZ* tristimulus values. XYZ_blackbody = colour.spectral_to_XYZ(blackbody_spd, cmfs) XYZ_red = colour.spectral_to_XYZ(spd_red, cmfs) XYZ_green = colour.spectral_to_XYZ(spd_green, cmfs) XYZ_blue = colour.spectral_to_XYZ(spd_blue, cmfs) #print(XYZ_blackbody,XYZ_red,XYZ_green,XYZ_blue) XYZ = np.vstack((XYZ_red, XYZ_green, XYZ_blue)) XYZ = XYZ.transpose() XYZ = np.linalg.inv(XYZ) XYZ_blackbody = XYZ_blackbody.transpose() abc = np.dot(XYZ, XYZ_blackbody) abc = abc / max(abc) 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 spd_3 = [spd_red, spd_green, spd_blue] spd_3d = spectr_LED(abc, spd_red0, spd_green0, spd_blue0) b1, b2, b3 = abc[0], abc[1], abc[2] c1 = 1 c2 = (b2 / b1) * (l_red[0] / l_green[0]) c3 = (b3 / b1) * (l_red[0] / l_blue[0]) h1, h2, h3 = h[0], h[1], h[2] h_sum = (c1 * h1 + c2 * h2 + c3 * h3) / (c1 + c2 + c3) multi_spd_plot(spd_3, bounding_box=[300, 800, 0, 1], filename=spd3_name) image.append(spd3_name) return spd_3, spd_3d, h_sum, image, abc
def LED_4D(l_red, l_green, l_blue, l_yellow, T, a, h, spd4_name, image, Fi_4d, Fi_red, Fi_green, Fi_blue, Fi_yellow): spd_red0 = aprocsimate_CIA(l_red[0], l_red[1]) spd_green0 = aprocsimate_CIA(l_green[0], l_green[1]) spd_blue0 = aprocsimate_CIA(l_blue[0], l_blue[1]) spd_yellow0 = aprocsimate_CIA(l_yellow[0], l_yellow[1]) spd_red = colour_spectr(spd_red0, 'red') spd_green = colour_spectr(spd_green0, 'green') spd_blue = colour_spectr(spd_blue0, 'blue') spd_yellow = colour_spectr(spd_yellow0, 'yellow') blackbody_spd = colour.blackbody_spd(T) #single_spd_plot(blackbody_spd) cmfs = colour.STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'] # # # # Calculating the sample spectral power distribution *CIE XYZ* tristimulus values. blackbody_spd.normalise() XYZ_blackbody = colour.spectral_to_XYZ(blackbody_spd, cmfs) XYZ_red = colour.spectral_to_XYZ(spd_red, cmfs) XYZ_green = colour.spectral_to_XYZ(spd_green, cmfs) XYZ_blue = colour.spectral_to_XYZ(spd_blue, cmfs) XYZ_yellow = colour.spectral_to_XYZ(spd_yellow, cmfs) XYZ_blackbody[0] = XYZ_blackbody[0] - XYZ_yellow[0] * a XYZ_blackbody[1] = XYZ_blackbody[1] - XYZ_yellow[1] * a XYZ_blackbody[2] = XYZ_blackbody[2] - XYZ_yellow[2] * a #print(XYZ_blackbody,XYZ_red,XYZ_green,XYZ_blue) XYZ = np.vstack((XYZ_red, XYZ_green, XYZ_blue)) XYZ = XYZ.transpose() XYZ = np.linalg.inv(XYZ) XYZ_blackbody = XYZ_blackbody.transpose() abc = np.dot(XYZ, XYZ_blackbody) abca = [abc[0], abc[1], abc[2], a] #abca=abca/max(abca) spd_4 = [spd_red, spd_green, spd_blue, spd_yellow] spd_4d = spectr_LED4(abca, spd_red0, spd_green0, spd_blue0, spd_yellow0) b1, b2, b3, b4 = abca[0], abca[1], abca[2], abca[3] c1 = 1 c2 = (b2 / b1) * (l_red[0] / l_green[0]) c3 = (b3 / b1) * (l_red[0] / l_blue[0]) c4 = (b4 / b1) * (l_red[0] / l_yellow[0]) h1, h2, h3, h4 = h[0], h[1], h[2], h[3] h_sum = (c1 * h1 + c2 * h2 + c3 * h3 + c4 * h4) / (c1 + c2 + c3 + c4) multi_spd_plot(spd_4, bounding_box=[300, 800, 0, 1], filename=spd4_name) image.append(spd4_name) from colour.colorimetry import PHOTOPIC_LEFS lef = PHOTOPIC_LEFS.get('CIE 1924 Photopic Standard Observer') lef_4d = lef.clone().align(spd_4d.shape, extrapolation_left=0, extrapolation_right=0) lef_red = lef.clone().align(spd_red.shape, extrapolation_left=0, extrapolation_right=0) lef_green = lef.clone().align(spd_green.shape, extrapolation_left=0, extrapolation_right=0) lef_blue = lef.clone().align(spd_blue.shape, extrapolation_left=0, extrapolation_right=0) lef_yellow = lef.clone().align(spd_yellow.shape, extrapolation_left=0, extrapolation_right=0) #import numpy as np #spd_4d Fi_max_4d = (683 * np.trapz(lef_4d.values * spd_4d.values, spd_4d.wavelengths)) k_4d = Fi_4d / Fi_max_4d Fe_4d = (k_4d * np.trapz(spd_4d.values, spd_4d.wavelengths)) F_4d = [Fi_max_4d, k_4d, Fe_4d, Fi_4d] #spd_red Fi_max_red = ( 683 * np.trapz(lef_red.values * spd_red.values, spd_red.wavelengths)) k_red = Fi_red / Fi_max_red Fe_red = (k_red * np.trapz(spd_red.values, spd_red.wavelengths)) F_red = [Fi_max_red, k_red, Fe_red, Fi_red] #spd_green Fi_max_green = ( 683 * np.trapz(lef_green.values * spd_green.values, spd_green.wavelengths)) k_green = Fi_green / Fi_max_green Fe_green = (k_green * np.trapz(spd_green.values, spd_green.wavelengths)) F_green = [Fi_max_green, k_green, Fe_green, Fi_green] #spd_blue Fi_max_blue = ( 683 * np.trapz(lef_blue.values * spd_blue.values, spd_blue.wavelengths)) k_blue = Fi_blue / Fi_max_blue Fe_blue = (k_blue * np.trapz(spd_blue.values, spd_blue.wavelengths)) F_blue = [Fi_max_blue, k_blue, Fe_blue, Fi_blue] #spd_yellow Fi_max_yellow = (683 * np.trapz(lef_yellow.values * spd_yellow.values, spd_yellow.wavelengths)) k_yellow = Fi_yellow / Fi_max_yellow Fe_yellow = (k_yellow * np.trapz(spd_yellow.values, spd_yellow.wavelengths)) F_yellow = [Fi_max_yellow, k_yellow, Fe_yellow, Fi_yellow] return spd_4, spd_4d, h_sum, image, abca, F_4d, F_red, F_green, F_blue, F_yellow