Skip to content

Images API

The Image API allows you to get information about the publicly available images on the CANFAR Science Platform through the CANFAR Harbor Registry. It can be used to get information about all images, or filter by a specific image kind.

Getting Image Information

Get image information
from skaha.images import Images

images = Images()
images.fetch()
[
    "images.canfar.net/canfar/base-3.12:v0.4.1",
    "images.canfar.net/canucs/test:1.2.5",
    "images.canfar.net/canucs/canucs:1.2.9",
    ...,
]

But most of the time, you are only interested in images of a particular type. For example, if you want to get all the images that are available for headless sessions, you can do the following:

Get headless image information
images.fetch(kind="headless")
[
    "images.canfar.net/chimefrb/testing:keep",
    "images.canfar.net/lsst/lsst_v19_0_0:0.1",
    "images.canfar.net/skaha/lensfit:22.11",
    "images.canfar.net/skaha/lensfit:22.10",
    "images.canfar.net/skaha/lensingsim:22.07",
    "images.canfar.net/skaha/phosim:5.6.11",
    "images.canfar.net/skaha/terminal:1.1.2",
    "images.canfar.net/skaha/terminal:1.1.1",
    "images.canfar.net/uvickbos/pycharm:0.1",
    "images.canfar.net/uvickbos/swarp:0.1",
    "images.canfar.net/uvickbos/isis:2.2",
    "images.canfar.net/uvickbos/find_moving:0.1",
]

API Reference

Bases: SkahaClient

Skaha Image Management.

Source code in skaha/images.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Images(SkahaClient):
    """Skaha Image Management."""

    @model_validator(mode="after")
    def _set_server(self) -> Self:
        """Sets the server path after validation."""
        self.server = f"{self.server}/{self.version}/image"  # type: ignore
        return self

    def fetch(self, kind: Optional[str] = None) -> List[str]:
        """Get images from Skaha Server.

        Args:
            kind (Optional[str], optional): Type of image. Defaults to None.

        Returns:
            List[str]: A list of images on the skaha server.

        Examples:
            >>> from skaha.images import Images
            >>> images = Images()
            >>> images.fetch(kind="headless")
            ['images.canfar.net/chimefrb/sample:latest',
             ...
             'images.canfar.net/skaha/terminal:1.1.1']
        """
        data: Dict[str, str] = {}
        # If kind is not None, add it to the data dictionary
        if kind:
            data["type"] = kind
        response: Response = self.session.get(url=self.server, params=data)  # type: ignore # noqa
        response.raise_for_status()
        response = response.json()
        reply: List[str] = []
        for image in response:
            reply.append(image["id"])  # type: ignore
        return reply

fetch(kind=None)

Get images from Skaha Server.

Parameters:

Name Type Description Default
kind Optional[str]

Type of image. Defaults to None.

None

Returns:

Type Description
List[str]

List[str]: A list of images on the skaha server.

Examples:

>>> from skaha.images import Images
>>> images = Images()
>>> images.fetch(kind="headless")
['images.canfar.net/chimefrb/sample:latest',
 ...
 'images.canfar.net/skaha/terminal:1.1.1']
Source code in skaha/images.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def fetch(self, kind: Optional[str] = None) -> List[str]:
    """Get images from Skaha Server.

    Args:
        kind (Optional[str], optional): Type of image. Defaults to None.

    Returns:
        List[str]: A list of images on the skaha server.

    Examples:
        >>> from skaha.images import Images
        >>> images = Images()
        >>> images.fetch(kind="headless")
        ['images.canfar.net/chimefrb/sample:latest',
         ...
         'images.canfar.net/skaha/terminal:1.1.1']
    """
    data: Dict[str, str] = {}
    # If kind is not None, add it to the data dictionary
    if kind:
        data["type"] = kind
    response: Response = self.session.get(url=self.server, params=data)  # type: ignore # noqa
    response.raise_for_status()
    response = response.json()
    reply: List[str] = []
    for image in response:
        reply.append(image["id"])  # type: ignore
    return reply