From ea0dcb068224aa4cd13a6278519e03f54a74633e Mon Sep 17 00:00:00 2001 From: Ricky O'Steen <39831871+rosteen@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:41:02 -0500 Subject: [PATCH] Backport PR #2731: Reverse gist_rainbow colors to match order of manual presets --- CHANGES.rst | 2 ++ .../plugins/plot_options/plot_options.py | 4 +++- .../plot_options/tests/test_plot_options.py | 24 +++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index cf78772649..726cee6b9c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ^^^^^^^ diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 81c2f46597..68a55a07ca 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -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]] diff --git a/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py b/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py index 556f5a1fd7..29b37f91fc 100644 --- a/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/tests/test_plot_options.py @@ -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): @@ -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):