lsst.afw  14.0-35-g29d3a87a7
utils.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2016 AURA/LSST.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <https://www.lsstcorp.org/LegalNotices/>.
21 #
22 from __future__ import absolute_import, division, print_function
23 
24 from .aggregates import CoordKey, Point2DKey
25 
26 __all__ = ["updateRefCentroids", "updateSourceCoords"]
27 
28 
29 def updateRefCentroids(wcs, refList):
30  """Update centroids in a collection of reference objects
31 
32  This code supports any kind of collection, instead of requiring a catalog,
33  to make it easy to use with match lists. For example:
34 
35  updateRefCentroids(wcs, refList=[match.first for match in matches])
36 
37  @param[in] wcs WCS to map from sky to pixels; an lsst.afw.image.Wcs
38  @param[in,out] refList collection of reference objects (lsst.afw.table.SimpleRecords); for each:
39  - read field "coords", an lsst.afw.coord.Coord
40  - write field "centroid", an lsst.afw.geom.Point2D
41  """
42  if len(refList) < 1:
43  return
44  schema = refList[0].schema
45  coordKey = CoordKey(schema["coord"])
46  centroidKey = Point2DKey(schema["centroid"])
47  for refObj in refList:
48  refObj.set(centroidKey, wcs.skyToPixel(refObj.get(coordKey)))
49 
50 
51 def updateSourceCoords(wcs, sourceList):
52  """Update coords in a collection of sources
53 
54  This code supports any kind of collection, instead of requiring a catalog,
55  to make it easy to use with match lists. For example:
56 
57  updateSourceCoords(wcs, sourceList=[match.second for match in matches])
58 
59  @param[in] wcs WCS to map from pixels to sky; an lsst.afw.image.Wcs
60  @param[in,out] sourceList collection of sources (lsst.afw.table.SourceRecords); for each:
61  - read centroid using getCentroid()
62  - write field "coord", an lsst.afw.coord.Coord
63  """
64  if len(sourceList) < 1:
65  return
66  schema = sourceList[0].schema
67  srcCoordKey = CoordKey(schema["coord"])
68  for src in sourceList:
69  src.set(srcCoordKey, wcs.pixelToSky(src.getCentroid()))
PointKey< double > Point2DKey
Definition: aggregates.h:107
def updateSourceCoords(wcs, sourceList)
Definition: utils.py:51
def updateRefCentroids(wcs, refList)
Definition: utils.py:29