LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Functions
lsst.afw.table.catalogMatches Namespace Reference

Functions

def makeMapper (sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
 
def makeMergedSchema (sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
 
def copyIntoCatalog (catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None)
 
def matchesToCatalog (matches, matchMeta)
 
def matchesFromCatalog (catalog, sourceSlotConfig=None)
 
def copyAliasMapWithPrefix (inSchema, outSchema, prefix="")
 

Function Documentation

◆ copyAliasMapWithPrefix()

def lsst.afw.table.catalogMatches.copyAliasMapWithPrefix (   inSchema,
  outSchema,
  prefix = "" 
)
Copy an alias map from one schema into another.

This copies the alias map of one schema into another, optionally
prepending a prefix to both the "from" and "to" names of the alias
(the example use case here is for the "match" catalog created by
`lsst.meas.astrom.denormalizeMatches` where prefixes "src_" and
"ref_" are added to the source and reference field entries,
respectively).

Parameters
----------
inSchema : `lsst.afw.table.Schema`
   The input schema whose `lsst.afw.table.AliasMap` is to be
   copied to ``outSchema``.
outSchema : `lsst.afw.table.Schema`
   The output schema into which the `lsst.afw.table.AliasMap`
   from ``inSchema`` is to be copied (modified in place).
prefix : `str`, optional
   An optional prefix to add to both the "from" and "to" names
   of the alias (default is an empty string).

Returns
-------
outSchema : `lsst.afw.table.Schema`
   The output schema with the alias mappings from `inSchema`
   added.

Definition at line 226 of file catalogMatches.py.

226 def copyAliasMapWithPrefix(inSchema, outSchema, prefix=""):
227  """Copy an alias map from one schema into another.
228 
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,
234  respectively).
235 
236  Parameters
237  ----------
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).
247 
248  Returns
249  -------
250  outSchema : `lsst.afw.table.Schema`
251  The output schema with the alias mappings from `inSchema`
252  added.
253  """
254  for k, v in inSchema.getAliasMap().items():
255  outSchema.getAliasMap().set(prefix + k, prefix + v)
256 
257  return outSchema
258 
std::vector< SchemaItem< Flag > > * items
daf::base::PropertySet * set
Definition: fits.cc:902
def copyAliasMapWithPrefix(inSchema, outSchema, prefix="")

◆ copyIntoCatalog()

def lsst.afw.table.catalogMatches.copyIntoCatalog (   catalog,
  target,
  sourceSchema = None,
  sourcePrefix = None,
  targetPrefix = None 
)
Copy entries from one Catalog into another.

Parameters
----------
catalog : :py:class:`lsst.afw.table.base.Catalog`
    Source catalog to be copied from.
target : :py:class:`lsst.afw.table.base.Catalog`
    Target catalog to be copied to (edited in place).
sourceSchema : :py:class:`lsst.afw.table.Schema`, optional
    Schema of source catalog.
sourcePrefix : `str`, optional
    If set, only those keys with that prefix will be copied.
targetPrefix : `str`, optional
    If set, prepend it to the copied (target) key name

Returns
-------
target : :py:class:`lsst.afw.table.base.Catalog`
    Target catalog that is edited in place.

Definition at line 94 of file catalogMatches.py.

94 def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None):
95  """Copy entries from one Catalog into another.
96 
97  Parameters
98  ----------
99  catalog : :py:class:`lsst.afw.table.base.Catalog`
100  Source catalog to be copied from.
101  target : :py:class:`lsst.afw.table.base.Catalog`
102  Target catalog to be copied to (edited in place).
103  sourceSchema : :py:class:`lsst.afw.table.Schema`, optional
104  Schema of source catalog.
105  sourcePrefix : `str`, optional
106  If set, only those keys with that prefix will be copied.
107  targetPrefix : `str`, optional
108  If set, prepend it to the copied (target) key name
109 
110  Returns
111  -------
112  target : :py:class:`lsst.afw.table.base.Catalog`
113  Target catalog that is edited in place.
114  """
115  if sourceSchema is None:
116  sourceSchema = catalog.schema
117 
118  targetSchema = target.schema
119  target.reserve(len(catalog))
120  for i in range(len(target), len(catalog)):
121  target.addNew()
122 
123  if len(catalog) != len(target):
124  raise RuntimeError("Length mismatch: %d vs %d" %
125  (len(catalog), len(target)))
126 
127  m = makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix)
128  for rFrom, rTo in zip(catalog, target):
129  rTo.assign(rFrom, m)
130 
131 
def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None)

◆ makeMapper()

def lsst.afw.table.catalogMatches.makeMapper (   sourceSchema,
  targetSchema,
  sourcePrefix = None,
  targetPrefix = None 
)
Create a SchemaMapper between the input source and target schemas.

Parameters
----------
sourceSchema : :py:class:`lsst.afw.table.Schema`
    Input source schema that fields will be mapped from.
targetSchema : :py:class:`lsst.afw.table.Schema`
    Target schema that fields will be mapped to.
sourcePrefix : `str`, optional
    If set, only those keys with that prefix will be mapped.
targetPrefix : `str`, optional
    If set, prepend it to the mapped (target) key name.

Returns
-------
SchemaMapper : :py:class:`lsst.afw.table.SchemaMapper`
    Mapping between source and target schemas.

Definition at line 41 of file catalogMatches.py.

41 def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None):
42  """Create a SchemaMapper between the input source and target schemas.
43 
44  Parameters
45  ----------
46  sourceSchema : :py:class:`lsst.afw.table.Schema`
47  Input source schema that fields will be mapped from.
48  targetSchema : :py:class:`lsst.afw.table.Schema`
49  Target schema that fields will be mapped to.
50  sourcePrefix : `str`, optional
51  If set, only those keys with that prefix will be mapped.
52  targetPrefix : `str`, optional
53  If set, prepend it to the mapped (target) key name.
54 
55  Returns
56  -------
57  SchemaMapper : :py:class:`lsst.afw.table.SchemaMapper`
58  Mapping between source and target schemas.
59  """
60  m = SchemaMapper(sourceSchema, targetSchema)
61  for key, field in sourceSchema:
62  keyName = field.getName()
63  if sourcePrefix is not None:
64  if not keyName.startswith(sourcePrefix):
65  continue
66  else:
67  keyName = field.getName().replace(sourcePrefix, "", 1)
68  m.addMapping(key, (targetPrefix or "") + keyName)
69  return m
70 
71 
def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)

◆ makeMergedSchema()

def lsst.afw.table.catalogMatches.makeMergedSchema (   sourceSchema,
  targetSchema,
  sourcePrefix = None,
  targetPrefix = None 
)
Return a schema that is a deep copy of a mapping between source and target schemas.

Parameters
----------
sourceSchema : :py:class:`lsst.afw.table.Schema`
    Input source schema that fields will be mapped from.
targetSchema : :py:class:`lsst.afw.atable.Schema`
    Target schema that fields will be mapped to.
sourcePrefix : `str`, optional
    If set, only those keys with that prefix will be mapped.
targetPrefix : `str`, optional
    If set, prepend it to the mapped (target) key name.

Returns
-------
schema : :py:class:`lsst.afw.table.Schema`
    Schema that is the result of the mapping between source and target schemas.

Definition at line 72 of file catalogMatches.py.

72 def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None):
73  """Return a schema that is a deep copy of a mapping between source and target schemas.
74 
75  Parameters
76  ----------
77  sourceSchema : :py:class:`lsst.afw.table.Schema`
78  Input source schema that fields will be mapped from.
79  targetSchema : :py:class:`lsst.afw.atable.Schema`
80  Target schema that fields will be mapped to.
81  sourcePrefix : `str`, optional
82  If set, only those keys with that prefix will be mapped.
83  targetPrefix : `str`, optional
84  If set, prepend it to the mapped (target) key name.
85 
86  Returns
87  -------
88  schema : :py:class:`lsst.afw.table.Schema`
89  Schema that is the result of the mapping between source and target schemas.
90  """
91  return makeMapper(sourceSchema, targetSchema, sourcePrefix, targetPrefix).getOutputSchema()
92 
93 
def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def makeMapper(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)

◆ matchesFromCatalog()

def lsst.afw.table.catalogMatches.matchesFromCatalog (   catalog,
  sourceSlotConfig = None 
)
Generate a list of ReferenceMatches from a Catalog of "unpacked matches".

Parameters
----------
catalog : :py:class:`lsst.afw.table.BaseCatalog`
    Catalog of matches.  Must have schema where reference entries
    are prefixed with "ref_" and source entries are prefixed with
    "src_".
sourceSlotConfig : `lsst.meas.base.baseMeasurement.SourceSlotConfig`, optional
    Configuration for source slots.

Returns
-------
matches : :py:class:`lsst.afw.table.ReferenceMatch`
    List of matches.

Definition at line 188 of file catalogMatches.py.

188 def matchesFromCatalog(catalog, sourceSlotConfig=None):
189  """Generate a list of ReferenceMatches from a Catalog of "unpacked matches".
190 
191  Parameters
192  ----------
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
196  "src_".
197  sourceSlotConfig : `lsst.meas.base.baseMeasurement.SourceSlotConfig`, optional
198  Configuration for source slots.
199 
200  Returns
201  -------
202  matches : :py:class:`lsst.afw.table.ReferenceMatch`
203  List of matches.
204  """
205  refSchema = makeMergedSchema(
206  catalog.schema, SimpleTable.makeMinimalSchema(), sourcePrefix="ref_")
207  refCatalog = SimpleCatalog(refSchema)
208  copyIntoCatalog(catalog, refCatalog, sourcePrefix="ref_")
209 
210  srcSchema = makeMergedSchema(
211  catalog.schema, SourceTable.makeMinimalSchema(), sourcePrefix="src_")
212  srcCatalog = SourceCatalog(srcSchema)
213  copyIntoCatalog(catalog, srcCatalog, sourcePrefix="src_")
214 
215  if sourceSlotConfig is not None:
216  sourceSlotConfig.setupSchema(srcCatalog.schema)
217 
218  matches = []
219  distKey = catalog.schema.find("distance").key
220  for ref, src, cat in zip(refCatalog, srcCatalog, catalog):
221  matches.append(ReferenceMatch(ref, src, cat[distKey]))
222 
223  return matches
224 
225 
def matchesFromCatalog(catalog, sourceSlotConfig=None)
def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None)
Match< SimpleRecord, SourceRecord > ReferenceMatch
Definition: fwd.h:104
SortedCatalogT< SourceRecord > SourceCatalog
Definition: fwd.h:85
SortedCatalogT< SimpleRecord > SimpleCatalog
Definition: fwd.h:79

◆ matchesToCatalog()

def lsst.afw.table.catalogMatches.matchesToCatalog (   matches,
  matchMeta 
)
Denormalise matches into a Catalog of "unpacked matches".

Parameters
----------
matches : `~lsst.afw.table.match.SimpleMatch`
    Unpacked matches, i.e. a list of Match objects whose schema
    has "first" and "second" attributes which, resepectively,
    contain the reference and source catalog entries, and a
    "distance" field (the measured distance between the reference
    and source objects).
matchMeta : `~lsst.daf.base.PropertySet`
    Metadata for matches (must have .add attribute).

Returns
-------
mergedCatalog : :py:class:`lsst.afw.table.BaseCatalog`
    Catalog of matches (with ref_ and src_ prefix identifiers for
    referece and source entries, respectively, including alias
    maps from reference and source catalogs)

Definition at line 132 of file catalogMatches.py.

132 def matchesToCatalog(matches, matchMeta):
133  """Denormalise matches into a Catalog of "unpacked matches".
134 
135  Parameters
136  ----------
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
142  and source objects).
143  matchMeta : `~lsst.daf.base.PropertySet`
144  Metadata for matches (must have .add attribute).
145 
146  Returns
147  -------
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)
152  """
153  if len(matches) == 0:
154  raise RuntimeError("No matches provided.")
155 
156  refSchema = matches[0].first.getSchema()
157  srcSchema = matches[0].second.getSchema()
158 
159  mergedSchema = makeMergedSchema(refSchema, Schema(), targetPrefix="ref_")
160  mergedSchema = makeMergedSchema(
161  srcSchema, mergedSchema, targetPrefix="src_")
162 
163  mergedSchema = copyAliasMapWithPrefix(refSchema, mergedSchema, prefix="ref_")
164  mergedSchema = copyAliasMapWithPrefix(srcSchema, mergedSchema, prefix="src_")
165 
166  distKey = mergedSchema.addField(
167  "distance", type=np.float64, doc="Distance between ref and src")
168 
169  mergedCatalog = BaseCatalog(mergedSchema)
170  copyIntoCatalog([m.first for m in matches], mergedCatalog,
171  sourceSchema=refSchema, targetPrefix="ref_")
172  copyIntoCatalog([m.second for m in matches], mergedCatalog,
173  sourceSchema=srcSchema, targetPrefix="src_")
174  for m, r in zip(matches, mergedCatalog):
175  r.set(distKey, m.distance)
176 
177  # obtain reference catalog name if one is setup
178  try:
179  catalogName = os.path.basename(getPackageDir("astrometry_net_data"))
181  catalogName = "NOT_SET"
182  matchMeta.add("REFCAT", catalogName)
183  mergedCatalog.getTable().setMetadata(matchMeta)
184 
185  return mergedCatalog
186 
187 
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:71
def makeMergedSchema(sourceSchema, targetSchema, sourcePrefix=None, targetPrefix=None)
def matchesToCatalog(matches, matchMeta)
std::string getPackageDir(std::string const &packageName)
return the root directory of a setup package
Definition: packaging.cc:33
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
def copyIntoCatalog(catalog, target, sourceSchema=None, sourcePrefix=None, targetPrefix=None)
def copyAliasMapWithPrefix(inSchema, outSchema, prefix="")