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