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 Optional
27import sqlalchemy
29from ...core import (
30 DataCoordinate,
31 DimensionElement,
32 DimensionRecord,
33 NamedKeyDict,
34 SkyPixDimension,
35 Timespan,
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 return cls(element)
61 @property
62 def element(self) -> DimensionElement:
63 # Docstring inherited from DimensionRecordStorage.element.
64 return self._dimension
66 def clearCaches(self):
67 # Docstring inherited from DimensionRecordStorage.clearCaches.
68 pass
70 def join(
71 self,
72 builder: QueryBuilder, *,
73 regions: Optional[NamedKeyDict[DimensionElement, sqlalchemy.sql.ColumnElement]] = None,
74 timespans: Optional[NamedKeyDict[DimensionElement, Timespan[sqlalchemy.sql.ColumnElement]]] = None,
75 ):
76 if builder.hasDimensionKey(self.element): 76 ↛ 88line 76 didn't jump to line 88, because the condition on line 76 was never false
77 # If joining some other element or dataset type already brought in
78 # the key for this dimension, there's nothing left to do, because
79 # a SkyPix dimension never has metadata or implied dependencies,
80 # and its regions are never stored in the database. This code path
81 # is the usual case for the storage instance that manages
82 # ``DimensionUniverse.commonSkyPix`` instance, which has no table
83 # of its own but many overlap tables.
84 # Storage instances for other skypix dimensions will probably hit
85 # the error below, but we don't currently have a use case for
86 # joining them in anyway.
87 return
88 raise NotImplementedError(f"Cannot includeSkyPix dimension {self.element.name} directly in query.")
90 def insert(self, *records: DimensionRecord):
91 # Docstring inherited from DimensionRecordStorage.insert.
92 raise TypeError(f"Cannot insert into SkyPix dimension {self._dimension.name}.")
94 def sync(self, record: DimensionRecord):
95 # Docstring inherited from DimensionRecordStorage.sync.
96 raise TypeError(f"Cannot sync SkyPixdimension {self._dimension.name}.")
98 def fetch(self, dataId: DataCoordinate) -> Optional[DimensionRecord]:
99 # Docstring inherited from DimensionRecordStorage.fetch.
100 return self._dimension.RecordClass(dataId[self._dimension.name],
101 self._dimension.pixelization.pixel(dataId[self._dimension.name]))