Hide keyboard shortcuts

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 

22 

23__all__ = ["SkyPixDimensionRecordStorage"] 

24 

25from typing import Optional 

26 

27import sqlalchemy 

28 

29from ...core import DataCoordinate, DimensionElement, DimensionRecord, SkyPixDimension, Timespan 

30from ...core.utils import NamedKeyDict 

31from ..queries import QueryBuilder 

32from ..interfaces import Database, DimensionRecordStorage, StaticTablesContext 

33 

34 

35class SkyPixDimensionRecordStorage(DimensionRecordStorage): 

36 """A storage implementation specialized for `SkyPixDimension` records. 

37 

38 `SkyPixDimension` records are never stored in a database, but are instead 

39 generated-on-the-fly from a `sphgeom.Pixelization` instance. 

40 

41 Parameters 

42 ---------- 

43 dimension : `SkyPixDimension` 

44 The dimension for which this instance will simulate storage. 

45 """ 

46 def __init__(self, dimension: SkyPixDimension): 

47 self._dimension = dimension 

48 

49 @classmethod 

50 def initialize(cls, db: Database, element: DimensionElement, *, 

51 context: Optional[StaticTablesContext] = None) -> DimensionRecordStorage: 

52 # Docstring inherited from DimensionRecordStorage. 

53 return cls(element) 

54 

55 @property 

56 def element(self) -> DimensionElement: 

57 # Docstring inherited from DimensionRecordStorage.element. 

58 return self._dimension 

59 

60 def clearCaches(self): 

61 # Docstring inherited from DimensionRecordStorage.clearCaches. 

62 pass 

63 

64 def join( 

65 self, 

66 builder: QueryBuilder, *, 

67 regions: Optional[NamedKeyDict[DimensionElement, sqlalchemy.sql.ColumnElement]] = None, 

68 timespans: Optional[NamedKeyDict[DimensionElement, Timespan[sqlalchemy.sql.ColumnElement]]] = None, 

69 ): 

70 if builder.hasDimensionKey(self.element): 70 ↛ 82line 70 didn't jump to line 82, because the condition on line 70 was never false

71 # If joining some other element or dataset type already brought in 

72 # the key for this dimension, there's nothing left to do, because 

73 # a SkyPix dimension never has metadata or implied dependencies, 

74 # and its regions are never stored in the database. This code path 

75 # is the usual case for the storage instance that manages 

76 # ``DimensionUniverse.commonSkyPix`` instance, which has no table 

77 # of its own but many overlap tables. 

78 # Storage instances for other skypix dimensions will probably hit 

79 # the error below, but we don't currently have a use case for 

80 # joining them in anyway. 

81 return 

82 raise NotImplementedError(f"Cannot includeSkyPix dimension {self.element.name} directly in query.") 

83 

84 def insert(self, *records: DimensionRecord): 

85 # Docstring inherited from DimensionRecordStorage.insert. 

86 raise TypeError(f"Cannot insert into SkyPix dimension {self._dimension.name}.") 

87 

88 def sync(self, record: DimensionRecord): 

89 # Docstring inherited from DimensionRecordStorage.sync. 

90 raise TypeError(f"Cannot sync SkyPixdimension {self._dimension.name}.") 

91 

92 def fetch(self, dataId: DataCoordinate) -> Optional[DimensionRecord]: 

93 # Docstring inherited from DimensionRecordStorage.fetch. 

94 return self._dimension.RecordClass(dataId[self._dimension.name], 

95 self._dimension.pixelization.pixel(dataId[self._dimension.name]))