Skip to content

Commit

Permalink
Renamed spectral_radiance to spd.
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Nov 16, 2023
1 parent 82e8047 commit 95cb9f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
32 changes: 16 additions & 16 deletions colorsynth/_colorsynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,33 +282,33 @@ def color_matching_xyz(


def cie_1931_tristimulus(
spectral_radiance: np.ndarray,
spd: np.ndarray,
wavelength: u.Quantity,
axis: int = -1,
) -> np.ndarray:
"""
Calculate the CIE 1931 tristimulus values, :math:`X`, :math:`Y`, and :math:`Z`,
for the given spectral radiance.
for the given spectral power distribution.
Parameters
----------
spectral_radiance
the spectral radiance of an emitting source as a function of wavelength
spd
the spectral power distribution of an emitting source as a function of wavelength
wavelength
the wavelength grid corresponding to the spectral radiance.
the wavelength grid corresponding to the spectral power distribution.
axis
the wavelength axis, or the axis along which to integrate
"""
spectral_radiance, wavelength = np.broadcast_arrays(
spectral_radiance,
spd, wavelength = np.broadcast_arrays(
spd,
wavelength,
subok=True,
)

axis = ~(~axis % spectral_radiance.ndim)
axis = ~(~axis % spd.ndim)

xyz = color_matching_xyz(wavelength, axis=0)
integrand = spectral_radiance * xyz
integrand = spd * xyz

result = np.trapz(
x=wavelength,
Expand Down Expand Up @@ -387,7 +387,7 @@ def srgb(
Examples
--------
Plot a 2d set of random spectral radiance curves as a color image
Plot a 2d set of random spectral power distribution curves as a color image
.. jupyter-execute::
Expand All @@ -402,11 +402,11 @@ def srgb(
# Define an evenly-spaced grid of wavelengths
wavelength = np.linspace(380, 780, num=num) * u.nm
# Define a random spectral radiance cube by sampling from a uniform distribution
spectral_radiance = np.random.uniform(size=(16, 16, num))
# Define a random spectral power distribution cube by sampling from a uniform distribution
spd = np.random.uniform(size=(16, 16, num))
# Calculate the CIE 1931 tristimulus values from the specdtral radiance
xyz = colorsynth.cie_1931_tristimulus(spectral_radiance, wavelength)
xyz = colorsynth.cie_1931_tristimulus(spd, wavelength)
# Normalize the tristimulus values based on the max value of the Y parameter
xyz = xyz / xyz[..., 1].max()
Expand All @@ -422,17 +422,17 @@ def srgb(
|
Plot the response curves of the :math:`R`, :math:`G`, and :math:`B` to
a constant spectral radiance
a constant spectral power distribution
.. jupyter-execute::
# Define an evenly-spaced grid of wavelengths
wavelength = np.linspace(380, 780, num=101) * u.nm
spectral_radiance = np.diagflat(np.ones(wavelength.shape))
spd = np.diagflat(np.ones(wavelength.shape))
# Calculate the CIE 1931 tristimulus values from the specdtral radiance
xyz = colorsynth.cie_1931_tristimulus(spectral_radiance, wavelength[..., np.newaxis], axis=0)
xyz = colorsynth.cie_1931_tristimulus(spd, wavelength[..., np.newaxis], axis=0)
# Normalize the tristimulus values based on the max value of the Y parameter
xyz = xyz / xyz.max(axis=1, keepdims=True)
Expand Down
6 changes: 3 additions & 3 deletions colorsynth/_tests/test_colorsynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_color_matching_xyz(


@pytest.mark.parametrize(
argnames="spectral_radiance",
argnames="spd",
argvalues=[
np.random.uniform(size=(101,)),
np.random.uniform(size=(64, 64, 101)),
Expand All @@ -76,12 +76,12 @@ def test_color_matching_xyz(
)
@pytest.mark.parametrize(argnames="axis", argvalues=[0, -1])
def test_cie_1931_tristimulus(
spectral_radiance: np.ndarray,
spd: np.ndarray,
wavelength: u.Quantity,
axis: int,
):
result = colorsynth.cie_1931_tristimulus(
spectral_radiance=spectral_radiance,
spd=spd,
wavelength=wavelength,
axis=axis,
)
Expand Down

0 comments on commit 95cb9f8

Please sign in to comment.