Skip to content

Commit

Permalink
Backport PR spacetelescope#2731: Reverse gist_rainbow colors to match…
Browse files Browse the repository at this point in the history
… order of manual presets
  • Loading branch information
rosteen authored and meeseeksmachine committed Feb 27, 2024
1 parent 9aea674 commit ea0dcb0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Bug Fixes

- Fix redshifted line lists that were displaying at rest wavelengths, by assuming a global redshift. [#2726]

- Order of RGB preset colors now matches for less than and greater than 5 layers. [#2731]

Cubeviz
^^^^^^^

Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,10 @@ def apply_RGB_presets(self):
# Sample along a colormap if we have too many layers
if n_visible > len(preset_colors):
cmap = matplotlib.colormaps['gist_rainbow'].resampled(n_visible)
# Have to reverse the order of the cmap to make physical sense with
# assumed wavelength order of layers.
preset_colors = [matplotlib.colors.to_hex(cmap(i), keep_alpha=True) for
i in range(n_visible)]
i in range(n_visible - 1, -1, -1)]
elif n_visible >= 2 and n_visible < len(preset_colors):
preset_colors = [preset_colors[i] for i in preset_inds[n_visible]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,16 @@ def test_apply_presets(imviz_helper):
po.apply_RGB_presets()

assert po.layer.selected == "array_3"
assert po.stretch_function.value == "arcsinh"
po.layer = "array_5"
# Make sure this one didn't change
assert po.stretch_function.value == "linear"

# Turn layer 5 back on
po.image_visible = True
po.apply_RGB_presets()

colorbar_colors = matplotlib.colormaps['gist_rainbow'].resampled(7)
colorbar_colors = matplotlib.colormaps['gist_rainbow'].resampled(8)
color_ind = 0

def _rgb_to_hex(rgb):
Expand All @@ -298,15 +306,11 @@ def _rgb_to_hex(rgb):

for i in range(8):
po.layer = f"array_{i}"
if i == 5:
# Make sure this one didn't change
assert po.stretch_function.value == "linear"
else:
assert po.stretch_function.value == "arcsinh"
assert po.stretch_preset.value == 99
assert po.image_color.value == matplotlib.colors.to_hex(colorbar_colors(color_ind),
keep_alpha=True)
color_ind += 1
assert po.stretch_function.value == "arcsinh"
assert po.stretch_preset.value == 99
assert po.image_color.value == matplotlib.colors.to_hex(colorbar_colors(7-color_ind),
keep_alpha=True)
color_ind += 1


def test_track_mixed_states(imviz_helper):
Expand Down

0 comments on commit ea0dcb0

Please sign in to comment.