LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
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__ = ("SkyMapDataIdPacker",)
23 
24 from lsst.daf.butler import DataIdPacker, DataId
25 
26 
27 class SkyMapDataIdPacker(DataIdPacker):
28  """A `DataIdPacker` for Tract, Patch and optionally AbstractFilter, given
29  a SkyMap.
30 
31  Parameters
32  ----------
33  dimensions : `DataIdPackerDimensions`
34  Struct containing dimensions related to this `DataIdPacker`. Must
35  have SkyMap as the only given dimension, Tract, Patch, and possibly
36  AbstractFilter as the covered dimensions, and all of these as required
37  dimensions.
38  skymap : `str`
39  SkyMap name from `Registry`.
40  tractMax : `int`
41  Maximum (exclusive) tract index for this skymap.
42  patchNxMax : `int`
43  Maximum (exclusive) patch index in the x direction.
44  patchNyMax : `int`
45  Maximum (exclusive) patch index in the y direction.
46  """
47 
48  SUPPORTED_FILTERS = [None] + list("ugrizyUBGVRIZYJHK") # split string into single chars
49  """AbstractFilter names supported by this packer.
50 
51  New filters should be added to the end of the list to maximize
52  compatibility with existing IDs.
53  """
54 
55  @classmethod
56  def getIntFromFilter(cls, name):
57  """Return an integer that represents the AbstractFilter with the given
58  name.
59  """
60  try:
61  return cls.SUPPORTED_FILTERS.index(name)
62  except ValueError:
63  raise NotImplementedError(f"AbstractFilter '{name}'' not supported by this ID packer.")
64 
65  @classmethod
66  def getFilterNameFromInt(cls, num):
67  """Return an AbstractFilter name from its integer representation.
68  """
69  return cls.SUPPORTED_FILTERS[num]
70 
71  @classmethod
73  return len(cls.SUPPORTED_FILTERS)
74 
75  @classmethod
76  def configure(cls, dimensions):
77  # Docstring inherited from DataIdPacker.configure
78  assert dimensions.given == ["SkyMap"]
79  assert dimensions.required.issuperset(["Tract", "Patch"])
80  metadata = {"SkyMap": ["tract_max", "patch_nx_max", "patch_ny_max"]}
81  kwds = {}
82  return metadata, kwds
83 
84  def __init__(self, dimensions, skymap, tractMax, patchNxMax, patchNyMax):
85  self._skyMapName = skymap
86  self._patchMax = patchNxMax*patchNyMax
87  self._tractPatchMax = self._patchMax*tractMax
88  if "AbstractFilter" in dimensions.required:
89  self._filterMax = self.getMaxIntForFilters()
90  else:
91  self._filterMax = None
92 
93  @property
94  def maxBits(self):
95  # Docstring inherited from DataIdPacker.maxBits
96  packedMax = self._tractPatchMax
97  if self._filterMax is not None:
98  packedMax *= self._filterMax
99  return packedMax.bit_length()
100 
101  def _pack(self, dataId):
102  # Docstring inherited from DataIdPacker.pack
103  packed = dataId["patch"] + self._patchMax*dataId["tract"]
104  if self._filterMax is not None:
105  packed += self.getIntFromFilter(dataId["abstract_filter"])*self._tractPatchMax
106  return packed
107 
108  def unpack(self, packedId):
109  # Docstring inherited from DataIdPacker.unpack
110  d = {"skymap": self._skyMapName}
111  if self._filterMax is not None:
112  d["abstract_filter"] = self.getFilterNameFromInt(packedId // self._tractPatchMax)
113  packedId %= self._tractPatchMax
114  d["tract"] = packedId // self._patchMax
115  d["patch"] = packedId % self._patchMax
116  return DataId(d, dimensions=self.dimensions.required)
def __init__(self, dimensions, skymap, tractMax, patchNxMax, patchNyMax)
Definition: packers.py:84
def configure(cls, dimensions)
Definition: packers.py:76
daf::base::PropertyList * list
Definition: fits.cc:833