Beispiel #1
0
def single_rayleigh_scattering_spd_plot(
        CO2_concentration=STANDARD_CO2_CONCENTRATION,
        temperature=STANDARD_AIR_TEMPERATURE,
        pressure=AVERAGE_PRESSURE_MEAN_SEA_LEVEL,
        latitude=DEFAULT_LATITUDE,
        altitude=DEFAULT_ALTITUDE,
        cmfs='CIE 1931 2 Degree Standard Observer',
        **kwargs):
    """
    Plots a single *Rayleigh* scattering spectral power distribution.

    Parameters
    ----------
    CO2_concentration : numeric, optional
        :math:`CO_2` concentration in parts per million (ppm).
    temperature : numeric, optional
        Air temperature :math:`T[K]` in kelvin degrees.
    pressure : numeric
        Surface pressure :math:`P` of the measurement site.
    latitude : numeric, optional
        Latitude of the site in degrees.
    altitude : numeric, optional
        Altitude of the site in meters.
    cmfs : unicode, optional
        Standard observer colour matching functions.

    Other Parameters
    ----------------
    \**kwargs : dict, optional
        {:func:`boundaries`, :func:`canvas`, :func:`decorate`,
        :func:`display`},
        Please refer to the documentation of the previously listed definitions.
    out_of_gamut_clipping : bool, optional
        {:func:`single_spd_plot`},
        Whether to clip out of gamut colours otherwise, the colours will be
        offset by the absolute minimal colour leading to a rendering on
        gray background, less saturated and smoother. [1]_

    Returns
    -------
    Figure
        Current figure or None.

    Examples
    --------
    >>> single_rayleigh_scattering_spd_plot()  # doctest: +SKIP
    """

    title = 'Rayleigh Scattering'

    cmfs = get_cmfs(cmfs)

    settings = {'title': title, 'y_label': 'Optical Depth'}
    settings.update(kwargs)

    spd = rayleigh_scattering_spd(cmfs.shape, CO2_concentration, temperature,
                                  pressure, latitude, altitude)

    return single_spd_plot(spd, **settings)
Beispiel #2
0
def single_rayleigh_scattering_spd_plot(
        CO2_concentration=STANDARD_CO2_CONCENTRATION,
        temperature=STANDARD_AIR_TEMPERATURE,
        pressure=AVERAGE_PRESSURE_MEAN_SEA_LEVEL,
        latitude=DEFAULT_LATITUDE,
        altitude=DEFAULT_ALTITUDE,
        cmfs='CIE 1931 2 Degree Standard Observer',
        **kwargs):
    """
    Plots a single rayleigh scattering spectral power distribution.

    Parameters
    ----------
    CO2_concentration : numeric, optional
        :math:`CO_2` concentration in parts per million (ppm).
    temperature : numeric, optional
        Air temperature :math:`T[K]` in kelvin degrees.
    pressure : numeric
        Surface pressure :math:`P` of the measurement site.
    latitude : numeric, optional
        Latitude of the site in degrees.
    altitude : numeric, optional
        Altitude of the site in meters.
    cmfs : unicode, optional
        Standard observer colour matching functions.
    \**kwargs : dict, optional
        Keywords arguments.

    Returns
    -------
    bool
        Definition success.

    Examples
    --------
    >>> single_rayleigh_scattering_spd_plot()  # doctest: +SKIP
    True
    """

    title = 'Rayleigh Scattering'

    cmfs = get_cmfs(cmfs)

    settings = {
        'title': title,
        'y_label': 'Optical Depth'}
    settings.update(kwargs)

    spd = rayleigh_scattering_spd(cmfs.shape,
                                  CO2_concentration,
                                  temperature,
                                  pressure,
                                  latitude,
                                  altitude)

    return single_spd_plot(spd, **settings)
Beispiel #3
0
def single_rayleigh_scattering_spd_plot(
        CO2_concentration=STANDARD_CO2_CONCENTRATION,
        temperature=STANDARD_AIR_TEMPERATURE,
        pressure=AVERAGE_PRESSURE_MEAN_SEA_LEVEL,
        latitude=DEFAULT_LATITUDE,
        altitude=DEFAULT_ALTITUDE,
        cmfs='CIE 1931 2 Degree Standard Observer',
        **kwargs):
    """
    Plots a single rayleigh scattering spectral power distribution.

    Parameters
    ----------
    CO2_concentration : numeric, optional
        :math:`CO_2` concentration in parts per million (ppm).
    temperature : numeric, optional
        Air temperature :math:`T[K]` in kelvin degrees.
    pressure : numeric
        Surface pressure :math:`P` of the measurement site.
    latitude : numeric, optional
        Latitude of the site in degrees.
    altitude : numeric, optional
        Altitude of the site in meters.
    cmfs : unicode, optional
        Standard observer colour matching functions.
    \**kwargs : dict, optional
        Keywords arguments.

    Returns
    -------
    Figure
        Current figure or None.

    Examples
    --------
    >>> single_rayleigh_scattering_spd_plot()  # doctest: +SKIP
    """

    title = 'Rayleigh Scattering'

    cmfs = get_cmfs(cmfs)

    settings = {
        'title': title,
        'y_label': 'Optical Depth'}
    settings.update(kwargs)

    spd = rayleigh_scattering_spd(cmfs.shape,
                                  CO2_concentration,
                                  temperature,
                                  pressure,
                                  latitude,
                                  altitude)

    return single_spd_plot(spd, **settings)
Beispiel #4
0
def the_blue_sky_plot(cmfs='CIE 1931 2 Degree Standard Observer', **kwargs):
    """
    Plots the blue sky.

    Parameters
    ----------
    cmfs : unicode, optional
        Standard observer colour matching functions.
    \**kwargs : dict, optional
        Keywords arguments.

    Returns
    -------
    bool
        Definition success.

    Examples
    --------
    >>> the_blue_sky_plot()  # doctest: +SKIP
    True
    """

    canvas(**kwargs)

    cmfs, name = get_cmfs(cmfs), cmfs

    ASTM_G_173_spd = ASTM_G_173_ETR.clone()
    rayleigh_spd = rayleigh_scattering_spd()
    ASTM_G_173_spd.align(rayleigh_spd.shape)

    spd = rayleigh_spd * ASTM_G_173_spd

    matplotlib.pyplot.subplots_adjust(hspace=0.4)

    matplotlib.pyplot.figure(1)
    matplotlib.pyplot.subplot(211)

    settings = {
        'title': 'The Blue Sky - Synthetic Spectral Power Distribution',
        'y_label': u'W / m-2 / nm-1',
        'standalone': False
    }
    settings.update(kwargs)

    single_spd_plot(spd, name, **settings)

    matplotlib.pyplot.subplot(212)

    settings = {
        'title':
        'The Blue Sky - Colour',
        'x_label': ('The sky is blue because molecules in the atmosphere '
                    'scatter shorter wavelengths more than longer ones.\n'
                    'The synthetic spectral power distribution is computed as '
                    'follows: '
                    '(ASTM G-173 ETR * Standard Air Rayleigh Scattering).'),
        'y_label':
        '',
        'aspect':
        None,
        'standalone':
        False
    }

    blue_sky_color = XYZ_to_sRGB(spectral_to_XYZ(spd))
    single_colour_plot(ColourParameter('', normalise(blue_sky_color)),
                       **settings)

    settings = {'standalone': True}
    settings.update(kwargs)

    boundaries(**settings)
    decorate(**settings)

    return display(**settings)
Beispiel #5
0
    780: 84.19,
    782: 84.19,
    784: 84.21,
    786: 84.22,
    788: 84.25,
    790: 84.29,
    792: 84.29,
    794: 84.31,
    796: 84.31,
    798: 84.34,
    800: 84.34,
    820: 84.47
}

message_box('Plotting various single spectral power distributions.')
single_spd_plot(
    colour.SpectralPowerDistribution(sample_spd_data, name='Custom'))
single_spd_plot(
    colour.SpectralPowerDistribution(galvanized_steel_metal_spd_data,
                                     name='Galvanized Steel Metal'))

print('\n')

message_box('Plotting multiple spectral power distributions.')
multi_spd_plot(
    (colour.SpectralPowerDistribution(galvanized_steel_metal_spd_data,
                                      name='Galvanized Steel Metal'),
     colour.SpectralPowerDistribution(white_marble_spd_data,
                                      name='White Marble')))

print('\n')
Beispiel #6
0
def the_blue_sky_plot(
        cmfs='CIE 1931 2 Degree Standard Observer',
        **kwargs):
    """
    Plots the blue sky.

    Parameters
    ----------
    cmfs : unicode, optional
        Standard observer colour matching functions.
    \*\*kwargs : \*\*
        Keywords arguments.

    Returns
    -------
    bool
        Definition success.

    Examples
    --------
    >>> the_blue_sky_plot()  # doctest: +SKIP
    True
    """

    canvas(**kwargs)

    cmfs, name = get_cmfs(cmfs), cmfs

    ASTM_G_173_spd = ASTM_G_173_ETR.clone()
    rayleigh_spd = rayleigh_scattering_spd()
    ASTM_G_173_spd.align(rayleigh_spd.shape)

    spd = rayleigh_spd * ASTM_G_173_spd

    matplotlib.pyplot.subplots_adjust(hspace=0.4)

    matplotlib.pyplot.figure(1)
    matplotlib.pyplot.subplot(211)

    settings = {
        'title': 'The Blue Sky - Synthetic Spectral Power Distribution',
        'y_label': u'W / m-2 / nm-1',
        'standalone': False}
    settings.update(kwargs)

    single_spd_plot(spd, name, **settings)

    matplotlib.pyplot.subplot(212)

    settings = {
        'title': 'The Blue Sky - Colour',
        'x_label': ('The sky is blue because molecules in the atmosphere '
                    'scatter shorter wavelengths more than longer ones.\n'
                    'The synthetic spectral power distribution is computed as '
                    'follows: '
                    '(ASTM G-173 ETR * Standard Air Rayleigh Scattering).'),
        'y_label': '',
        'aspect': None,
        'standalone': False}

    blue_sky_color = XYZ_to_sRGB(spectral_to_XYZ(spd))
    single_colour_plot(colour_parameter('', normalise(blue_sky_color)),
                       **settings)

    settings = {'standalone': True}
    settings.update(kwargs)

    boundaries(**settings)
    decorate(**settings)
    return display(**settings)
Beispiel #7
0
seed(20180501)
from iminuit import Minuit, describe, Struct
from iminuit.util import make_func_code # lo utiliza Chi2Functor
from math import pi, exp, sqrt
#import colour.colorimetry as colorimetry

"""
Conviete valores RGB cualquiera, dado como constante, a xy y lo grafica como un punto dentro chromaticity diagram standar 
"""
from colour.plotting import (
    colour_plotting_defaults, chromaticity_diagram_plot_CIE1931,render,single_spd_plot)

# Defining a sample spectral power distribution data.
sample_spd_data = {380+i*5: random() for i in range(80)}
spd = colour.SpectralPowerDistribution(sample_spd_data)
single_spd_plot(spd)
cmfs = colour.STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer']
XYZ = colour.spectral_to_XYZ(spd, cmfs)
#ch1=colour.XYZ_to_spectral(XYZ,Method='Meng 2015')
ch1=colour.XYZ_to_spectral(XYZ,Method='Smits 1999')
single_spd_plot(ch1)
#spd_rec=ch1.values
y=ch1.values
x=[360+i*5 for i in range(95)]
#for i, v in enumerate(spd_rec):
#    x=360+i*5
#    y=v
#this is very useful if you want to build a generic cost functor
#this is actually how probfit is implemented
#x=sorted(sample_spd_data.keys())
#y=sorted(sample_spd_data.values())
Beispiel #8
0
def the_blue_sky_plot(cmfs='CIE 1931 2 Degree Standard Observer', **kwargs):
    """
    Plots the blue sky.

    Parameters
    ----------
    cmfs : unicode, optional
        Standard observer colour matching functions.

    Other Parameters
    ----------------
    \**kwargs : dict, optional
        {:func:`colour.plotting.render`},
        Please refer to the documentation of the previously listed definition.

    Returns
    -------
    Figure
        Current figure or None.

    Examples
    --------
    >>> the_blue_sky_plot()  # doctest: +SKIP
    """

    canvas(**kwargs)

    cmfs, name = get_cmfs(cmfs), cmfs

    ASTM_G_173_spd = ASTM_G_173_ETR.copy()
    rayleigh_spd = rayleigh_scattering_spd()
    ASTM_G_173_spd.align(rayleigh_spd.shape)

    spd = rayleigh_spd * ASTM_G_173_spd

    matplotlib.pyplot.subplots_adjust(hspace=0.4)

    matplotlib.pyplot.figure(1)
    matplotlib.pyplot.subplot(211)

    settings = {
        'title': 'The Blue Sky - Synthetic Spectral Power Distribution',
        'y_label': u'W / m-2 / nm-1',
        'standalone': False
    }
    settings.update(kwargs)

    single_spd_plot(spd, name, **settings)

    matplotlib.pyplot.subplot(212)

    settings = {
        'title':
            'The Blue Sky - Colour',
        'x_label': ('The sky is blue because molecules in the atmosphere '
                    'scatter shorter wavelengths more than longer ones.\n'
                    'The synthetic spectral power distribution is computed as '
                    'follows: '
                    '(ASTM G-173 ETR * Standard Air Rayleigh Scattering).'),
        'y_label':
            '',
        'aspect':
            None,
        'standalone':
            False
    }

    blue_sky_color = XYZ_to_sRGB(spectral_to_XYZ(spd))
    single_colour_swatch_plot(
        ColourSwatch('', normalise_maximum(blue_sky_color)), **settings)

    settings = {'standalone': True}
    settings.update(kwargs)

    return render(**settings)
Beispiel #9
0
def index():
    cmfs = CMFS['CIE 1931 2 Degree Standard Observer']
    with open('test.txt') as f:
        data = pd.read_csv(f, sep="\t" or ' ' or ',', header=None)
        f.close()
    w = [i[0] for i in data.values]
    s = [i[1] for i in data.values]
    data_formated = dict(zip(w, s))
    spd = SpectralPowerDistribution('Sample', data_formated)
    b = single_spd_plot(spd,
                        standalone=False,
                        figure_size=(5, 5),
                        title='Spectrum')
    figfile_b = StringIO()
    b.savefig(figfile_b, format='svg')
    figfile_b.seek(0)
    figdata_svg_b = '<svg' + figfile_b.getvalue().split('<svg')[1]
    b.clf()
    plot.close(b)
    illuminant = ILLUMINANTS_RELATIVE_SPDS['D50']
    XYZ = spectral_to_XYZ(spd, cmfs, illuminant)
    xy = XYZ_to_xy(XYZ)
    print(xy)
    cct = xy_to_CCT(xy)
    print(cct)
    cri = colour_rendering_index(spd, additional_data=True)
    print(cri.Q_a)
    Q_as = cri.Q_as
    y = [s[1].Q_a for s in sorted(Q_as.items(), key=lambda s: s[0])]
    print(y)
    single_spd_colour_rendering_index_bars_plot(spd,
                                                standalone=False,
                                                figure_size=(7, 7),
                                                title='Colour rendering index')
    c = plot.gcf()
    figfile_c = StringIO()
    c.savefig(figfile_c, format='svg')
    figfile_c.seek(0)
    figdata_svg_c = '<svg' + figfile_c.getvalue().split('<svg')[1]
    c.clf()
    plot.close(c)

    CIE_1931_chromaticity_diagram_plot(standalone=False,
                                       figure_size=(6, 5),
                                       grid=False,
                                       title='CIE 1931 Chromaticity Diagram',
                                       bounding_box=(-0.1, 0.9, -0.05, 0.95))
    x, y = xy
    pylab.plot(x, y, 'o-', color='white')
    pylab.annotate((("%.4f" % x), ("%.4f" % y)),
                   xy=xy,
                   xytext=(-50, 30),
                   textcoords='offset points',
                   arrowprops=dict(arrowstyle='->',
                                   connectionstyle='arc3, rad=-0.2'))

    a = plot.gcf()
    figfile = StringIO()
    a.savefig(figfile, format='svg')
    figfile.seek(0)
    figdata_svg = '<svg' + figfile.getvalue().split('<svg')[1]
    a.clf()
    plot.close(a)
    del a, b, c
    # pprint.pprint(figdata_svg)
    return render_template('index.html',
                           spd=figdata_svg_b,
                           result=figdata_svg,
                           colour_rendering_index=figdata_svg_c)
Beispiel #10
0
 def spd_plot(self):
     cpt.single_spd_plot(self.spd)