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