Skip to content

Commit

Permalink
Reverse preset color order (#2568)
Browse files Browse the repository at this point in the history
* Reverse preset color order

Add changelog

* End 4 color preset at red

* Fix codestyle

* Swap case order
  • Loading branch information
rosteen authored Nov 15, 2023
1 parent cfe7e25 commit 64e0974
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^
Expand Down
19 changes: 10 additions & 9 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 64e0974

Please sign in to comment.