21__all__ = [
"tractBuilderRegistry",
22 "BaseTractBuilderConfig",
"BaseTractBuilder",
23 "LegacyTractBuilderConfig",
"LegacyTractBuilder",
24 "CellTractBuilderConfig",
"CellTractBuilder"]
33from .patchInfo
import PatchInfo
34from .detail
import Index2D
38 """Configuration that is to be shared amongst all tract builders."""
43 """Base class for algorithms that define patches within the tract.
47 config : `lsst.pexConfig.Config`
48 Input for configuring the algorithm
54 """Set up the patches of a particular size in a tract.
56 We grow the tract bounding box to hold an exact multiple of
57 the desired size (patchInnerDimensions or
58 numCellsPerPatchInner*cellInnerDimensions),
while keeping
59 the center roughly the same. We
return the final tract
60 bounding box,
and the number of patches
in each dimension
66 Minimum bounding box
for tract
73 final bounding box, number of patches
77 bboxMin = bbox.getMin()
78 bboxDim = bbox.getDimensions()
79 numPatchesList = [0, 0]
80 for i, innerDim
in enumerate(self._patchInnerDimensions):
81 num = (bboxDim[i] + innerDim - 1) // innerDim
82 deltaDim = (innerDim*num) - bboxDim[i]
84 bboxDim[i] = innerDim * num
85 bboxMin[i] -= deltaDim // 2
86 numPatchesList[i] = num
87 numPatches =
Index2D(*numPatchesList)
94 return bbox, numPatches
97 return self._patchBorder
101 """Return information for the specified patch.
106 Index of patch,
as Index2D
or pair of ints;
107 or a sequential index
as returned by getSequentialPatchIndex;
108 negative values are
not supported.
110 WCS associated
with the tract.
115 The patch info
for that index.
120 If index
is out of range.
122 raise NotImplementedError(
"Must be implemented by a subclass")
125 """Get dimensions of inner region of the patches (all are the same)
127 return self._patchInnerDimensions
130 """Return a single integer that uniquely identifies
131 the given patch within this tract.
139 sequentialIndex : `int`
141 index = patchInfo.getIndex()
145 """Return a single integer that uniquely identifies
146 the patch index within the tract.
154 sequentialIndex : `int`
156 if isinstance(index, Index2D):
159 if not isinstance(index, Iterable):
160 raise ValueError(
"Input index is not an iterable.")
162 raise ValueError(
"Input index does not have two values.")
165 return nx*_index.y + _index.x
168 """Convert sequential index into patch index (x,y) pair.
172 sequentialIndex : `int`
179 x = sequentialIndex % nx
180 y = sequentialIndex // nx
185 """Get a packed config suitable for using in a sha1.
193 configPacked : `bytes`
195 raise NotImplementedError(
"Must be implemented by a subclass")
199 patchInnerDimensions = pexConfig.ListField(
200 doc=
"dimensions of inner region of patches (x,y pixels)",
203 default=(4000, 4000),
205 patchBorder = pexConfig.Field(
206 doc=
"border between patch inner and outer bbox (pixels)",
213 ConfigClass = LegacyTractBuilderConfig
219 for val
in config.patchInnerDimensions))
226 raise RuntimeError(
"Programmer error; this should always be initialized.")
227 if isinstance(index, Index2D):
230 if isinstance(index, numbers.Number):
236 raise IndexError(
"Patch index %s is not in range [0-%d, 0-%d]" %
242 "Bug: patch index %s valid but inner bbox=%s not contained in tract bbox=%s" %
256 subConfig = config.tractBuilder[config.tractBuilder.name]
257 configPacked = struct.pack(
259 subConfig.patchInnerDimensions[0],
260 subConfig.patchInnerDimensions[1],
261 subConfig.patchBorder,
264 config.projection.encode(
'ascii'),
272 cellInnerDimensions = pexConfig.ListField(
273 doc=
"dimensions of inner region of cells (x,y pixels)",
278 cellBorder = pexConfig.Field(
279 doc=
"Border between cell inner and outer bbox (pixels)",
283 numCellsPerPatchInner = pexConfig.Field(
284 doc=
"Number of cells per inner patch.",
288 numCellsInPatchBorder = pexConfig.Field(
289 doc=
"Number of cells in the patch border (outside the inner patch region).",
296 raise ValueError(
"cellInnerDimensions must be 2 ints.")
299 raise ValueError(
"cellInnerDimensions must be equal (for square cells).")
303 ConfigClass = CellTractBuilderConfig
309 for val
in config.cellInnerDimensions))
314 for val
in config.cellInnerDimensions))
322 raise RuntimeError(
"Programmer error; this should always be initialized.")
323 if isinstance(index, Index2D):
326 if isinstance(index, numbers.Number):
332 raise IndexError(
"Patch index %s is not in range [0-%d, 0-%d]" %
338 "Bug: patch index %s valid but inner bbox=%s not contained in tract bbox=%s" %
356 subConfig = config.tractBuilder[config.tractBuilder.name]
357 configPacked = struct.pack(
359 subConfig.cellInnerDimensions[0],
360 subConfig.cellInnerDimensions[1],
361 subConfig.cellBorder,
362 subConfig.numCellsPerPatchInner,
363 subConfig.numCellsInPatchBorder,
366 config.projection.encode(
'ascii'),
373tractBuilderRegistry = pexConfig.makeRegistry(
374 doc=
"A registry of Tract Builders (subclasses of BaseTractBuilder)",
377tractBuilderRegistry.register(
"legacy", LegacyTractBuilder)
378tractBuilderRegistry.register(
"cells", CellTractBuilder)
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
An integer coordinate rectangle.
def getSequentialPatchIndexFromPair(self, index)
def getPatchIndexPair(self, sequentialIndex)
def getPatchInnerDimensions(self)
def getPackedConfig(self, config)
def __init__(self, config)
def getPatchInfo(self, index, tractWcs)
def setupPatches(self, minBBox, wcs)
def getSequentialPatchIndex(self, patchInfo)
def __init__(self, config)
def getPatchInfo(self, index, tractWcs)
def getPackedConfig(self, config)
def __init__(self, config)
def getPatchInfo(self, index, tractWcs)
def getPackedConfig(self, config)