23 __all__ = [
"makeMergedSchema",
"copyIntoCatalog",
24 "matchesToCatalog",
"matchesFromCatalog"]
31 from .schema
import Schema
32 from .schemaMapper
import SchemaMapper
33 from .base
import BaseCatalog
34 from .simple
import SimpleCatalog, SimpleTable
35 from .source
import SourceCatalog, SourceTable
36 from .match
import ReferenceMatch
41 def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None):
42 """Create a SchemaMapper between the input source and target schemas 44 @param[in] sourceSchema input source schema that fields will be mapped from 45 @param[in] targetSchema target schema that fields will be mapped to 46 @param[in] sourcePrefix if set, only those keys with that prefix will be mapped 47 @param[in] targetPrefix if set, prepend it to the mapped (target) key name 49 @return SchemaMapper between source and target schemas 52 for key, field
in sourceSchema:
53 keyName = field.getName()
54 if sourcePrefix
is not None:
55 if not keyName.startswith(sourcePrefix):
58 keyName = field.getName().replace(sourcePrefix,
"", 1)
59 m.addMapping(key, (targetPrefix
or "") + keyName)
63 def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None):
64 """Return a schema that is a deep copy of a mapping between source and target schemas 65 @param[in] sourceSchema input source schema that fields will be mapped from 66 @param[in] targetSchema target schema that fields will be mapped to 67 @param[in] sourcePrefix if set, only those keys with that prefix will be mapped 68 @param[in] targetPrefix if set, prepend it to the mapped (target) key name 70 @return schema schema that is the result of the mapping between source and target schemas 72 return makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix).getOutputSchema()
75 def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None):
76 """Copy entries from one Catalog into another 78 @param[in] catalog source catalog to be copied from 79 @param[in/out] target target catalog to be copied to (edited in place) 80 @param[in] souceSchema schema of source catalog (optional) 81 @param[in] sourcePrefix if set, only those keys with that prefix will be copied 82 @param[in] targetPrefix if set, prepend it to the copied (target) key name 84 if sourceSchema
is None:
85 sourceSchema = catalog.schema
87 targetSchema = target.schema
88 target.reserve(len(catalog))
89 for i
in range(len(target), len(catalog)):
92 if len(catalog) != len(target):
93 raise RuntimeError(
"Length mismatch: %d vs %d" %
94 (len(catalog), len(target)))
96 m =
makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix)
97 for rFrom, rTo
in zip(catalog, target):
102 """Denormalise matches into a Catalog of "unpacked matches" 104 @param[in] matches unpacked matches, i.e. a list of Match objects whose schema 105 has "first" and "second" attributes which, resepectively, contain the 106 reference and source catalog entries, and a "distance" field (the 107 measured distance between the reference and source objects) 108 @param[in] matchMeta metadata for matches (must have .add attribute) 110 @return lsst.afw.table.BaseCatalog of matches (with ref_ and src_ prefix identifiers 111 for referece and source entries, respectively) 113 if len(matches) == 0:
114 raise RuntimeError(
"No matches provided.")
116 refSchema = matches[0].first.getSchema()
117 srcSchema = matches[0].second.getSchema()
121 srcSchema, mergedSchema, targetPrefix=
"src_")
122 distKey = mergedSchema.addField(
123 "distance", type=np.float64, doc=
"Distance between ref and src")
127 sourceSchema=refSchema, targetPrefix=
"ref_")
129 sourceSchema=srcSchema, targetPrefix=
"src_")
130 for m, r
in zip(matches, mergedCatalog):
131 r.set(distKey, m.distance)
135 catalogName = os.path.basename(getPackageDir(
"astrometry_net_data"))
137 catalogName =
"NOT_SET" 138 matchMeta.add(
"REFCAT", catalogName)
139 mergedCatalog.getTable().setMetadata(matchMeta)
145 """Generate a list of ReferenceMatches from a Catalog of "unpacked matches" 147 @param[in] catalog catalog of matches. Must have schema where reference entries are 148 prefixed with "ref_" and source entries are prefixed with "src_" 149 @param[in] sourceSlotConfig an lsst.meas.base.baseMeasurement.SourceSlotConfig configuration 150 for source slots (optional) 152 @returns lsst.afw.table.ReferenceMatch of matches 155 catalog.schema, SimpleTable.makeMinimalSchema(), sourcePrefix=
"ref_")
160 catalog.schema, SourceTable.makeMinimalSchema(), sourcePrefix=
"src_")
164 if sourceSlotConfig
is not None:
165 sourceSlotConfig.setupSchema(srcCatalog.schema)
168 distKey = catalog.schema.find(
"distance").key
169 for ref, src, cat
in zip(refCatalog, srcCatalog, catalog):
CatalogT< BaseRecord > BaseCatalog
def matchesFromCatalog(catalog, sourceSlotConfig=None)
def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def matchesToCatalog(matches, matchMeta)
def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None)
Match< SimpleRecord, SourceRecord > ReferenceMatch
SortedCatalogT< SimpleRecord > SimpleCatalog