LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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 from lsst.log import Log
31 
32 def checkMatches(srcMatchSet, exposure, log=None):
33  if not exposure:
34  return {}
35 
36  if log is None:
37  log = Log.getLogger("meas.astrom.verifyWcs.checkMatches")
38 
39  im = exposure.getMaskedImage().getImage()
40  width, height = im.getWidth(), im.getHeight()
41  nx, ny = 3, 3
42  w, h = width//nx, height//ny
43 
44  if w == 0:
45  w = 1
46  while nx*w < width:
47  w += 1
48 
49  if h == 0:
50  h = 1
51  while ny*h < height:
52  h += 1
53 
54  cellSet = afwMath.SpatialCellSet(
55  afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(width, height)), w, h)
56  #
57  # Populate cellSet
58  #
59  i = -1
60  for m in srcMatchSet:
61  i += 1
62 
63  src = m.second
64  csrc = afwDetection.Source()
65  csrc.setId(i)
66  csrc.setXAstrom(src.getXAstrom())
67  csrc.setYAstrom(src.getYAstrom())
68 
69  try:
70  cellSet.insertCandidate(measAlg.PsfCandidateF(csrc, exposure.getMaskedImage()))
71  except Exception as e:
72  log.warn(str(e))
73 
74  ncell = len(cellSet.getCellList())
75  nobj = np.ndarray(ncell, dtype='i')
76 
77  for i in range(ncell):
78  cell = cellSet.getCellList()[i]
79 
80  nobj[i] = cell.size()
81 
82  dx = np.ndarray(cell.size())
83  dy = np.ndarray(cell.size())
84 
85  j = 0
86  for cand in cell:
87  #
88  # Swig doesn't know that we're a SpatialCellImageCandidate; all it knows is that we have
89  # a SpatialCellCandidate so we need an explicit (dynamic) cast
90  #
91  cand = measAlg.cast_PsfCandidateF(cand)
92 
93  mid = cand.getSource().getId()
94  dx[j] = srcMatchSet[mid].first.getXAstrom() - srcMatchSet[mid].second.getXAstrom()
95  dy[j] = srcMatchSet[mid].first.getYAstrom() - srcMatchSet[mid].second.getYAstrom()
96 
97  j += 1
98 
99  log.debug("%s %-30s %8s dx,dy = %5.2f,%5.2f rms_x,y = %5.2f,%5.2f",
100  cell.getLabel(), cell.getBBox(), ("nobj=%d" % cell.size()),
101  dx.mean(), dy.mean(), dx.std(), dy.std())
102 
103  nobj.sort()
104 
105  values = {}
106  values["minObjectsPerCell"] = int(nobj[0]) # otherwise it's a numpy integral type
107  values["maxObjectsPerCell"] = int(nobj[-1])
108  values["meanObjectsPerCell"] = nobj.mean()
109  values["stdObjectsPerCell"] = nobj.std()
110 
111  return values
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations...
An integer coordinate rectangle.
Definition: Box.h:53
A collection of SpatialCells covering an entire image.
Definition: SpatialCell.h:304