lsst.meas.astrom  14.0-7-g0d69b06+3
setMatchDistance.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
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 <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 from __future__ import absolute_import, division, print_function
23 
24 __all__ = ["setMatchDistance"]
25 
26 import lsst.afw.table as afwTable
27 
28 
29 def setMatchDistance(matches):
30  """Set the distance field of the matches in a match list to the distance in radians on the sky
31 
32  @warning the coord field of the source in each match must be correct
33 
34  @param[in,out] matches a list of matches, an instance of lsst.afw.table.ReferenceMatch
35  reads the coord field of the source and reference object of each match
36  writes the distance field of each match
37  """
38  if len(matches) < 1:
39  return
40 
41  sourceCoordKey = afwTable.CoordKey(matches[0].first.schema["coord"])
42  refObjCoordKey = afwTable.CoordKey(matches[0].second.schema["coord"])
43  for match in matches:
44  sourceCoord = match.first.get(sourceCoordKey)
45  refObjCoord = match.second.get(refObjCoordKey)
46  match.distance = refObjCoord.angularSeparation(sourceCoord).asRadians()