Coverage for python/lsst/daf/butler/registry/dimensions/skypix.py: 65%
34 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-14 09:21 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-14 09:21 +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 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 TYPE_CHECKING
27import sqlalchemy
28from lsst.daf.relation import Calculation, ColumnExpression, Join, Relation
30from ...core import (
31 DataCoordinate,
32 DimensionKeyColumnTag,
33 DimensionRecord,
34 DimensionRecordColumnTag,
35 SkyPixDimension,
36)
37from ..interfaces import SkyPixDimensionRecordStorage
39if TYPE_CHECKING:
40 from .. import queries
43class BasicSkyPixDimensionRecordStorage(SkyPixDimensionRecordStorage):
44 """A storage implementation specialized for `SkyPixDimension` records.
46 `SkyPixDimension` records are never stored in a database, but are instead
47 generated-on-the-fly from a `sphgeom.Pixelization` instance.
49 Parameters
50 ----------
51 dimension : `SkyPixDimension`
52 The dimension for which this instance will simulate storage.
53 """
55 def __init__(self, dimension: SkyPixDimension):
56 self._dimension = dimension
58 @property
59 def element(self) -> SkyPixDimension:
60 # Docstring inherited from DimensionRecordStorage.element.
61 return self._dimension
63 def clearCaches(self) -> None:
64 # Docstring inherited from DimensionRecordStorage.clearCaches.
65 pass
67 def join_results_postprocessed(self) -> bool:
68 # Docstring inherited.
69 return True
71 def join(
72 self,
73 relation: Relation,
74 join: Join,
75 context: queries.SqlQueryContext,
76 ) -> Relation:
77 # Docstring inherited.
78 assert join.predicate.as_trivial(), "Expected trivial join predicate for skypix relation."
79 id_column = DimensionKeyColumnTag(self._dimension.name)
80 assert id_column in relation.columns, "Guaranteed by QueryBuilder.make_dimension_relation."
81 function_name = f"{self._dimension.name}_region"
82 context.iteration_engine.functions[function_name] = self._dimension.pixelization.pixel
83 calculation = Calculation(
84 tag=DimensionRecordColumnTag(self._dimension.name, "region"),
85 expression=ColumnExpression.function(function_name, ColumnExpression.reference(id_column)),
86 )
87 return calculation.apply(
88 relation, preferred_engine=context.iteration_engine, transfer=True, backtrack=True
89 )
91 def insert(self, *records: DimensionRecord, replace: bool = False, skip_existing: bool = False) -> 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, update: bool = False) -> bool:
96 # Docstring inherited from DimensionRecordStorage.sync.
97 raise TypeError(f"Cannot sync SkyPixdimension {self._dimension.name}.")
99 def fetch_one(self, data_id: DataCoordinate, context: queries.SqlQueryContext) -> DimensionRecord:
100 # Docstring inherited from DimensionRecordStorage.
101 index = data_id[self._dimension.name]
102 return self._dimension.RecordClass(id=index, region=self._dimension.pixelization.pixel(index))
104 def digestTables(self) -> list[sqlalchemy.schema.Table]:
105 # Docstring inherited from DimensionRecordStorage.digestTables.
106 return []