LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 abstract_filter, 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  abstract_filter 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  """abstract_filter 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 abstract_filter with the given
58  name.
59  """
60  try:
61  return cls.SUPPORTED_FILTERS.index(name)
62  except ValueError:
63  raise NotImplementedError(f"abstract_filter '{name}' not supported by this ID packer.")
64 
65  @classmethod
66  def getFilterNameFromInt(cls, num):
67  """Return an abstract_filter 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 "abstract_filter" 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:885