Coverage for python/lsst/daf/butler/registry/dimensions/skypix.py: 79%

30 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-06 12:40 -0800

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__ = ["BasicSkyPixDimensionRecordStorage"] 

24 

25from typing import Iterable, Optional 

26 

27import sqlalchemy 

28 

29from ...core import ( 

30 DataCoordinateIterable, 

31 DimensionElement, 

32 DimensionRecord, 

33 NamedKeyDict, 

34 SkyPixDimension, 

35 SpatialRegionDatabaseRepresentation, 

36 TimespanDatabaseRepresentation, 

37) 

38from ..interfaces import SkyPixDimensionRecordStorage 

39from ..queries import QueryBuilder 

40 

41 

42class BasicSkyPixDimensionRecordStorage(SkyPixDimensionRecordStorage): 

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

44 

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

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

47 

48 Parameters 

49 ---------- 

50 dimension : `SkyPixDimension` 

51 The dimension for which this instance will simulate storage. 

52 """ 

53 

54 def __init__(self, dimension: SkyPixDimension): 

55 self._dimension = dimension 

56 

57 @property 

58 def element(self) -> SkyPixDimension: 

59 # Docstring inherited from DimensionRecordStorage.element. 

60 return self._dimension 

61 

62 def clearCaches(self) -> None: 

63 # Docstring inherited from DimensionRecordStorage.clearCaches. 

64 pass 

65 

66 def join( 

67 self, 

68 builder: QueryBuilder, 

69 *, 

70 regions: Optional[NamedKeyDict[DimensionElement, SpatialRegionDatabaseRepresentation]] = None, 

71 timespans: Optional[NamedKeyDict[DimensionElement, TimespanDatabaseRepresentation]] = None, 

72 ) -> None: 

73 if builder.hasDimensionKey(self._dimension): 73 ↛ 85line 73 didn't jump to line 85, because the condition on line 73 was never false

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

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

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

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

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

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

80 # of its own but many overlap tables. 

81 # Storage instances for other skypix dimensions will probably hit 

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

83 # joining them in anyway. 

84 return 

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

86 

87 def insert(self, *records: DimensionRecord, replace: bool = False, skip_existing: bool = False) -> None: 

88 # Docstring inherited from DimensionRecordStorage.insert. 

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

90 

91 def sync(self, record: DimensionRecord, update: bool = False) -> bool: 

92 # Docstring inherited from DimensionRecordStorage.sync. 

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

94 

95 def fetch(self, dataIds: DataCoordinateIterable) -> Iterable[DimensionRecord]: 

96 # Docstring inherited from DimensionRecordStorage.fetch. 

97 RecordClass = self._dimension.RecordClass 

98 for dataId in dataIds: 

99 index = dataId[self._dimension.name] 

100 yield RecordClass(id=index, region=self._dimension.pixelization.pixel(index)) 

101 

102 def digestTables(self) -> Iterable[sqlalchemy.schema.Table]: 

103 # Docstring inherited from DimensionRecordStorage.digestTables. 

104 return []