Skip to content

Commit

Permalink
Modified the wavelength argument of colorsynth.colorbar() to have…
Browse files Browse the repository at this point in the history
… a default value of `None`. (#4)
  • Loading branch information
byrdie authored Jul 21, 2024
1 parent 6d20ca2 commit f2683d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions colorsynth/_colorsynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def rgb(

def colorbar(
spd: np.ndarray,
wavelength: u.Quantity,
wavelength: None | u.Quantity = None,
axis: int = -1,
spd_min: None | np.ndarray = None,
spd_max: None | np.ndarray = None,
Expand All @@ -785,7 +785,9 @@ def colorbar(
spd
a spectral power distribution to be converted into a RGB array
wavelength
the wavelength array corresponding to the spectral power distribution
The wavelength array corresponding to the spectral power distribution.
If :obj:`None`, the wavelength is assumed to be evenly sampled across
the human visible color range.
axis
the logical axis corresponding to changing wavelength,
or the axis along which to integrate the spectral power distribution
Expand All @@ -808,6 +810,12 @@ def colorbar(
an optional function to transform the wavelength values before they
are mapped into the human visible color range.
"""
if wavelength is None:
shape_wavelength = [1] * spd.ndim
shape_wavelength[axis] = -1
wavelength = np.linspace(0, 1, num=spd.shape[axis])
wavelength = wavelength.reshape(shape_wavelength)

spd, wavelength = np.broadcast_arrays(spd, wavelength, subok=True)

transform_spd_wavelength = _transform_spd_wavelength(
Expand Down
1 change: 1 addition & 0 deletions colorsynth/_tests/test_colorsynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def test_rgb(
@pytest.mark.parametrize(
argnames="wavelength",
argvalues=[
None,
np.linspace(380, 780, num=101) * u.nm,
],
)
Expand Down

0 comments on commit f2683d3

Please sign in to comment.