<commit_before>"""
Blackbody - Planckian Radiator
==============================

Defines the objects to compute the spectral radiance of a planckian radiator
and its spectral distribution.

References
----------
-   :cite:`CIETC1-482004i` : CIE TC 1-48. (2004). APPENDIX E. INFORMATION ON
    THE USE OF PLANCK'S EQUATION FOR STANDARD AIR. In CIE 015:2004 Colorimetry,
    3rd Edition (pp. 77-82). ISBN:978-3-901906-33-6
"""

from __future__ import annotations

import numpy as np

from colour.colorimetry import (
    SPECTRAL_SHAPE_DEFAULT,
    SpectralDistribution,
    SpectralShape,
)
from colour.hints import Floating, FloatingOrArrayLike, FloatingOrNDArray
from colour.utilities import as_float_array

__author__ = "Colour Developers"
__copyright__ = "Copyright (C) 2013-2022 - Colour Developers"
__license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause"
__maintainer__ = "Colour Developers"
__email__ = "<EMAIL>"
__status__ = "Production"

__all__ = [
    "CONSTANT_C1",
    "CONSTANT_C2",
    "CONSTANT_N",
    "planck_law",
    "blackbody_spectral_radiance",
    "sd_blackbody",
]

# 2 * math.pi * CONSTANT_PLANCK * CONSTANT_LIGHT_SPEED ** 2
CONSTANT_C1: float = 3.741771e-16

# CONSTANT_PLANCK * CONSTANT_LIGHT_SPEED / CONSTANT_BOLTZMANN
CONSTANT_C2: float = 1.4388e-2

CONSTANT_N: float = 1


def planck_law(
    wavelength: FloatingOrArrayLike,
    temperature: FloatingOrArrayLike,
    c1: Floating = CONSTANT_C1,
    c2: Floating = CONSTANT_C2,
    n: Floating = CONSTANT_N,
) -> FloatingOrNDArray:
    """
    Returns the spectral radiance of a blackbody at thermodynamic temperature
    :math:`T[K]` in a medium having index of refraction :math:`n`.

    Parameters
    ----------
    wavelength
        Wavelength in meters.
    temperature
        Temperature :math:`T[K]` in kelvin degrees.
    c1
        The official value of :math:`c1` is provided by the Committee on Data
        for Science and Technology (CODATA) and is
        :math:`c1=3,741771x10.16\\ W/m_2` *(Mohr and Taylor, 2000)*.
    c2
        Since :math:`T` is measured on the International Temperature Scale,
        the value of :math:`c2` used in colorimetry should follow that adopted
        in the current International Temperature Scale (ITS-90)
        *(Preston-Thomas, 1990; Mielenz et aI., 1991)*, namely
        :math:`c2=1,4388x10.2\\ m/K`.
    n
        Medium index of refraction. For dry air at 15C and 101 325 Pa,
        containing 0,03 percent by volume of carbon dioxide, it is
        approximately 1,00028 throughout the visible region although
        *CIE 15:2004* recommends using :math:`n=1`.

    Returns
    -------
    :class:`numpy.floating` or :class:`numpy.ndarray`
        Radiance in *watts per steradian per square metre* (:math:`W/sr/m^2`).

    Notes
    -----
    -   The following form implementation is expressed in term of wavelength.
    -   The SI unit of radiance is *watts per steradian per square metre*
        (:math:`W/sr/m^2`).

    References
    ----------
    :cite:`CIETC1-482004i`

    Examples
    --------
    >>> planck_law(500 * 1e-9, 5500)  # doctest: +ELLIPSIS
    20472701909806.5...
    """

    l = as_float_array(wavelength)  # noqa
    t = as_float_array(temperature)

    p = ((c1 * n ** -2 * l ** -5) / np.pi) * (
        np.exp(c2 / (n * l * t)) - 1
    ) ** -1

    return p


blackbody_spectral_radiance = planck_law


def sd_blackbody(
    temperature: Floating,
    shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT,
    c1: Floating = CONSTANT_C1,
    c2: Floating = CONSTANT_C2,
    n: Floating = CONSTANT_N,
) -> SpectralDistribution:
    """
    Returns the spectral distribution of the planckian radiator for given
    temperature :math:`T[K]` with values in
    *watts per steradian per square metre per nanometer* (:math:`W/sr/m^2/nm`).

    Parameters
    ----------
    temperature
        Temperature :math:`T[K]` in kelvin degrees.
    shape
        Spectral shape used to create the spectral distribution of the
        planckian radiator.
    c1
        The official value of :math:`c1` is provided by the Committee on Data
        for Science and Technology (CODATA) and is
        :math:`c1=3,741771x10.16\\ W/m_2` *(Mohr and Taylor, 2000)*.<commit_msg>use np.expm1() instead of np.exp() - 1<commit_after>"""
Blackbody - Planckian Radiator
==============================

Defines the objects to compute the spectral radiance of a planckian radiator
and its spectral distribution.

References
----------
-   :cite:`CIETC1-482004i` : CIE TC 1-48. (2004). APPENDIX E. INFORMATION ON
    THE USE OF PLANCK'S EQUATION FOR STANDARD AIR. In CIE 015:2004 Colorimetry,
    3rd Edition (pp. 77-82). ISBN:978-3-901906-33-6
"""

from __future__ import annotations

import numpy as np

from colour.colorimetry import (
    SPECTRAL_SHAPE_DEFAULT,
    SpectralDistribution,
    SpectralShape,
)
from colour.hints import Floating, FloatingOrArrayLike, FloatingOrNDArray
from colour.utilities import as_float_array

__author__ = "Colour Developers"
__copyright__ = "Copyright (C) 2013-2022 - Colour Developers"
__license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause"
__maintainer__ = "Colour Developers"
__email__ = "<EMAIL>"
__status__ = "Production"

__all__ = [
    "CONSTANT_C1",
    "CONSTANT_C2",
    "CONSTANT_N",
    "planck_law",
    "blackbody_spectral_radiance",
    "sd_blackbody",
]

# 2 * math.pi * CONSTANT_PLANCK * CONSTANT_LIGHT_SPEED ** 2
CONSTANT_C1: float = 3.741771e-16

# CONSTANT_PLANCK * CONSTANT_LIGHT_SPEED / CONSTANT_BOLTZMANN
CONSTANT_C2: float = 1.4388e-2

CONSTANT_N: float = 1


def planck_law(
    wavelength: FloatingOrArrayLike,
    temperature: FloatingOrArrayLike,
    c1: Floating = CONSTANT_C1,
    c2: Floating = CONSTANT_C2,
    n: Floating = CONSTANT_N,
) -> FloatingOrNDArray:
    """
    Returns the spectral radiance of a blackbody at thermodynamic temperature
    :math:`T[K]` in a medium having index of refraction :math:`n`.

    Parameters
    ----------
    wavelength
        Wavelength in meters.
    temperature
        Temperature :math:`T[K]` in kelvin degrees.
    c1
        The official value of :math:`c1` is provided by the Committee on Data
        for Science and Technology (CODATA) and is
        :math:`c1=3,741771x10.16\\ W/m_2` *(<NAME>, 2000)*.
    c2
        Since :math:`T` is measured on the International Temperature Scale,
        the value of :math:`c2` used in colorimetry should follow that adopted
        in the current International Temperature Scale (ITS-90)
        *(Preston-Thomas, 1990; Mielenz et aI., 1991)*, namely
        :math:`c2=1,4388x10.2\\ m/K`.
    n
        Medium index of refraction. For dry air at 15C and 101 325 Pa,
        containing 0,03 percent by volume of carbon dioxide, it is
        approximately 1,00028 throughout the visible region although
        *CIE 15:2004* recommends using :math:`n=1`.

    Returns
    -------
    :class:`numpy.floating` or :class:`numpy.ndarray`
        Radiance in *watts per steradian per square metre* (:math:`W/sr/m^2`).

    Notes
    -----
    -   The following form implementation is expressed in term of wavelength.
    -   The SI unit of radiance is *watts per steradian per square metre*
        (:math:`W/sr/m^2`).

    References
    ----------
    :cite:`CIETC1-482004i`

    Examples
    --------
    >>> planck_law(500 * 1e-9, 5500)  # doctest: +ELLIPSIS
    20472701909806.5...
    """

    l = as_float_array(wavelength)  # noqa
    t = as_float_array(temperature)

    p = ((c1 * n ** -2 * l ** -5) / np.pi) * (np.expm1(c2 / (n * l * t))) ** -1

    return p


blackbody_spectral_radiance = planck_law


def sd_blackbody(
    temperature: Floating,
    shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT,
    c1: Floating = CONSTANT_C1,
    c2: Floating = CONSTANT_C2,
    n: Floating = CONSTANT_N,
) -> SpectralDistribution:
    """
    Returns the spectral distribution of the planckian radiator for given
    temperature :math:`T[K]` with values in
    *watts per steradian per square metre per nanometer* (:math:`W/sr/m^2/nm`).

    Parameters
    ----------
    temperature
        Temperature :math:`T[K]` in kelvin degrees.
    shape
        Spectral shape used to create the spectral distribution of the
        planckian radiator.
    c1
        The official value of :math:`c1` is provided by the Committee on Data
        for Science and Technology (CODATA) and is
        :math:`c1=3,741771x10.16\\ W/m_2` *(Mo<NAME>, 2000)*.
{'fraction_non_alphanumeric': 0.1166215101896572, 'fraction_numerical': 0.04759100011779951, 'mean_word_length': 2.892709766162311, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7296570', 'n_tokens_mistral': 3141, 'n_tokens_neox': 2813, 'n_words': 831}