33 minMag = lsst.pex.config.Field(dtype=float, default=18.0, doc=
"Minimum magnitude for mock objects")
34 maxMag = lsst.pex.config.Field(dtype=float, default=20.0, doc=
"Maximum magnitude for mock objects")
35 maxRadius = lsst.pex.config.Field(
36 dtype=float, default=10.0,
37 doc=(
"Maximum radius of an object in arcseconds; only used "
38 "when determining which objects are in an exposure.")
40 spacing = lsst.pex.config.Field(
41 dtype=float, default=20.0,
42 doc=
"Distance between objects (in arcseconds)."
44 seed = lsst.pex.config.Field(dtype=int, default=1, doc=
"Seed for numpy random number generator")
48 """Task that generates simple mock objects and draws them on images, intended as a subtask of
51 May be subclassed to generate things other than stars.
54 ConfigClass = MockObjectConfig
57 lsst.pipe.base.Task.__init__(self, **kwds)
59 self.
center = lsst.afw.table.Point2DKey.addFields(self.
schema,
"center",
60 "center position in tract WCS",
"pixel")
61 self.
magKey = self.schema.addField(
"mag", type=float, doc=
"exact true magnitude")
62 self.
rng = numpy.random.RandomState(self.config.seed)
64 def run(self, tractInfo, catalog=None):
65 """Add records to the truth catalog and return it, delegating to makePositions and defineObject.
67 If the given catalog is not None, add records to this catalog and return it instead
68 of creating a new one.
70 Subclasses should generally not need to override this method.
75 if not catalog.getSchema().contains(self.
schema):
76 raise ValueError(
"Catalog schema does not match Task schema")
78 record = catalog.addNew()
79 record.setCoord(coord)
80 record.set(self.
center, center)
85 """Generate the centers (as a (coord, point) tuple) of mock objects (the point returned is
86 in the tract coordinate system).
88 Default implementation puts objects on a grid that is square in the tract's image coordinate
89 system, with spacing approximately given by config.spacings.
91 The return value is a Python iterable over (coord, point) pairs; the default implementation
92 is actually an iterator (i.e. the function is a "generator"), but derived-class overrides may
95 wcs = tractInfo.getWcs()
96 spacing = self.config.spacing / wcs.pixelScale().asArcseconds()
97 bbox = tractInfo.getBBox()
98 for y
in numpy.arange(bbox.getMinY() + 0.5 * spacing, bbox.getMaxY(), spacing):
99 for x
in numpy.arange(bbox.getMinX() + 0.5 * spacing, bbox.getMaxX(), spacing):
103 """Fill in additional fields in a truth catalog record (id and coord will already have
106 mag = self.rng.rand() * (self.config.maxMag - self.config.minMag) + self.config.minMag
107 record.setD(self.
magKey, mag)
110 """Draw the given truth catalog record on the given exposure, makings use of its Psf, Wcs,
111 Calib, and possibly filter to transform it appropriately.
113 The mask and variance planes of the Exposure are ignored.
115 The 'buffer' parameter is used to expand the source's bounding box when testing whether it
116 is considered fully part of the image.
118 Returns 0 if the object does not appear on the given image at all, 1 if it appears partially,
119 and 2 if it appears fully (including the given buffer).
121 wcs = exposure.getWcs()
122 center = wcs.skyToPixel(record.getCoord())
124 psfImage = exposure.getPsf().computeImage(center).convertF()
127 psfBBox = psfImage.getBBox()
128 overlap = exposure.getBBox()
129 overlap.clip(psfBBox)
130 if overlap.isEmpty():
132 flux = exposure.getCalib().getFlux(record.getD(self.
magKey))
133 normalization = flux / psfImage.getArray().sum()
134 if psfBBox != overlap:
135 psfImage = psfImage.Factory(psfImage, overlap)
141 bufferedBBox.grow(buffer)
142 bufferedOverlap = exposure.getBBox()
143 bufferedOverlap.clip(bufferedBBox)
144 if bufferedOverlap != bufferedBBox:
146 image = exposure.getMaskedImage().getImage()
147 subImage = image.Factory(image, overlap)
148 subImage.scaledPlus(normalization, psfImage)
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
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.