37def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None):
38 """Create a SchemaMapper between the input source and target schemas.
42 sourceSchema : :py:class:`lsst.afw.table.Schema`
43 Input source schema that fields will be mapped from.
44 targetSchema : :py:class:`lsst.afw.table.Schema`
45 Target schema that fields will be mapped to.
46 sourcePrefix : `str`, optional
47 If set, only those keys with that prefix will be mapped.
48 targetPrefix : `str`, optional
49 If set, prepend it to the mapped (target) key name.
53 SchemaMapper : :py:class:`lsst.afw.table.SchemaMapper`
54 Mapping between source and target schemas.
57 for key, field
in sourceSchema:
58 keyName = field.getName()
59 if sourcePrefix
is not None:
60 if not keyName.startswith(sourcePrefix):
63 keyName = field.getName().replace(sourcePrefix,
"", 1)
64 m.addMapping(key, (targetPrefix
or "") + keyName)
69 """Return a schema that is a deep copy of a mapping between source and target schemas.
73 sourceSchema : :py:class:`lsst.afw.table.Schema`
74 Input source schema that fields will be mapped from.
75 targetSchema : :py:class:`lsst.afw.atable.Schema`
76 Target schema that fields will be mapped to.
77 sourcePrefix : `str`, optional
78 If set, only those keys with that prefix will be mapped.
79 targetPrefix : `str`, optional
80 If set, prepend it to the mapped (target) key name.
84 schema : :py:class:`lsst.afw.table.Schema`
85 Schema that is the result of the mapping between source and target schemas.
87 return makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix).getOutputSchema()
90def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None):
91 """Copy entries from one Catalog into another.
95 catalog : :py:class:`lsst.afw.table.base.Catalog`
96 Source catalog to be copied from.
97 target : :py:class:`lsst.afw.table.base.Catalog`
98 Target catalog to be copied to (edited in place).
99 sourceSchema : :py:class:`lsst.afw.table.Schema`, optional
100 Schema of source catalog.
101 sourcePrefix : `str`, optional
102 If set, only those keys with that prefix will be copied.
103 targetPrefix : `str`, optional
104 If set, prepend it to the copied (target) key name
108 target : :py:class:`lsst.afw.table.base.Catalog`
109 Target catalog that is edited in place.
111 if sourceSchema
is None:
112 sourceSchema = catalog.schema
114 targetSchema = target.schema
115 target.reserve(len(catalog))
116 for i
in range(len(target), len(catalog)):
119 if len(catalog) != len(target):
120 raise RuntimeError(f
"Length mismatch: {len(catalog)} vs {len(target)}")
122 m =
makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix)
123 for rFrom, rTo
in zip(catalog, target):
128 """Denormalise matches into a Catalog of "unpacked matches".
132 matches : `~lsst.afw.table.match.SimpleMatch`
133 Unpacked matches, i.e. a list of Match objects whose schema
134 has "first" and "second" attributes which, resepectively,
135 contain the reference and source catalog entries, and a
136 "distance" field (the measured distance between the reference
138 matchMeta : `~lsst.daf.base.PropertySet`
139 Metadata for matches (must have .add attribute).
143 mergedCatalog : :py:class:`lsst.afw.table.BaseCatalog`
144 Catalog of matches (with ``ref_`` and ``src_`` prefix identifiers for
145 referece and source entries, respectively, including alias
146 maps from reference and source catalogs)
148 if len(matches) == 0:
149 raise RuntimeError(
"No matches provided.")
151 refSchema = matches[0].first.getSchema()
152 srcSchema = matches[0].second.getSchema()
156 srcSchema, mergedSchema, targetPrefix=
"src_")
161 distKey = mergedSchema.addField(
162 "distance", type=np.float64, doc=
"Distance between ref and src")
166 sourceSchema=refSchema, targetPrefix=
"ref_")
168 sourceSchema=srcSchema, targetPrefix=
"src_")
169 for m, r
in zip(matches, mergedCatalog):
170 r.set(distKey, m.distance)
173 catalogName =
"NOT_SET"
174 matchMeta.add(
"REFCAT", catalogName)
175 mergedCatalog.getTable().setMetadata(matchMeta)
181 """Generate a list of ReferenceMatches from a Catalog of "unpacked matches".
185 catalog : :py:class:`lsst.afw.table.BaseCatalog`
186 Catalog of matches. Must have schema where reference entries
187 are prefixed with ``ref_`` and source entries are prefixed with
189 sourceSlotConfig : `lsst.meas.base.baseMeasurement.SourceSlotConfig`, optional
190 Configuration for source slots.
194 matches : :py:class:`lsst.afw.table.ReferenceMatch`
198 catalog.schema, SimpleTable.makeMinimalSchema(), sourcePrefix=
"ref_")
203 catalog.schema, SourceTable.makeMinimalSchema(), sourcePrefix=
"src_")
207 if sourceSlotConfig
is not None:
208 sourceSlotConfig.setupSchema(srcCatalog.schema)
211 distKey = catalog.schema.find(
"distance").key
212 for ref, src, cat
in zip(refCatalog, srcCatalog, catalog):