Skip to content

Commit

Permalink
Rename monochromatic color mode and add descriptions (#2894)
Browse files Browse the repository at this point in the history
* show description in UI for color_mode
* deprecated API support for "Monochromatic"
* update tests/docs/comments
  • Loading branch information
kecnry authored May 24, 2024
1 parent 0b11723 commit 8f65073
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ New Features

- New "About" plugin to show Jdaviz version info. [#2886]

- Descriptions are shown in the color mode dropdown for image layers to help describe the use-cases
for ``Colormap`` vs ``Color``. [#2894]

Cubeviz
^^^^^^^

Expand All @@ -37,6 +40,10 @@ Specviz2d
API Changes
-----------

- The ``Monochromatic`` option for ``color_mode`` in plot options is now renamed to ``Color``.
``Monochromatic`` will continue to work with a deprecation warning, but may be removed in a
future release. [#2894]

Cubeviz
^^^^^^^

Expand Down
4 changes: 2 additions & 2 deletions docs/imviz/displayimages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ Color mode
----------

This option allows you to choose whether to use a colormap or or a single color to visualize the image.
The colormap can be selected from a dropdown within the Layer tab. In monochromatic mode, the color
The colormap can be selected from a dropdown within the Layer tab. In "Color" mode, the color
can be chosen from a color picker under "Image Color" within the Layer tab.

In monochromatic mode, the option "Assign RGB presets" appears. This will automatically
In "Color" mode, the option "Assign RGB presets" appears. This will automatically
assign colors spanning from blue to red to the available layers and will adjust opacity and
stretch to produce a composite color image (also known as RGB image). You will then
be able to fine tune all options within each Layer tab.
Expand Down
8 changes: 4 additions & 4 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class PlotOptions(PluginTemplateMixin):
* ``image_color_mode`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
not exposed for Specviz
* ``image_color`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
not exposed for Specviz. This only applies when ``image_color_mode`` is "Monochromatic".
not exposed for Specviz. This only applies when ``image_color_mode`` is "Color".
* ``image_colormap`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
not exposed for Specviz. This only applies when ``image_color_mode`` is "Colormap".
* ``image_opacity`` (:class:`~jdaviz.core.template_mixin.PlotOptionsSyncState`):
Expand Down Expand Up @@ -769,12 +769,12 @@ def vue_set_value(self, data):
def apply_RGB_presets(self):
"""
Applies preset colors, opacities, and stretch settings to all visible layers
(in all viewers) when in Monochromatic mode.
(in all viewers) when in Color (Monochromatic) mode.
"""

if (self.image_color_mode_value != "One color per layer" or
self.image_color_mode_sync['mixed']):
raise ValueError("RGB presets can only be applied if color mode is Monochromatic.")
raise ValueError("RGB presets can only be applied if color mode is Color.")
# Preselected colors we want to use for 5 or less layers
preset_colors = [self.swatches_palette[4][1],
"#0000FF",
Expand Down Expand Up @@ -1088,7 +1088,7 @@ def _update_stretch_curve(self, msg=None):
# Compute colormapped image
plane = layer_cmap(data)

else: # Monochromatic
else: # Color (Monochromatic)
# Get color
color = COLOR_CONVERTER.to_rgba_array(self.image_color_value)[0]
plane = data[:, np.newaxis] * color
Expand Down
24 changes: 20 additions & 4 deletions jdaviz/configs/default/plugins/plot_options/plot_options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,26 @@
:items="image_color_mode_sync.choices"
v-model="image_color_mode_value"
label="Color Mode"
hint="Whether each layer gets a single color or colormap"
persistent-hint
dense
></v-select>
hint="Whether each layer gets a single color or colormap."
persistent-hint
dense
>
<template v-slot:selection="{ item }">
<span>
{{ item.text }}
</span>
</template>
<template v-slot:item="{ item }">
<span>
<b>
{{ item.text }}
</b>
<span v-if="item.description" style="opacity: 0.85; font-size: 10pt">
| {{ item.description }}
</span>
</span>
</template>
</v-select>
</glue-state-sync-wrapper>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_apply_presets(imviz_helper):
for i in range(4):
imviz_helper.load_data(arr, data_label=f"array_{i}")

po.image_color_mode = "Monochromatic"
po.image_color_mode = "Color"
po.apply_RGB_presets()

for i in range(4):
Expand Down
14 changes: 12 additions & 2 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import bqplot
from contextlib import contextmanager
import numpy as np
import logging
import os
import threading
import time
Expand Down Expand Up @@ -4152,8 +4153,12 @@ def _get_glue_choices(self, state):
helper = getattr(state, f'{glue_name}_helper')
return [{'text': str(choice), 'value': str(choice)} for choice in helper.choices]
if glue_name == 'color_mode':
return [{'text': 'Colormap', 'value': 'Colormaps'},
{'text': 'Monochromatic', 'value': 'One color per layer'}]
return [{'text': 'Colormap',
'value': 'Colormaps',
'description': 'Select a colormap per-layer. Only top-layer will be visible without adjusting opacity.'}, # noqa
{'text': 'Color',
'value': 'One color per layer',
'description': 'Select a color per-layer. Layers will be composited.'}]

values, labels = _get_glue_choices(state, glue_name)
return [{'text': l, 'value': v} for v, l in zip(values, labels)]
Expand Down Expand Up @@ -4271,6 +4276,11 @@ def _on_value_changed(self, msg):
if self._spinner is not None:
setattr(self.plugin, self._spinner, True)

if self._glue_name == 'color_mode' and msg['new'] == 'Monochromatic':
logging.warning("DeprecationWarning: 'Monochromatic' renamed to 'Color'")
self.value = 'One color per layer'
return

self._processing_change_to_glue = True
for glue_state in self.linked_states:
glue_name = self.glue_name(glue_state)
Expand Down
4 changes: 2 additions & 2 deletions notebooks/concepts/cubeviz_ndarray_gif.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"outputs": [],
"source": [
"plot_plg.viewer = \"flux-viewer\"\n",
"plot_plg.image_color_mode = \"Monochromatic\"\n",
"plot_plg.image_color_mode = \"Color\"\n",
"plot_plg.image_color = \"Red\""
]
},
Expand All @@ -284,7 +284,7 @@
"outputs": [],
"source": [
"plot_plg.viewer = \"uncert-viewer\"\n",
"plot_plg.image_color_mode = \"Monochromatic\"\n",
"plot_plg.image_color_mode = \"Color\"\n",
"plot_plg.image_color = \"Blue\""
]
},
Expand Down
4 changes: 2 additions & 2 deletions notebooks/concepts/imviz_colorbar_mpl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Monochromatic\n",
"#plg.image_color_mode = \"Monochromatic\"\n",
"# Color (Monochromatic / RGB)\n",
"#plg.image_color_mode = \"Color\"\n",
"#plg.image_color = \"red\""
]
},
Expand Down
2 changes: 1 addition & 1 deletion notebooks/concepts/imviz_dithered_gwcs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"outputs": [],
"source": [
"# Set color mode to easily distinguish between them\n",
"imviz.plugins['Plot Options'].image_color_mode = 'Monochromatic'"
"imviz.plugins['Plot Options'].image_color_mode = 'Color'"
]
},
{
Expand Down

0 comments on commit 8f65073

Please sign in to comment.