1 from __future__
import absolute_import, division, print_function
3 __all__ = [
"SkyObjectsConfig",
"SkyObjectsTask",
"generateSkyObjects"]
14 """Configuration for generating sky objects""" 15 avoidMask = ListField(dtype=str, default=[
"DETECTED",
"DETECTED_NEGATIVE",
"BAD",
"NO_DATA"],
16 doc=
"Avoid pixels masked with these mask planes")
17 growMask = Field(dtype=int, default=0,
18 doc=
"Number of pixels to grow the masked pixels when adding sky objects")
19 sourceRadius = Field(dtype=float, default=8, doc=
"Radius, in pixels, of sky objects")
20 nSources = Field(dtype=int, default=100, doc=
"Try to add this many sky objects")
21 nTrialSources = Field(dtype=int, default=
None, optional=
True,
22 doc=
"Maximum number of trial sky object positions\n" 23 "(default: nSkySources*nTrialSkySourcesMultiplier)")
24 nTrialSourcesMultiplier = Field(dtype=int, default=5,
25 doc=
"Set nTrialSkySources to\n" 26 " nSkySources*nTrialSkySourcesMultiplier\n" 27 "if nTrialSkySources is None")
31 """Generate a list of Footprints of sky objects 33 Sky objects don't overlap with other objects. This is determined 34 through the provided `mask` (in which objects are typically flagged 37 The algorithm for determining sky objects is random trial and error: 38 we try up to `nTrialSkySources` random positions to find `nSources` 43 mask : `lsst.afw.image.Mask` 44 Input mask plane, which identifies pixels to avoid for the sky 47 Random number generator seed. 48 config : `SkyObjectsConfig` 49 Configuration for finding sky objects. 53 skyFootprints : `list` of `lsst.afw.detection.Footprint` 54 Footprints of sky objects. Each will have a peak at the center 57 if config.nSources <= 0:
60 skySourceRadius = config.sourceRadius
61 nSkySources = config.nSources
62 nTrialSkySources = config.nTrialSources
63 if nTrialSkySources
is None:
64 nTrialSkySources = config.nTrialSourcesMultiplier*nSkySources
67 box.grow(-(int(skySourceRadius) + 1))
68 xMin, yMin = box.getMin()
69 xMax, yMax = box.getMax()
72 if config.growMask > 0:
73 avoid = avoid.dilated(config.growMask)
78 for _
in range(nTrialSkySources):
79 if len(skyFootprints) == nSkySources:
82 x = int(rng.flat(xMin, xMax))
83 y = int(rng.flat(yMin, yMax))
85 if spans.overlaps(avoid):
90 skyFootprints.append(fp)
96 ConfigClass = SkyObjectsConfig
98 def run(self, mask, seed):
99 """Generate a list of Footprints of sky objects 101 Sky objects don't overlap with other objects. This is determined 102 through the provided `mask` (in which objects are typically flagged 105 The algorithm for determining sky objects is random trial and error: 106 we try up to `nTrialSkySources` random positions to find `nSources` 111 mask : `lsst.afw.image.Mask` 112 Input mask plane, which identifies pixels to avoid for the sky 115 Random number generator seed. 119 skyFootprints : `list` of `lsst.afw.detection.Footprint` 120 Footprints of sky objects. Each will have a peak at the center 124 self.log.info(
"Added %d of %d requested sky sources (%.0f%%)", len(skyFootprints),
125 self.config.nSources, 100*len(skyFootprints)/self.config.nSources)
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, UnaryPredicate comparator=details::AnyBitSetFunctor< T >())
def run(self, mask, seed)
def generateSkyObjects(mask, seed, config)
static std::shared_ptr< geom::SpanSet > fromShape(int r, Stencil s=Stencil::CIRCLE, Point2I offset=Point2I())