32 minMag = lsst.pex.config.Field(dtype=float, default=18.0, doc=
"Minimum magnitude for mock objects")
33 maxMag = lsst.pex.config.Field(dtype=float, default=20.0, doc=
"Maximum magnitude for mock objects")
34 maxRadius = lsst.pex.config.Field(
35 dtype=float, default=10.0,
36 doc=(
"Maximum radius of an object in arcseconds; only used "
37 "when determining which objects are in an exposure.")
39 spacing = lsst.pex.config.Field(
40 dtype=float, default=20.0,
41 doc=
"Distance between objects (in arcseconds)."
43 seed = lsst.pex.config.Field(dtype=int, default=1, doc=
"Seed for numpy random number generator")
46 """Task that generates simple mock objects and draws them on images, intended as a subtask of
49 May be subclassed to generate things other than stars.
52 ConfigClass = MockObjectConfig
55 lsst.pipe.base.Task.__init__(self, **kwds)
57 self.
center = lsst.afw.table.Point2DKey.addFields(self.
schema,
"center",
58 "center position in tract WCS",
"pixels")
59 self.
magKey = self.schema.addField(
"mag", type=float, doc=
"exact true magnitude")
60 self.
rng = numpy.random.RandomState(self.config.seed)
62 def run(self, tractInfo, catalog=None):
63 """Add records to the truth catalog and return it, delegating to makePositions and defineObject.
65 If the given catalog is not None, add records to this catalog and return it instead
66 of creating a new one.
68 Subclasses should generally not need to override this method.
73 if not catalog.getSchema().contains(self.
schema):
74 raise ValueError(
"Catalog schema does not match Task schema")
76 record = catalog.addNew()
77 record.setCoord(coord)
78 record.set(self.
center, center)
83 """Generate the centers (as a (coord, point) tuple) of mock objects (the point returned is
84 in the tract coordinate system).
86 Default implementation puts objects on a grid that is square in the tract's image coordinate
87 system, with spacing approximately given by config.spacings.
89 The return value is a Python iterable over (coord, point) pairs; the default implementation
90 is actually an iterator (i.e. the function is a "generator"), but derived-class overrides may
93 wcs = tractInfo.getWcs()
94 spacing = self.config.spacing / wcs.pixelScale().asArcseconds()
95 bbox = tractInfo.getBBox()
96 for y
in numpy.arange(bbox.getMinY() + 0.5 * spacing, bbox.getMaxY(), spacing):
97 for x
in numpy.arange(bbox.getMinX() + 0.5 * spacing, bbox.getMaxX(), spacing):
101 """Fill in additional fields in a truth catalog record (id and coord will already have
104 mag = self.rng.rand() * (self.config.maxMag - self.config.minMag) + self.config.minMag
105 record.setD(self.
magKey, mag)
108 """Draw the given truth catalog record on the given exposure, makings use of its Psf, Wcs,
109 Calib, and possibly filter to transform it appropriately.
111 The mask and variance planes of the Exposure are ignored.
113 The 'buffer' parameter is used to expand the source's bounding box when testing whether it
114 is considered fully part of the image.
116 Returns 0 if the object does not appear on the given image at all, 1 if it appears partially,
117 and 2 if it appears fully (including the given buffer).
119 wcs = exposure.getWcs()
120 center = wcs.skyToPixel(record.getCoord())
122 psfImage = exposure.getPsf().computeImage(center).convertF()
125 psfBBox = psfImage.getBBox()
126 overlap = exposure.getBBox()
127 overlap.clip(psfBBox)
128 if overlap.isEmpty():
130 flux = exposure.getCalib().getFlux(record.getD(self.
magKey))
131 normalization = flux / psfImage.getArray().
sum()
132 if psfBBox != overlap:
133 psfImage = psfImage.Factory(psfImage, overlap)
139 bufferedBBox.grow(buffer)
140 bufferedOverlap = exposure.getBBox()
141 bufferedOverlap.clip(bufferedBBox)
142 if bufferedOverlap != bufferedBBox:
144 image = exposure.getMaskedImage().getImage()
145 subImage = image.Factory(image, overlap)
146 subImage.scaledPlus(normalization, psfImage)
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
An integer coordinate rectangle.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.