Coverage for python/lsst/daf/butler/registry/dimensions/skypix.py: 86%
35 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-05 11:05 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-05 11:05 +0000
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 software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
27from __future__ import annotations
29__all__ = ["BasicSkyPixDimensionRecordStorage"]
31from typing import TYPE_CHECKING
33import sqlalchemy
34from lsst.daf.relation import Calculation, ColumnExpression, Join, Relation
36from ..._column_tags import DimensionKeyColumnTag, DimensionRecordColumnTag
37from ...dimensions import DataCoordinate, DimensionRecord, SkyPixDimension
38from ..interfaces import SkyPixDimensionRecordStorage
40if TYPE_CHECKING:
41 from .. import queries
44class BasicSkyPixDimensionRecordStorage(SkyPixDimensionRecordStorage):
45 """A storage implementation specialized for `SkyPixDimension` records.
47 `SkyPixDimension` records are never stored in a database, but are instead
48 generated-on-the-fly from a `sphgeom.Pixelization` instance.
50 Parameters
51 ----------
52 dimension : `SkyPixDimension`
53 The dimension for which this instance will simulate storage.
54 """
56 def __init__(self, dimension: SkyPixDimension):
57 self._dimension = dimension
59 @property
60 def element(self) -> SkyPixDimension:
61 # Docstring inherited from DimensionRecordStorage.element.
62 return self._dimension
64 def clearCaches(self) -> None:
65 # Docstring inherited from DimensionRecordStorage.clearCaches.
66 pass
68 def join_results_postprocessed(self) -> bool:
69 # Docstring inherited.
70 return True
72 def join(
73 self,
74 relation: Relation,
75 join: Join,
76 context: queries.SqlQueryContext,
77 ) -> Relation:
78 # Docstring inherited.
79 assert join.predicate.as_trivial(), "Expected trivial join predicate for skypix relation."
80 id_column = DimensionKeyColumnTag(self._dimension.name)
81 assert id_column in relation.columns, "Guaranteed by QueryBuilder.make_dimension_relation."
82 function_name = f"{self._dimension.name}_region"
83 context.iteration_engine.functions[function_name] = self._dimension.pixelization.pixel
84 calculation = Calculation(
85 tag=DimensionRecordColumnTag(self._dimension.name, "region"),
86 expression=ColumnExpression.function(function_name, ColumnExpression.reference(id_column)),
87 )
88 return calculation.apply(
89 relation, preferred_engine=context.iteration_engine, transfer=True, backtrack=True
90 )
92 def insert(self, *records: DimensionRecord, replace: bool = False, skip_existing: bool = False) -> None:
93 # Docstring inherited from DimensionRecordStorage.insert.
94 raise TypeError(f"Cannot insert into SkyPix dimension {self._dimension.name}.")
96 def sync(self, record: DimensionRecord, update: bool = False) -> bool:
97 # Docstring inherited from DimensionRecordStorage.sync.
98 raise TypeError(f"Cannot sync SkyPixdimension {self._dimension.name}.")
100 def fetch_one(self, data_id: DataCoordinate, context: queries.SqlQueryContext) -> DimensionRecord:
101 # Docstring inherited from DimensionRecordStorage.
102 index = data_id[self._dimension.name]
103 return self._dimension.RecordClass(id=index, region=self._dimension.pixelization.pixel(index))
105 def digestTables(self) -> list[sqlalchemy.schema.Table]:
106 # Docstring inherited from DimensionRecordStorage.digestTables.
107 return []