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