Coverage for python/lsst/daf/butler/registry/dimensions/skypix.py: 86%
34 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-10-02 07:59 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-10-02 07:59 +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 ...core import (
37 DataCoordinate,
38 DimensionKeyColumnTag,
39 DimensionRecord,
40 DimensionRecordColumnTag,
41 SkyPixDimension,
42)
43from ..interfaces import SkyPixDimensionRecordStorage
45if TYPE_CHECKING:
46 from .. import queries
49class BasicSkyPixDimensionRecordStorage(SkyPixDimensionRecordStorage):
50 """A storage implementation specialized for `SkyPixDimension` records.
52 `SkyPixDimension` records are never stored in a database, but are instead
53 generated-on-the-fly from a `sphgeom.Pixelization` instance.
55 Parameters
56 ----------
57 dimension : `SkyPixDimension`
58 The dimension for which this instance will simulate storage.
59 """
61 def __init__(self, dimension: SkyPixDimension):
62 self._dimension = dimension
64 @property
65 def element(self) -> SkyPixDimension:
66 # Docstring inherited from DimensionRecordStorage.element.
67 return self._dimension
69 def clearCaches(self) -> None:
70 # Docstring inherited from DimensionRecordStorage.clearCaches.
71 pass
73 def join_results_postprocessed(self) -> bool:
74 # Docstring inherited.
75 return True
77 def join(
78 self,
79 relation: Relation,
80 join: Join,
81 context: queries.SqlQueryContext,
82 ) -> Relation:
83 # Docstring inherited.
84 assert join.predicate.as_trivial(), "Expected trivial join predicate for skypix relation."
85 id_column = DimensionKeyColumnTag(self._dimension.name)
86 assert id_column in relation.columns, "Guaranteed by QueryBuilder.make_dimension_relation."
87 function_name = f"{self._dimension.name}_region"
88 context.iteration_engine.functions[function_name] = self._dimension.pixelization.pixel
89 calculation = Calculation(
90 tag=DimensionRecordColumnTag(self._dimension.name, "region"),
91 expression=ColumnExpression.function(function_name, ColumnExpression.reference(id_column)),
92 )
93 return calculation.apply(
94 relation, preferred_engine=context.iteration_engine, transfer=True, backtrack=True
95 )
97 def insert(self, *records: DimensionRecord, replace: bool = False, skip_existing: bool = False) -> None:
98 # Docstring inherited from DimensionRecordStorage.insert.
99 raise TypeError(f"Cannot insert into SkyPix dimension {self._dimension.name}.")
101 def sync(self, record: DimensionRecord, update: bool = False) -> bool:
102 # Docstring inherited from DimensionRecordStorage.sync.
103 raise TypeError(f"Cannot sync SkyPixdimension {self._dimension.name}.")
105 def fetch_one(self, data_id: DataCoordinate, context: queries.SqlQueryContext) -> DimensionRecord:
106 # Docstring inherited from DimensionRecordStorage.
107 index = data_id[self._dimension.name]
108 return self._dimension.RecordClass(id=index, region=self._dimension.pixelization.pixel(index))
110 def digestTables(self) -> list[sqlalchemy.schema.Table]:
111 # Docstring inherited from DimensionRecordStorage.digestTables.
112 return []