lsst.meas.astrom  14.0-7-g0d69b06+3
verifyWcs.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__ = ["checkMatches"]
25 
26 from builtins import range
27 
28 import numpy as np
29 
30 import lsst.afw.detection as afwDetection
31 import lsst.afw.geom as afwGeom
32 import lsst.afw.math as afwMath
33 import lsst.meas.algorithms as measAlg
34 from lsst.log import Log
35 
36 
37 def checkMatches(srcMatchSet, exposure, log=None):
38  if not exposure:
39  return {}
40 
41  if log is None:
42  log = Log.getLogger("meas.astrom.verifyWcs.checkMatches")
43 
44  im = exposure.getMaskedImage().getImage()
45  width, height = im.getWidth(), im.getHeight()
46  nx, ny = 3, 3
47  w, h = width//nx, height//ny
48 
49  if w == 0:
50  w = 1
51  while nx*w < width:
52  w += 1
53 
54  if h == 0:
55  h = 1
56  while ny*h < height:
57  h += 1
58 
59  cellSet = afwMath.SpatialCellSet(
60  afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(width, height)), w, h)
61  #
62  # Populate cellSet
63  #
64  i = -1
65  for m in srcMatchSet:
66  i += 1
67 
68  src = m.second
69  csrc = afwDetection.Source()
70  csrc.setId(i)
71  csrc.setXAstrom(src.getXAstrom())
72  csrc.setYAstrom(src.getYAstrom())
73 
74  try:
75  cellSet.insertCandidate(measAlg.PsfCandidateF(csrc, exposure.getMaskedImage()))
76  except Exception as e:
77  log.warn(str(e))
78 
79  ncell = len(cellSet.getCellList())
80  nobj = np.ndarray(ncell, dtype='i')
81 
82  for i in range(ncell):
83  cell = cellSet.getCellList()[i]
84 
85  nobj[i] = cell.size()
86 
87  dx = np.ndarray(cell.size())
88  dy = np.ndarray(cell.size())
89 
90  j = 0
91  for cand in cell:
92  #
93  # Swig doesn't know that we're a SpatialCellImageCandidate; all it knows is that we have
94  # a SpatialCellCandidate so we need an explicit (dynamic) cast
95  #
96  mid = cand.getSource().getId()
97  dx[j] = srcMatchSet[mid].first.getXAstrom() - srcMatchSet[mid].second.getXAstrom()
98  dy[j] = srcMatchSet[mid].first.getYAstrom() - srcMatchSet[mid].second.getYAstrom()
99 
100  j += 1
101 
102  log.debug("%s %-30s %8s dx,dy = %5.2f,%5.2f rms_x,y = %5.2f,%5.2f",
103  cell.getLabel(), cell.getBBox(), ("nobj=%d" % cell.size()),
104  dx.mean(), dy.mean(), dx.std(), dy.std())
105 
106  nobj.sort()
107 
108  values = {}
109  values["minObjectsPerCell"] = int(nobj[0]) # otherwise it's a numpy integral type
110  values["maxObjectsPerCell"] = int(nobj[-1])
111  values["meanObjectsPerCell"] = nobj.mean()
112  values["stdObjectsPerCell"] = nobj.std()
113 
114  return values
def checkMatches(srcMatchSet, exposure, log=None)
Definition: verifyWcs.py:37