Skip to content

Commit d95fc67

Browse files
committed
Add set/get viewport on image_label to interface definition
1 parent 51d7582 commit d95fc67

File tree

1 file changed

+54
-26
lines changed

1 file changed

+54
-26
lines changed

src/astro_image_display_api/interface_definition.py

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class ImageViewerInterface(Protocol):
3030
# do any checking at all of these types.
3131
image_width: int
3232
image_height: int
33-
zoom_level: float
3433
cursor: str
3534
marker: Any
3635

@@ -47,7 +46,7 @@ class ImageViewerInterface(Protocol):
4746

4847
# Method for loading image data
4948
@abstractmethod
50-
def load_image(self, data: Any) -> None:
49+
def load_image(self, data: Any, image_label: str | None = None) -> None:
5150
"""
5251
Load data into the viewer. At a minimum, this should allow a FITS file
5352
to be loaded. Viewers may allow additional data types to be loaded, such as
@@ -217,42 +216,71 @@ def get_markers(self, x_colname: str = 'x', y_colname: str = 'y',
217216

218217
# Methods that modify the view
219218
@abstractmethod
220-
def center_on(self, point: tuple | SkyCoord):
219+
def set_viewport(
220+
self, center: SkyCoord | tuple[float, float] | None = None,
221+
fov: Quantity | float | None = None,
222+
image_label: str | None = None
223+
) -> None:
221224
"""
222-
Center the view on the point.
225+
Set the viewport of the image, which defines the center and field of viea.
223226
224227
Parameters
225228
----------
226-
tuple or `~astropy.coordinates.SkyCoord`
227-
If tuple of ``(X, Y)`` is given, it is assumed
228-
to be in data coordinates.
229+
center : `astropy.coordinates.SkyCoord` or tuple of float, optional
230+
The center of the viewport. If not given, the current center is used.
231+
fov : `astropy.units.Quantity` or float, optional
232+
The field of view (FOV) of the viewport. If not given, the current FOV
233+
is used. If a float is given, it is interpreted a size in pixels.
234+
image_label : str, optional
235+
The label of the image to set the viewport for. If not given and there is
236+
only one image loaded, the viewport for that image is set. If there are
237+
multiple images and no label is provided, an error is raised.
238+
239+
Raises
240+
------
241+
TypeError
242+
If the `center` is not a `SkyCoord` object or a tuple of floats, or if
243+
the `fov` is not a angular `Quantity` or a float
244+
245+
ValueError
246+
If `image_label` is not provided when there are multiple images loaded.
247+
248+
`astropy.units.UnitTypeError`
249+
If the `fov` is a `Quantity` but does not have an angular unit.
229250
"""
230251
raise NotImplementedError
231252

232253
@abstractmethod
233-
def offset_by(self, dx: float | Quantity, dy: float | Quantity) -> None:
254+
def get_viewport(self, sky_or_pixel: str | None = None, image_label: str | None = None) -> dict[str, Any]:
234255
"""
235-
Move the center to a point that is given offset
236-
away from the current center.
256+
Get the current viewport of the image.
237257
238258
Parameters
239259
----------
240-
dx, dy : float or `~astropy.units.Quantity`
241-
Offset value. Without a unit, assumed to be pixel offsets.
242-
If a unit is attached, offset by pixel or sky is assumed from
243-
the unit.
244-
"""
245-
raise NotImplementedError
246-
247-
@abstractmethod
248-
def zoom(self, val: float) -> None:
249-
"""
250-
Zoom in or out by the given factor.
260+
sky_or_pixel : str, optional
261+
If 'sky', the center will be returned as a `SkyCoord` object.
262+
If 'pixel', the center will be returned as a tuple of pixel coordinates.
263+
If `None`, the default behavior is to return the center as a `SkyCoord` if
264+
possible, or as a tuple of floats if the image is in pixel coordinates and has
265+
no WCS information.
266+
image_label : str, optional
267+
The label of the image to get the viewport for. If not given and there is only one
268+
image loaded, the viewport for that image is returned. If there are multiple images
269+
and no label is provided, an error is raised.
251270
252-
Parameters
253-
----------
254-
val : float
255-
The zoom level to zoom the image.
256-
See `zoom_level`.
271+
Returns
272+
-------
273+
dict
274+
A dictionary containing the current viewport settings.
275+
The keys are 'center', 'fov', and 'image_label'.
276+
- 'center' is an `astropy.coordinates.SkyCoord` object or a tuple of floats.
277+
- 'fov' is an `astropy.units.Quantity` object or a float.
278+
- 'image_label' is a string representing the label of the image.
279+
280+
Raises
281+
-------
282+
ValueError
283+
If the `sky_or_pixel` parameter is not one of 'sky', 'pixel', or `None`, or if
284+
the `image_label` is not provided when there are multiple images loaded.
257285
"""
258286
raise NotImplementedError

0 commit comments

Comments
 (0)