Skip to content

Commit 4344cd4

Browse files
committed
Implement colormap in dummy viewer
1 parent 21660b9 commit 4344cd4

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/astro_image_display_api/dummy_viewer.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from astropy.coordinates import SkyCoord
1111
from astropy.nddata import CCDData, NDData
1212
from astropy.table import Table, vstack
13-
from astropy.units import Quantity, get_physical_type
13+
from astropy.units import Quantity
1414
from astropy.wcs import WCS
1515
from astropy.wcs.utils import proj_plane_pixel_scales
1616
from astropy.visualization import AsymmetricPercentileInterval, BaseInterval, BaseStretch, LinearStretch, ManualInterval
@@ -37,6 +37,7 @@ class ViewportInfo:
3737
largest_dimension: int | None = None
3838
stretch: BaseStretch | None = None
3939
cuts: BaseInterval | tuple[numbers.Real, numbers.Real] | None = None
40+
colormap: str | None = None
4041

4142
@dataclass
4243
class ImageViewer:
@@ -58,6 +59,9 @@ class ImageViewer:
5859
# Allowed locations for cursor display
5960
ALLOWED_CURSOR_LOCATIONS: tuple = ImageViewerInterface.ALLOWED_CURSOR_LOCATIONS
6061

62+
# Minimal required colormaps
63+
MINIMUM_REQUIRED_COLORMAPS: tuple[str, ...] = ImageViewerInterface.MINIMUM_REQUIRED_COLORMAPS
64+
6165
# some internal variable for keeping track of viewer state
6266
_wcs: WCS | None = None
6367
_center: tuple[numbers.Real, numbers.Real] = (0.0, 0.0)
@@ -150,6 +154,30 @@ def set_cuts(self, value: tuple[numbers.Real, numbers.Real] | BaseInterval, imag
150154
raise ValueError(f"Image label '{image_label}' not found. Please load an image first.")
151155
self._images[image_label].cuts = self._cuts
152156

157+
@property
158+
def colormap_options(self) -> list[str]:
159+
return list(self.MINIMUM_REQUIRED_COLORMAPS)
160+
colormap_options.__doc__ = ImageViewerInterface.colormap_options.__doc__
161+
162+
def set_colormap(self, map_name: str, image_label: str | None = None) -> None:
163+
if map_name not in self.colormap_options:
164+
raise ValueError(f"Invalid colormap '{map_name}'. Must be one of {self.colormap_options}.")
165+
166+
image_label = self._resolve_image_label(image_label)
167+
if image_label not in self._images:
168+
raise ValueError(f"Image label '{image_label}' not found. Please load an image first.")
169+
self._images[image_label].colormap = map_name
170+
171+
set_colormap.__doc__ = ImageViewerInterface.set_colormap.__doc__
172+
173+
def get_colormap(self, image_label: str | None = None) -> str:
174+
image_label = self._resolve_image_label(image_label)
175+
if image_label not in self._images:
176+
raise ValueError(f"Image label '{image_label}' not found. Please load an image first.")
177+
return self._images[image_label].colormap
178+
179+
get_colormap.__doc__ = ImageViewerInterface.get_colormap.__doc__
180+
153181
@property
154182
def cursor(self) -> str:
155183
return self._cursor

0 commit comments

Comments
 (0)