Coverage for python/lsst/daf/butler/instrument.py : 88%

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/>.
22__all__ = ["ObservationDimensionPacker"]
24from lsst.daf.butler import DataCoordinate, DimensionPacker
27class ObservationDimensionPacker(DimensionPacker):
28 """A `DimensionPacker` for visit+detector or exposure+detector, given an
29 instrument.
30 """
32 def __init__(self, fixed, dimensions):
33 super().__init__(fixed, dimensions)
34 self._instrumentName = fixed["instrument"]
35 if self.dimensions.required.names == set(["instrument", "visit", "detector"]):
36 self._observationName = "visit"
37 obsMax = fixed.records["instrument"].visit_max
38 elif dimensions.required.names == set(["instrument", "exposure", "detector"]): 38 ↛ 42line 38 didn't jump to line 42, because the condition on line 38 was never false
39 self._observationName = "exposure"
40 obsMax = fixed.records["instrument"].exposure_max
41 else:
42 raise ValueError(f"Invalid dimensions for ObservationDimensionPacker: {dimensions.required}")
43 self._detectorMax = fixed.records["instrument"].detector_max
44 self._maxBits = (obsMax*self._detectorMax).bit_length()
46 @property
47 def maxBits(self):
48 # Docstring inherited from DimensionPacker.maxBits
49 return self._maxBits
51 def _pack(self, dataId):
52 # Docstring inherited from DimensionPacker._pack
53 return dataId["detector"] + self._detectorMax*dataId[self._observationName]
55 def unpack(self, packedId):
56 # Docstring inherited from DimensionPacker.unpack
57 observation, detector = divmod(packedId, self._detectorMax)
58 return DataCoordinate.standardize(
59 {
60 "instrument": self._instrumentName,
61 "detector": detector,
62 self._observationName: observation,
63 },
64 graph=self.dimensions
65 )