-
-
Notifications
You must be signed in to change notification settings - Fork 4
covert shape-getting to method #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import os | ||
from abc import abstractmethod | ||
from typing import Any, Protocol, runtime_checkable | ||
from collections import namedtuple | ||
|
||
from astropy.coordinates import SkyCoord | ||
from astropy.table import Table | ||
|
@@ -10,17 +11,13 @@ | |
|
||
__all__ = [ | ||
"ImageViewerInterface", | ||
"ImageShape", | ||
] | ||
|
||
ImageShape = namedtuple("ImageShape", ["width", "height"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking out loud here...is there any way to avoid declaring Or, I suppose, we could follow the Array API specification and just return a plain tuple... Not against named tuples, but trying to think of ways to minimize the imports for backends. |
||
|
||
@runtime_checkable | ||
class ImageViewerInterface(Protocol): | ||
# These are attributes, not methods. The type annotations are there | ||
# to make sure Protocol knows they are attributes. Python does not | ||
# do any checking at all of these types. | ||
image_width: int | ||
image_height: int | ||
|
||
# The methods, grouped loosely by purpose | ||
|
||
# Method for loading image data | ||
|
@@ -201,6 +198,31 @@ def get_colormap(self, image_label: str | None = None) -> str: | |
""" | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def get_shape(self, image_label: str | None = None) -> ImageShape: | ||
""" | ||
Get the shape (i.e., width and height in pixels) of the image. | ||
|
||
Parameters | ||
---------- | ||
image_label : optional | ||
The label of the image to get the shape for. If not given and there is | ||
only one image loaded, the shape for that image is returned. If there are | ||
multiple images and no label is provided, an error is raised. | ||
|
||
Returns | ||
------- | ||
shape : `ImageShape`, a 2-tuple of ints | ||
A named tuple containing the width and height of the image in pixels. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
If the `image_label` is not provided when there are multiple images loaded, | ||
or if the `image_label` does not correspond to a loaded image. | ||
""" | ||
raise NotImplementedError | ||
|
||
# Saving contents of the view and accessing the view | ||
@abstractmethod | ||
def save(self, filename: str | os.PathLike, overwrite: bool = False) -> None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also add a test that
get_shape
returns anImageShape
?