LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
packers.py
Go to the documentation of this file.
1# This file is part of skymap.
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/>.
21
22__all__ = ("SkyMapDimensionPacker",)
23
24from lsst.daf.butler import DimensionPacker, DimensionGraph, DataCoordinate
25
26
27class SkyMapDimensionPacker(DimensionPacker):
28 """A `DimensionPacker` for tract, patch and optionally band,
29 given a SkyMap.
30
31 Parameters
32 ----------
33 fixed : `lsst.daf.butler.DataCoordinate`
34 Expanded data ID that must include at least the skymap dimension.
35 dimensions : `lsst.daf.butler.DimensionGraph`
36 The dimensions of data IDs packed by this instance. Must include
37 skymap, tract, and patch, and may include band.
38 """
39
40 SUPPORTED_FILTERS = (
41 [None]
42 + list("ugrizyUBGVRIZYJHK") # split string into single chars
43 + [f"N{d}" for d in (387, 515, 656, 816, 921, 1010)] # HSC narrow-bands
44 + [f"N{d}" for d in (419, 540, 708, 964)] # DECam narrow-bands
45 )
46 """band names supported by this packer.
47
48 New filters should be added to the end of the list to maximize
49 compatibility with existing IDs.
50 """
51
52 @classmethod
53 def getIntFromFilter(cls, name):
54 """Return an integer that represents the band with the given
55 name.
56 """
57 try:
58 return cls.SUPPORTED_FILTERS.index(name)
59 except ValueError:
60 raise NotImplementedError(f"band '{name}' not supported by this ID packer.")
61
62 @classmethod
63 def getFilterNameFromInt(cls, num):
64 """Return an band name from its integer representation.
65 """
66 return cls.SUPPORTED_FILTERS[num]
67
68 @classmethod
70 return len(cls.SUPPORTED_FILTERS)
71
72 @classmethod
73 def configure(cls, dimensions):
74 # Docstring inherited from DataIdPacker.configure
75 assert dimensions.given == ["skymap"]
76 assert dimensions.required.issuperset(["tract", "patch"])
77 metadata = {"skymap": ["tract_max", "patch_nx_max", "patch_ny_max"]}
78 kwds = {}
79 return metadata, kwds
80
81 def __init__(self, fixed: DataCoordinate, dimensions: DimensionGraph):
82 super().__init__(fixed, dimensions)
83 record = fixed.records["skymap"]
84 self._skyMapName = record.name
85 self._patchMax = record.patch_nx_max * record.patch_ny_max
86 self._tractPatchMax = self._patchMax*record.tract_max
87 if "band" in dimensions:
89 else:
90 self._filterMax = None
91
92 @property
93 def maxBits(self) -> int:
94 # Docstring inherited from DataIdPacker.maxBits
95 packedMax = self._tractPatchMax
96 if self._filterMax is not None:
97 packedMax *= self._filterMax
98 return packedMax.bit_length()
99
100 def _pack(self, dataId: DataCoordinate) -> int:
101 # Docstring inherited from DataIdPacker.pack
102 packed = dataId["patch"] + self._patchMax*dataId["tract"]
103 if self._filterMax is not None:
104 packed += self.getIntFromFilter(dataId["band"])*self._tractPatchMax
105 return packed
106
107 def unpack(self, packedId: int) -> DataCoordinate:
108 # Docstring inherited from DataIdPacker.unpack
109 d = {"skymap": self._skyMapName}
110 if self._filterMax is not None:
111 d["band"] = self.getFilterNameFromInt(packedId // self._tractPatchMax)
112 packedId %= self._tractPatchMax
113 d["tract"] = packedId // self._patchMax
114 d["patch"] = packedId % self._patchMax
115 return DataCoordinate.standardize(d, graph=self.dimensions)
def __init__(self, DataCoordinate fixed, DimensionGraph dimensions)
Definition: packers.py:81
DataCoordinate unpack(self, int packedId)
Definition: packers.py:107
daf::base::PropertyList * list
Definition: fits.cc:928