Skip to content

Commit

Permalink
Merge pull request #553 from lsst/tickets/DM-27800
Browse files Browse the repository at this point in the history
Add two new functions for matching and reindexing catalogs
  • Loading branch information
fred3m committed Jun 4, 2021
2 parents 68b03cc + b2cca1e commit ade869a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion python/lsst/afw/table/catalogMatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

__all__ = ["makeMergedSchema", "copyIntoCatalog",
"matchesToCatalog", "matchesFromCatalog", "copyAliasMapWithPrefix"]
"matchesToCatalog", "matchesFromCatalog", "copyAliasMapWithPrefix",
"reindexCatalog"]

import os.path

Expand Down Expand Up @@ -254,3 +255,26 @@ def copyAliasMapWithPrefix(inSchema, outSchema, prefix=""):
outSchema.getAliasMap().set(prefix + k, prefix + v)

return outSchema


def reindexCatalog(catalog, indices, deep=True):
"""Apply a numpy index array to an afw Catalog
Parameters
----------
catalog : `lsst.afw.table.SourceCatalog`
Catalog to reindex.
indices : `numpy.ndarray` of `int`
Index array.
deep : `bool`
Whether or not to make a deep copy of the original catalog.
Returns
-------
new : subclass of `lsst.afw.table.BaseCatalog`
Reindexed catalog. Records are shallow copies of those in ``catalog``.
"""
new = SourceCatalog(catalog.table.clone() if deep else catalog.table)
records = [catalog[int(ii)] for ii in indices]
new.extend(records, deep=deep)
return new

0 comments on commit ade869a

Please sign in to comment.