Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the wavelength argument of colorsynth.colorbar() to have a default value of None. #4

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading