22 __all__ = [
"makeMergedSchema",
"copyIntoCatalog",
23 "matchesToCatalog",
"matchesFromCatalog",
"copyAliasMapWithPrefix",
31 from ._schema
import Schema
32 from ._schemaMapper
import SchemaMapper
33 from ._base
import BaseCatalog
34 from ._table
import SimpleTable
35 from ._simple
import SimpleCatalog
36 from ._source
import SourceCatalog, SourceTable
37 from ._match
import ReferenceMatch
42 def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None):
43 """Create a SchemaMapper between the input source and target schemas.
47 sourceSchema : :py:class:`lsst.afw.table.Schema`
48 Input source schema that fields will be mapped from.
49 targetSchema : :py:class:`lsst.afw.table.Schema`
50 Target schema that fields will be mapped to.
51 sourcePrefix : `str`, optional
52 If set, only those keys with that prefix will be mapped.
53 targetPrefix : `str`, optional
54 If set, prepend it to the mapped (target) key name.
58 SchemaMapper : :py:class:`lsst.afw.table.SchemaMapper`
59 Mapping between source and target schemas.
62 for key, field
in sourceSchema:
63 keyName = field.getName()
64 if sourcePrefix
is not None:
65 if not keyName.startswith(sourcePrefix):
68 keyName = field.getName().replace(sourcePrefix,
"", 1)
69 m.addMapping(key, (targetPrefix
or "") + keyName)
73 def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None):
74 """Return a schema that is a deep copy of a mapping between source and target schemas.
78 sourceSchema : :py:class:`lsst.afw.table.Schema`
79 Input source schema that fields will be mapped from.
80 targetSchema : :py:class:`lsst.afw.atable.Schema`
81 Target schema that fields will be mapped to.
82 sourcePrefix : `str`, optional
83 If set, only those keys with that prefix will be mapped.
84 targetPrefix : `str`, optional
85 If set, prepend it to the mapped (target) key name.
89 schema : :py:class:`lsst.afw.table.Schema`
90 Schema that is the result of the mapping between source and target schemas.
92 return makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix).getOutputSchema()
95 def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None):
96 """Copy entries from one Catalog into another.
100 catalog : :py:class:`lsst.afw.table.base.Catalog`
101 Source catalog to be copied from.
102 target : :py:class:`lsst.afw.table.base.Catalog`
103 Target catalog to be copied to (edited in place).
104 sourceSchema : :py:class:`lsst.afw.table.Schema`, optional
105 Schema of source catalog.
106 sourcePrefix : `str`, optional
107 If set, only those keys with that prefix will be copied.
108 targetPrefix : `str`, optional
109 If set, prepend it to the copied (target) key name
113 target : :py:class:`lsst.afw.table.base.Catalog`
114 Target catalog that is edited in place.
116 if sourceSchema
is None:
117 sourceSchema = catalog.schema
119 targetSchema = target.schema
120 target.reserve(len(catalog))
121 for i
in range(len(target), len(catalog)):
124 if len(catalog) != len(target):
125 raise RuntimeError(f
"Length mismatch: {len(catalog)} vs {len(target)}")
127 m =
makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix)
128 for rFrom, rTo
in zip(catalog, target):
133 """Denormalise matches into a Catalog of "unpacked matches".
137 matches : `~lsst.afw.table.match.SimpleMatch`
138 Unpacked matches, i.e. a list of Match objects whose schema
139 has "first" and "second" attributes which, resepectively,
140 contain the reference and source catalog entries, and a
141 "distance" field (the measured distance between the reference
143 matchMeta : `~lsst.daf.base.PropertySet`
144 Metadata for matches (must have .add attribute).
148 mergedCatalog : :py:class:`lsst.afw.table.BaseCatalog`
149 Catalog of matches (with ``ref_`` and ``src_`` prefix identifiers for
150 referece and source entries, respectively, including alias
151 maps from reference and source catalogs)
153 if len(matches) == 0:
154 raise RuntimeError(
"No matches provided.")
156 refSchema = matches[0].first.getSchema()
157 srcSchema = matches[0].second.getSchema()
161 srcSchema, mergedSchema, targetPrefix=
"src_")
166 distKey = mergedSchema.addField(
167 "distance", type=np.float64, doc=
"Distance between ref and src")
171 sourceSchema=refSchema, targetPrefix=
"ref_")
173 sourceSchema=srcSchema, targetPrefix=
"src_")
174 for m, r
in zip(matches, mergedCatalog):
175 r.set(distKey, m.distance)
179 catalogName = os.path.basename(getPackageDir(
"astrometry_net_data"))
181 catalogName =
"NOT_SET"
182 matchMeta.add(
"REFCAT", catalogName)
183 mergedCatalog.getTable().setMetadata(matchMeta)
189 """Generate a list of ReferenceMatches from a Catalog of "unpacked matches".
193 catalog : :py:class:`lsst.afw.table.BaseCatalog`
194 Catalog of matches. Must have schema where reference entries
195 are prefixed with ``ref_`` and source entries are prefixed with
197 sourceSlotConfig : `lsst.meas.base.baseMeasurement.SourceSlotConfig`, optional
198 Configuration for source slots.
202 matches : :py:class:`lsst.afw.table.ReferenceMatch`
206 catalog.schema, SimpleTable.makeMinimalSchema(), sourcePrefix=
"ref_")
211 catalog.schema, SourceTable.makeMinimalSchema(), sourcePrefix=
"src_")
215 if sourceSlotConfig
is not None:
216 sourceSlotConfig.setupSchema(srcCatalog.schema)
219 distKey = catalog.schema.find(
"distance").key
220 for ref, src, cat
in zip(refCatalog, srcCatalog, catalog):
227 """Copy an alias map from one schema into another.
229 This copies the alias map of one schema into another, optionally
230 prepending a prefix to both the "from" and "to" names of the alias
231 (the example use case here is for the "match" catalog created by
232 `lsst.meas.astrom.denormalizeMatches` where prefixes ``src_`` and
233 ``ref_`` are added to the source and reference field entries,
238 inSchema : `lsst.afw.table.Schema`
239 The input schema whose `lsst.afw.table.AliasMap` is to be
240 copied to ``outSchema``.
241 outSchema : `lsst.afw.table.Schema`
242 The output schema into which the `lsst.afw.table.AliasMap`
243 from ``inSchema`` is to be copied (modified in place).
244 prefix : `str`, optional
245 An optional prefix to add to both the "from" and "to" names
246 of the alias (default is an empty string).
250 outSchema : `lsst.afw.table.Schema`
251 The output schema with the alias mappings from `inSchema`
254 for k, v
in inSchema.getAliasMap().
items():
255 outSchema.getAliasMap().
set(prefix + k, prefix + v)
261 """Apply a numpy index array to an afw Catalog
265 catalog : `lsst.afw.table.SourceCatalog`
267 indices : `numpy.ndarray` of `int`
270 Whether or not to make a deep copy of the original catalog.
274 new : subclass of `lsst.afw.table.BaseCatalog`
275 Reindexed catalog. Records are shallow copies of those in ``catalog``.
277 new =
SourceCatalog(catalog.table.clone()
if deep
else catalog.table)
278 records = [catalog[int(ii)]
for ii
in indices]
279 new.extend(records, deep=deep)
std::vector< SchemaItem< Flag > > * items
daf::base::PropertySet * set
def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def matchesToCatalog(matches, matchMeta)
def reindexCatalog(catalog, indices, deep=True)
def copyAliasMapWithPrefix(inSchema, outSchema, prefix="")
def matchesFromCatalog(catalog, sourceSlotConfig=None)
def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None)
Match< SimpleRecord, SourceRecord > ReferenceMatch
SortedCatalogT< SimpleRecord > SimpleCatalog
CatalogT< BaseRecord > BaseCatalog