LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
verifyWcs.py
Go to the documentation of this file.
1 from builtins import range
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 import numpy as np
25 
26 import lsst.afw.detection as afwDetection
27 import lsst.afw.geom as afwGeom
28 import lsst.afw.math as afwMath
29 import lsst.meas.algorithms as measAlg
30 
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 as e:
69  log.log(log.WARN, str(e))
70 
71  ncell = len(cellSet.getCellList())
72  nobj = np.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 = np.ndarray(cell.size())
80  dy = np.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  nobj.sort()
102 
103  values = {}
104  values["minObjectsPerCell"] = int(nobj[0]) # otherwise it's a numpy integral type
105  values["maxObjectsPerCell"] = int(nobj[-1])
106  values["meanObjectsPerCell"] = nobj.mean()
107  values["stdObjectsPerCell"] = nobj.std()
108 
109  return values
An integer coordinate rectangle.
Definition: Box.h:53
A collection of SpatialCells covering an entire image.
Definition: SpatialCell.h:378