LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
lsst.skymap.packers.SkyMapDimensionPacker Class Reference
Inheritance diagram for lsst.skymap.packers.SkyMapDimensionPacker:

Public Member Functions

 __init__ (self, DataCoordinate fixed, DimensionGroup|DimensionGraph|None dimensions=None, Mapping[str, int]|None bands=None, int|None n_bands=None, int|None n_tracts=None, int|None n_patches=None)
 
ConfigurableField make_config_field (cls, str doc="How to pack tract, patch, and possibly band into an integer.")
 
SkyMapDimensionPacker from_config (cls, DataCoordinate data_id, SkyMapDimensionPackerConfig config)
 
int maxBits (self)
 
DataCoordinate unpack (self, int packedId)
 

Static Public Attributes

tuple SUPPORTED_FILTERS
 
 ConfigClass = SkyMapDimensionPackerConfig
 

Protected Member Functions

int _pack (self, DataCoordinate dataId)
 

Protected Attributes

 _bands
 
 _n_bands
 
 _n_tracts
 
 _n_patches
 
 _bands_list
 

Detailed Description

A `DimensionPacker` for tract, patch and optionally band,
given a SkyMap.

Parameters
----------
fixed : `lsst.daf.butler.DataCoordinate`
    Data ID that identifies just the ``skymap`` dimension.  Must have
    dimension records attached unless ``n_tracts`` and ``n_patches`` are
    not `None`.
dimensions : `lsst.daf.butler.DimensionGraph`, or \
        `lsst.daf.butler.DimensionGroup`, optional
    The dimensions of data IDs packed by this instance.  Must include
    ``{skymap, tract, patch}``, and may include ``band``.  If not provided,
    this will be set to include ``band`` if ``n_bands != 0``.
bands : `~collections.abc.Mapping` [ `str`, `int` ] or `None`, optional
    Mapping from band name to integer to use in the packed ID.  `None` uses
    a fixed set of bands defined in this class.  When calling code can
    enumerate the bands it is likely to see, providing an explicit mapping
    is preferable.
n_bands : `int` or `None`, optional
    The number of bands to leave room for in the packed ID.  If `None`,
    this will be set to ``len(bands)``.  If ``0``, the band will not be
    included in the dimensions at all.  If ``1``, the band will be included
    in the dimensions but will not occupy any extra bits in the packed ID.
    This may be larger or smaller than ``len(bands)``, to reserve extra
    space for the future or align to byte boundaries, or support a subset
    of a larger mapping, respectively.
n_tracts : `int` or `None`, optional
    The number of tracts to leave room for in the packed ID.  If `None`,
    this will be set via the ``skymap`` dimension record in ``fixed``.
n_patches : `int` or `None`, optional
    The number of patches (per tract) to leave room for in the packed ID.
    If `None`, this will be set via the ``skymap`` dimension record in
    ``fixed``.

Notes
-----
The standard pattern for constructing instances of this class is to use
`make_config_field`::

    class SomeConfig(lsst.pex.config.Config):
        packer = ObservationDimensionPacker.make_config_field()

    class SomeTask(lsst.pipe.base.Task):
        ConfigClass = SomeConfig

        def run(self, ..., data_id: DataCoordinate):
            packer = self.config.packer.apply(data_id)
            packed_id = packer.pack(data_id)
            ...

Definition at line 67 of file packers.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.skymap.packers.SkyMapDimensionPacker.__init__ ( self,
DataCoordinate fixed,
DimensionGroup | DimensionGraph | None dimensions = None,
Mapping[str, int] | None bands = None,
int | None n_bands = None,
int | None n_tracts = None,
int | None n_patches = None )

Definition at line 137 of file packers.py.

145 ):
146 if bands is None:
147 bands = {b: i for i, b in enumerate(self.SUPPORTED_FILTERS)}
148 if dimensions is None:
149 if n_bands is None:
150 n_bands = len(bands)
151 dimension_names = ["tract", "patch"]
152 if n_bands != 0:
153 dimension_names.append("band")
154 dimensions = fixed.universe.conform(dimension_names)
155 else:
156 if "band" not in dimensions.names:
157 n_bands = 0
158 if dimensions.names != {"tract", "patch", "skymap"}:
159 raise ValueError(
160 f"Invalid dimensions for skymap dimension packer with n_bands=0: {dimensions}."
161 )
162 else:
163 if dimensions.names != {"tract", "patch", "skymap", "band"}:
164 raise ValueError(
165 f"Invalid dimensions for skymap dimension packer with n_bands>0: {dimensions}."
166 )
167 if n_bands is None:
168 n_bands = len(bands)
169 if n_tracts is None:
170 n_tracts = fixed.records["skymap"].tract_max
171 if n_patches is None:
172 n_patches = (
173 fixed.records["skymap"].patch_nx_max
174 * fixed.records["skymap"].patch_ny_max
175 )
176 super().__init__(fixed, dimensions)
177 self._bands = bands
178 self._n_bands = n_bands
179 self._n_tracts = n_tracts
180 self._n_patches = n_patches
181 self._bands_list = None
182

Member Function Documentation

◆ _pack()

int lsst.skymap.packers.SkyMapDimensionPacker._pack ( self,
DataCoordinate dataId )
protected

Definition at line 247 of file packers.py.

247 def _pack(self, dataId: DataCoordinate) -> int:
248 # Docstring inherited from DataIdPacker.pack
249 if dataId["patch"] >= self._n_patches:
250 raise ValueError(f"Patch ID {dataId['patch']} is out of bounds; expected <{self._n_patches}.")
251 if dataId["tract"] >= self._n_tracts:
252 raise ValueError(f"Tract ID {dataId['tract']} is out of bounds; expected <{self._n_tracts}.")
253 packed = dataId["patch"] + self._n_patches * dataId["tract"]
254 if self._n_bands:
255 if (band_index := self._bands.get(dataId["band"])) is None:
256 raise ValueError(
257 f"Band {dataId['band']!r} is not supported by SkyMapDimensionPacker "
258 f"configuration; expected one of {list(self._bands)}."
259 )
260 if band_index >= self._n_bands:
261 raise ValueError(
262 f"Band index {band_index} for {dataId['band']!r} is out of bounds; "
263 f"expected <{self._n_bands}."
264 )
265 packed += self._bands[dataId["band"]] * self._n_patches * self._n_tracts
266 return packed
267

◆ from_config()

SkyMapDimensionPacker lsst.skymap.packers.SkyMapDimensionPacker.from_config ( cls,
DataCoordinate data_id,
SkyMapDimensionPackerConfig config )
Construct a dimension packer from a config object and a data ID.

Parameters
----------
data_id : `lsst.daf.butler.DataCoordinate`
    Data ID that identifies at least the ``skymap`` dimension.  Must
    have dimension records attached unless ``config.n_tracts`` and
    ``config.n_patches`` are both not `None`.
config : `SkyMapDimensionPackerConfig`
    Configuration object.

Returns
-------
packer : `SkyMapDimensionPackerConfig`
    New dimension packer.

Notes
-----
This interface is provided for consistency with the `lsst.pex.config`
"Configurable" concept, and is invoked when ``apply(data_id)`` is
called on a config instance attribute that corresponds to a field
created by `make_config_field`.  The constructor signature cannot play
this role easily for backwards compatibility reasons.

Definition at line 204 of file packers.py.

206 ) -> SkyMapDimensionPacker:
207 """Construct a dimension packer from a config object and a data ID.
208
209 Parameters
210 ----------
211 data_id : `lsst.daf.butler.DataCoordinate`
212 Data ID that identifies at least the ``skymap`` dimension. Must
213 have dimension records attached unless ``config.n_tracts`` and
214 ``config.n_patches`` are both not `None`.
215 config : `SkyMapDimensionPackerConfig`
216 Configuration object.
217
218 Returns
219 -------
220 packer : `SkyMapDimensionPackerConfig`
221 New dimension packer.
222
223 Notes
224 -----
225 This interface is provided for consistency with the `lsst.pex.config`
226 "Configurable" concept, and is invoked when ``apply(data_id)`` is
227 called on a config instance attribute that corresponds to a field
228 created by `make_config_field`. The constructor signature cannot play
229 this role easily for backwards compatibility reasons.
230 """
231 return cls(
232 data_id.subset(data_id.universe.conform(["skymap"])),
233 n_bands=config.n_bands,
234 bands=config.bands,
235 n_tracts=config.n_tracts,
236 n_patches=config.n_patches,
237 )
238

◆ make_config_field()

ConfigurableField lsst.skymap.packers.SkyMapDimensionPacker.make_config_field ( cls,
str doc = "How to pack tract, patch, and possibly band into an integer." )
Make a config field to control how skymap data IDs are packed.

Parameters
----------
doc : `str`, optional
    Documentation for the config field.

Returns
-------
field : `lsst.pex.config.ConfigurableField`
    A config field whose instance values are [wrapper proxies to]
    `SkyMapDimensionPackerConfig` instances.

Definition at line 184 of file packers.py.

187 ) -> ConfigurableField:
188 """Make a config field to control how skymap data IDs are packed.
189
190 Parameters
191 ----------
192 doc : `str`, optional
193 Documentation for the config field.
194
195 Returns
196 -------
197 field : `lsst.pex.config.ConfigurableField`
198 A config field whose instance values are [wrapper proxies to]
199 `SkyMapDimensionPackerConfig` instances.
200 """
201 return ConfigurableField(doc, target=cls.from_config, ConfigClass=cls.ConfigClass)
202

◆ maxBits()

int lsst.skymap.packers.SkyMapDimensionPacker.maxBits ( self)

Definition at line 240 of file packers.py.

240 def maxBits(self) -> int:
241 # Docstring inherited from DataIdPacker.maxBits
242 packedMax = self._n_tracts * self._n_patches
243 if self._n_bands:
244 packedMax *= self._n_bands
245 return (packedMax - 1).bit_length()
246

◆ unpack()

DataCoordinate lsst.skymap.packers.SkyMapDimensionPacker.unpack ( self,
int packedId )

Definition at line 268 of file packers.py.

268 def unpack(self, packedId: int) -> DataCoordinate:
269 # Docstring inherited from DataIdPacker.unpack
270 d = {"skymap": self.fixed["skymap"]}
271 if self._n_bands:
272 index, packedId = divmod(packedId, (self._n_tracts * self._n_patches))
273 if self._bands_list is None:
274 self._bands_list = list(self._bands)
275 d["band"] = self._bands_list[index]
276 d["tract"], d["patch"] = divmod(packedId, self._n_patches)
277 return DataCoordinate.standardize(d, dimensions=self.dimensions)

Member Data Documentation

◆ _bands

lsst.skymap.packers.SkyMapDimensionPacker._bands
protected

Definition at line 177 of file packers.py.

◆ _bands_list

lsst.skymap.packers.SkyMapDimensionPacker._bands_list
protected

Definition at line 181 of file packers.py.

◆ _n_bands

lsst.skymap.packers.SkyMapDimensionPacker._n_bands
protected

Definition at line 178 of file packers.py.

◆ _n_patches

lsst.skymap.packers.SkyMapDimensionPacker._n_patches
protected

Definition at line 180 of file packers.py.

◆ _n_tracts

lsst.skymap.packers.SkyMapDimensionPacker._n_tracts
protected

Definition at line 179 of file packers.py.

◆ ConfigClass

lsst.skymap.packers.SkyMapDimensionPacker.ConfigClass = SkyMapDimensionPackerConfig
static

Definition at line 135 of file packers.py.

◆ SUPPORTED_FILTERS

tuple lsst.skymap.packers.SkyMapDimensionPacker.SUPPORTED_FILTERS
static
Initial value:
= (
[None]
+ list("ugrizyUBGVRIZYJHK") # split string into single chars
+ [f"N{d}" for d in (387, 515, 656, 816, 921, 1010)] # HSC narrow-bands
+ [f"N{d}" for d in (419, 540, 708, 964)] # DECam narrow-bands
)

Definition at line 121 of file packers.py.


The documentation for this class was generated from the following file: