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

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__ = ["BasicSkyPixDimensionRecordStorage"]
25from typing import Iterable, Optional
27import sqlalchemy
29from ...core import (
30 DataCoordinateIterable,
31 DimensionElement,
32 DimensionRecord,
33 NamedKeyDict,
34 SkyPixDimension,
35 SpatialRegionDatabaseRepresentation,
36 TimespanDatabaseRepresentation,
37)
38from ..queries import QueryBuilder
39from ..interfaces import SkyPixDimensionRecordStorage
42class BasicSkyPixDimensionRecordStorage(SkyPixDimensionRecordStorage):
43 """A storage implementation specialized for `SkyPixDimension` records.
45 `SkyPixDimension` records are never stored in a database, but are instead
46 generated-on-the-fly from a `sphgeom.Pixelization` instance.
48 Parameters
49 ----------
50 dimension : `SkyPixDimension`
51 The dimension for which this instance will simulate storage.
52 """
53 def __init__(self, dimension: SkyPixDimension):
54 self._dimension = dimension
56 @property
57 def element(self) -> SkyPixDimension:
58 # Docstring inherited from DimensionRecordStorage.element.
59 return self._dimension
61 def clearCaches(self) -> None:
62 # Docstring inherited from DimensionRecordStorage.clearCaches.
63 pass
65 def join(
66 self,
67 builder: QueryBuilder, *,
68 regions: Optional[NamedKeyDict[DimensionElement, SpatialRegionDatabaseRepresentation]] = None,
69 timespans: Optional[NamedKeyDict[DimensionElement, TimespanDatabaseRepresentation]] = None,
70 ) -> None:
71 if builder.hasDimensionKey(self._dimension): 71 ↛ 83line 71 didn't jump to line 83, because the condition on line 71 was never false
72 # If joining some other element or dataset type already brought in
73 # the key for this dimension, there's nothing left to do, because
74 # a SkyPix dimension never has metadata or implied dependencies,
75 # and its regions are never stored in the database. This code path
76 # is the usual case for the storage instance that manages
77 # ``DimensionUniverse.commonSkyPix`` instance, which has no table
78 # of its own but many overlap tables.
79 # Storage instances for other skypix dimensions will probably hit
80 # the error below, but we don't currently have a use case for
81 # joining them in anyway.
82 return
83 raise NotImplementedError(f"Cannot includeSkyPix dimension {self.element.name} directly in query.")
85 def insert(self, *records: DimensionRecord) -> None:
86 # Docstring inherited from DimensionRecordStorage.insert.
87 raise TypeError(f"Cannot insert into SkyPix dimension {self._dimension.name}.")
89 def sync(self, record: DimensionRecord) -> bool:
90 # Docstring inherited from DimensionRecordStorage.sync.
91 raise TypeError(f"Cannot sync SkyPixdimension {self._dimension.name}.")
93 def fetch(self, dataIds: DataCoordinateIterable) -> Iterable[DimensionRecord]:
94 # Docstring inherited from DimensionRecordStorage.fetch.
95 RecordClass = self._dimension.RecordClass
96 for dataId in dataIds:
97 index = dataId[self._dimension.name]
98 yield RecordClass(id=index, region=self._dimension.pixelization.pixel(index))
100 def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
101 # Docstring inherited from DimensionRecordStorage.digestTables.
102 return []