Coverage for python / lsst / images / _transforms / _frame_set.py: 75%
16 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-17 09:16 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-17 09:16 +0000
1# This file is part of lsst-images.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12from __future__ import annotations
14__all__ = ("FrameLookupError", "FrameSet")
16from abc import ABC, abstractmethod
18from . import _frames # use this import style to facilitate pattern matching
19from ._transform import Transform
22class FrameLookupError(LookupError):
23 """Exception raised when a frame cannot be found in a `FrameSet`."""
26class FrameSet(ABC):
27 """A container or factory for `Transform` objects that relates frames.
29 Notes
30 -----
31 `FrameSet` supposes ``in`` (``__contains__``) tests on individual `Frame`
32 objects to test whether they are known to the frame set, and indexing
33 (``__getitem__``) of **pairs** of frames to return a `Transform` that maps
34 the first to the second.
35 """
37 @abstractmethod
38 def __contains__(self, frame: _frames.Frame) -> bool:
39 raise NotImplementedError()
41 @abstractmethod
42 def __getitem__[I: _frames.Frame, O: _frames.Frame](self, key: tuple[I, O]) -> Transform[I, O]:
43 raise NotImplementedError()
45 def get[I: _frames.Frame, O: _frames.Frame](self, in_frame: I, out_frame: O) -> Transform[I, O] | None:
46 """Return the `Transform` that maps the two frames, or `None` if at
47 least one is not known to the `FrameSet`.
48 """
49 try:
50 return self[in_frame, out_frame]
51 except FrameLookupError:
52 return None