Skip to content

Commit 2a82f88

Browse files
committed
Implement img_source() for LoadedSpatialImage and make img_source() an abstract method
1 parent 7b50196 commit 2a82f88

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

src/spatialexperiment/SpatialImage.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ def dimensions(self) -> Tuple[int, int]:
109109
######>> img utils <<#######
110110
############################
111111

112+
@abstractmethod
113+
def img_source(self, as_path: bool = False) -> Union[str, None]:
114+
"""Get the source of the image.
115+
116+
Args:
117+
as_path: If True, returns path as string. Defaults to False.
118+
119+
Returns:
120+
Source path/URL of the image, or None if loaded in memory.
121+
"""
122+
pass
123+
112124
@abstractmethod
113125
def img_raster(self) -> Image.Image:
114126
"""Get the image as a PIL Image object."""
@@ -290,6 +302,14 @@ def image(self, image: Union[Image.Image, np.ndarray]):
290302
)
291303
return self.set_image(image=image, in_place=True)
292304

305+
def img_source(self, as_path: bool = False) -> None:
306+
"""Get the source of the loaded image.
307+
308+
Returns:
309+
Always returns None.
310+
"""
311+
return None
312+
293313
############################
294314
######>> img utils <<#######
295315
############################
@@ -450,7 +470,14 @@ def path(self, path: Union[str, Path]):
450470
return self.set_path(path=path, in_place=True)
451471

452472
def img_source(self, as_path: bool = False) -> str:
453-
"""Get the source path of the image."""
473+
"""Get the source path of the image.
474+
475+
Args:
476+
as_path: If True, returns string path. Defaults to False.
477+
478+
Returns:
479+
Path to the image.
480+
"""
454481
return str(self._path) if as_path is True else self._path
455482

456483
############################
@@ -645,7 +672,14 @@ def img_raster(self) -> Image.Image:
645672
return Image.open(cache_path)
646673

647674
def img_source(self, as_path: bool = False) -> str:
648-
"""Get the source URL or cached path of the image."""
675+
"""Get the source URL or cached path of the image.
676+
677+
Args:
678+
as_path: If True, returns downloaded path. Defaults to False.
679+
680+
Returns:
681+
URL or cached path of the image.
682+
"""
649683
if as_path:
650684
return str(self._download_image())
651685
return self._url

0 commit comments

Comments
 (0)