Coverage for python/lsst/daf/butler/registry/dimensions/skypix.py : 86%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21from __future__ import annotations
23__all__ = ["SkyPixDimensionRecordStorage"]
25from typing import Iterable, Optional
27import sqlalchemy
29from ...core import (
30 DatabaseTimespanRepresentation,
31 DataCoordinateIterable,
32 DimensionElement,
33 DimensionRecord,
34 NamedKeyDict,
35 SkyPixDimension,
36)
37from ..queries import QueryBuilder
38from ..interfaces import Database, DimensionRecordStorage, StaticTablesContext
41class SkyPixDimensionRecordStorage(DimensionRecordStorage):
42 """A storage implementation specialized for `SkyPixDimension` records.
44 `SkyPixDimension` records are never stored in a database, but are instead
45 generated-on-the-fly from a `sphgeom.Pixelization` instance.
47 Parameters
48 ----------
49 dimension : `SkyPixDimension`
50 The dimension for which this instance will simulate storage.
51 """
52 def __init__(self, dimension: SkyPixDimension):
53 self._dimension = dimension
55 @classmethod
56 def initialize(cls, db: Database, element: DimensionElement, *,
57 context: Optional[StaticTablesContext] = None) -> DimensionRecordStorage:
58 # Docstring inherited from DimensionRecordStorage.
59 assert isinstance(element, SkyPixDimension)
60 return cls(element)
62 @property
63 def element(self) -> DimensionElement:
64 # Docstring inherited from DimensionRecordStorage.element.
65 return self._dimension
67 def clearCaches(self) -> None:
68 # Docstring inherited from DimensionRecordStorage.clearCaches.
69 pass
71 def join(
72 self,
73 builder: QueryBuilder, *,
74 regions: Optional[NamedKeyDict[DimensionElement, sqlalchemy.sql.ColumnElement]] = None,
75 timespans: Optional[NamedKeyDict[DimensionElement, DatabaseTimespanRepresentation]] = None,
76 ) -> None:
77 if builder.hasDimensionKey(self._dimension): 77 ↛ 89line 77 didn't jump to line 89, because the condition on line 77 was never false
78 # If joining some other element or dataset type already brought in
79 # the key for this dimension, there's nothing left to do, because
80 # a SkyPix dimension never has metadata or implied dependencies,
81 # and its regions are never stored in the database. This code path
82 # is the usual case for the storage instance that manages
83 # ``DimensionUniverse.commonSkyPix`` instance, which has no table
84 # of its own but many overlap tables.
85 # Storage instances for other skypix dimensions will probably hit
86 # the error below, but we don't currently have a use case for
87 # joining them in anyway.
88 return
89 raise NotImplementedError(f"Cannot includeSkyPix dimension {self.element.name} directly in query.")
91 def insert(self, *records: DimensionRecord) -> None:
92 # Docstring inherited from DimensionRecordStorage.insert.
93 raise TypeError(f"Cannot insert into SkyPix dimension {self._dimension.name}.")
95 def sync(self, record: DimensionRecord) -> bool:
96 # Docstring inherited from DimensionRecordStorage.sync.
97 raise TypeError(f"Cannot sync SkyPixdimension {self._dimension.name}.")
99 def fetch(self, dataIds: DataCoordinateIterable) -> Iterable[DimensionRecord]:
100 # Docstring inherited from DimensionRecordStorage.fetch.
101 RecordClass = self._dimension.RecordClass
102 for dataId in dataIds:
103 index = dataId[self._dimension.name]
104 yield RecordClass(id=index, region=self._dimension.pixelization.pixel(index))
106 def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
107 # Docstring inherited from DimensionRecordStorage.digestTables.
108 return []