diff --git a/CHANGES.rst b/CHANGES.rst index daa7eb4798..0ffabf7ea3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,7 +17,7 @@ New Features - Reorder viewer and layer settings in Plot Options. [#2543, #2557] -- Add button in Plot Options to apply preset RBG options to visible layers when in Monochromatic mode. [#2558] +- Add button in Plot Options to apply preset RBG options to visible layers when in Monochromatic mode. [#2558, #2568] Cubeviz ^^^^^^^ diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 0474113c03..4693dee1f1 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -616,13 +616,15 @@ def apply_RGB_presets(self): self.image_color_mode_sync['mixed']): raise ValueError("RGB presets can only be applied if color mode is Monochromatic.") # Preselected colors we want to use for 5 or less layers - preset_colors = [self.swatches_palette[0][0], - self.swatches_palette[1][0], - "#00FF00", + preset_colors = [self.swatches_palette[4][1], "#0000FF", - self.swatches_palette[4][1] + "#00FF00", + self.swatches_palette[1][0], + self.swatches_palette[0][0], ] + preset_inds = {2: [1, 4], 3: [1, 2, 4], 4: [1, 2, 3, 4]} + # Switch back to this at the end initial_layer = self.layer_selected @@ -639,15 +641,14 @@ def apply_RGB_presets(self): default_opacity = 1 if n_visible > 2: default_opacity = 1 / math.log2(n_visible) + # Sample along a colormap if we have too many layers - if n_visible == 2: - preset_colors = [preset_colors[0], preset_colors[3]] - elif n_visible == 3: - preset_colors = [preset_colors[0], preset_colors[2], preset_colors[3]] - elif n_visible > len(preset_colors): + if n_visible > len(preset_colors): cmap = matplotlib.colormaps['gist_rainbow'].resampled(n_visible) preset_colors = [matplotlib.colors.to_hex(cmap(i), keep_alpha=True) for i in range(n_visible)] + elif n_visible >= 2 and n_visible < len(preset_colors): + preset_colors = [preset_colors[i] for i in preset_inds[n_visible]] for i in range(n_visible): self.layer_selected = visible_layers[i] 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 6201c6e1e5..3a95bdeb81 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 @@ -257,8 +257,8 @@ def test_apply_presets(imviz_helper): arr = np.arange(36).reshape(6, 6) po = imviz_helper.plugins['Plot Options'] - preset_colors = [po._obj.swatches_palette[0][0], po._obj.swatches_palette[1][0], - "#00FF00", "#0000FF", po._obj.swatches_palette[4][1]] + preset_colors_4 = ["#0000FF", "#00FF00", po._obj.swatches_palette[1][0], + po._obj.swatches_palette[0][0]] # Test applying presets with < 6 layers @@ -272,7 +272,7 @@ def test_apply_presets(imviz_helper): po.layer = f"array_{i}" assert po.stretch_function.value == "arcsinh" assert po.stretch_preset.value == 99 - assert po.image_color.value == preset_colors[i] + assert po.image_color.value == preset_colors_4[i] # Test applying presets with > 5 layers