22 from collections.abc
import Iterable
30 """Recreate the `NoiseReplacer` used in measurement.
32 Given a measurement catalog and the exposure on which the measurements
33 were made, reconstruct the `NoiseReplacer` object that was used to mask
34 out sources during measurement.
38 exposure : `lsst.afw.exposure.Exposure`
39 The image on which measurements were made.
41 measCat : `lsst.afw.table.SourceCatalog`
42 Catalog containing the results measurements on each source.
46 noiseReplacer : `NoiseReplacer`
47 Object used to replace and/or restore sources in the exposure with
51 algMetadata = measCat.getMetadata()
53 noiseReplacerConf.noiseSeedMultiplier = \
54 algMetadata.getScalar(SFMT.NOISE_SEED_MULTIPLIER)
55 noiseReplacerConf.noiseSource = algMetadata.getScalar(SFMT.NOISE_SOURCE)
56 noiseReplacerConf.noiseOffset = algMetadata.getScalar(SFMT.NOISE_OFFSET)
58 footprints = {src.getId(): (src.getParent(), src.getFootprint())
62 exposureId = algMetadata.getScalar(SFMT.NOISE_EXPOSURE_ID)
66 noiseReplacer =
NoiseReplacer(noiseReplacerConf, exposure, footprints,
67 exposureId=exposureId)
72 resetParents=True, addParents=False):
73 """Create a catalog prepopulated with IDs.
75 This function is used to generate a `~lsst.afw.table.SourceCatalog`
76 containing blank records with IDs as specified in the ``idList``
79 This function is primarily used when re-running measurements on a
80 particular footprint. Specifying IDs in the new measurement catalog which
81 correspond to IDs in the old catalog makes comparing results much easier.
83 The ``resetParents`` and ``addParents`` options are needed because
84 `SingleFrameMeasurementTask.runPlugins` will skip child
85 objects whose parents are not in the catalog.
89 schema : `lsst.afw.table.Schema`
90 Schema used to describe the fields in the resulting catalog.
92 oldCatalog : `lsst.afw.table.SourceCatalog`
93 Catalog containing previous measurements.
95 idList : iterable of `int`
96 Iterable whose values should be numbers corresponding to measurement
97 IDs which exist in ``oldCatalog``.
99 fields : iterable of `str`
100 Iterable whose entries should be strings corresponding to schema keys
101 that exist in both the old catalog and input schema. Fields listed
102 will be copied from the old catalog into the new catalog.
104 resetParents : `bool`
105 If `True`, child objects whose parents are not in the ``idList``
106 will have their parents reset to zero.
109 If `True`, parents of child objects will be added to ``idList`` if
110 they are not already present.
114 measCat : `lsst.afw.table.SourceCatalog`
115 Catalog prepopulated with entries with the IDs specified.
118 if not isinstance(schema, Schema):
119 raise RuntimeError(
"schema must be an instance of "
120 "lsst.afw.table.Schema")
122 if not isinstance(oldCatalog, SourceCatalog):
123 raise RuntimeError(
"oldCatalog must be an instance of "
124 "lsst.afw.table.SourceCatalogiterable")
128 if not isinstance(fields, Iterable):
129 raise RuntimeError(
"fields list must be an iterable with string"
132 if entry
not in schema:
133 schema.addField(oldCatalog.schema.find(entry).field)
139 parentId = oldCatalog.find(srcId).getParent()
141 newIdList.add(parentId)
143 idList = sorted(idList)
147 oldSrc = oldCatalog.find(srcId)
148 src = measCat.addNew()
150 src.setFootprint(oldSrc.getFootprint())
151 parent = oldSrc.getParent()
152 if resetParents
and parent
and parent
not in idList:
154 src.setParent(parent)
155 src.setCoord(oldSrc.getCoord())
157 src[entry] = oldSrc[entry]