23 __all__ = [
"displayAstrometry",
"plotAstrometry"]
34 def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None,
35 matches=None, frame=1, title="", pause=True):
36 """Show an astrometry debug image. 40 refCat : `lsst.afw.table.SimpleCatalog` 41 reference object catalog; must have fields "centroid_x" an 43 sourceCat : `lsst.afw.table.SourceCatalg` 44 source catalog; must have field "slot_Centroid_x" and "slot_Centroid_y" 45 distortedCentroidKey : `lsst.afw.table.Key` 46 key for sourceCat with field to use for distorted positions 47 exposure : `lsst.afw.image.Exposure` 49 bbox : `lsst.geom.Box2I` 50 bounding box of exposure; Used if the exposure is `None` 51 matches : `list` of `lsst.afw.table.ReferenceMatch` 52 List of matched objects 54 frame number for ds9 display 58 pause for inspection of display? This is done by dropping into pdb. 63 - reference objects in refCat are shown as red X 64 - sources in sourceCat are shown as green + 65 - distorted sources in sourceCat (position given by distortedCentroidKey) 67 - matches are shown as a yellow circle around the source and a yellow line 68 connecting the reference object and source 69 - if both exposure and bbox are `None`, no image is displayed 72 disp = afwDisplay.getDisplay(frame)
74 if exposure
is not None:
75 disp.mtv(exposure, title=title)
76 elif bbox
is not None:
77 disp.mtv(exposure=ExposureF(bbox), title=title)
79 with disp.Buffering():
80 if refCat
is not None:
81 refCentroidKey =
Point2DKey(refCat.schema[
"centroid"])
83 rx, ry = refObj.get(refCentroidKey)
84 disp.dot(
"x", rx, ry, size=10, ctype=afwDisplay.RED)
86 if sourceCat
is not None:
87 sourceCentroidKey =
Point2DKey(sourceCat.schema[
"slot_Centroid"])
88 for source
in sourceCat:
89 sx, sy = source.get(sourceCentroidKey)
90 disp.dot(
"+", sx, sy, size=10, ctype=afwDisplay.GREEN)
91 if distortedCentroidKey
is not None:
92 dx, dy = source.get(distortedCentroidKey)
93 disp.dot(
"o", dx, dy, size=10, ctype=afwDisplay.GREEN)
94 disp.line([(sx, sy), (dx, dy)], ctype=afwDisplay.GREEN)
96 if matches
is not None:
97 refCentroidKey =
Point2DKey(matches[0].first.schema[
"centroid"])
98 sourceCentroidKey =
Point2DKey(matches[0].second.schema[
"slot_Centroid"])
99 radArr = np.ndarray(len(matches))
101 for i, m
in enumerate(matches):
102 refCentroid = m.first.get(refCentroidKey)
103 sourceCentroid = m.second.get(sourceCentroidKey)
104 radArr[i] = math.hypot(*(refCentroid - sourceCentroid))
105 sx, sy = sourceCentroid
106 disp.dot(
"o", sx, sy, size=10, ctype=afwDisplay.YELLOW)
107 disp.line([refCentroid, sourceCentroid], ctype=afwDisplay.YELLOW)
109 print(
"<match radius> = %.4g +- %.4g [%d matches]" %
110 (radArr.mean(), radArr.std(), len(matches)))
113 print(
"Dropping into debugger to allow inspection of display. Type 'continue' when done.")
128 """Plot reference objects, sources and matches 132 matches : `list` of `lsst.afw.table.ReferenceMatch` 134 refCat : `lsst.afw.table.SimpleCatalog` 135 reference object catalog, or None to not plot reference objects 136 sourceCat : `lsst.afw.table.SourceCatalog` 137 source catalog, or None to not plot sources 139 pyplot marker for reference objects 141 pyplot color for reference objects 143 pyplot marker for sources 145 pyplot color for sources 147 color for matches; can be a constant 148 or a function taking one match and returning a string 154 - reference objects in refCat are shown as red X 155 - sources in sourceCat are shown as green + 156 - matches are shown as a yellow circle around the source and a line 157 connecting the reference object to the source 160 import matplotlib.pyplot
as plt
161 refSchema = matches[0][0].schema
162 refCentroidKey =
Point2DKey(refSchema[
"centroid"])
163 srcSchema = matches[0][1].schema
164 srcCentroidKey =
Point2DKey(srcSchema[
"slot_Centroid"])
166 if refCat
is not None:
167 refXArr, refYArr =
list(zip(*[ref.get(refCentroidKey)
for ref
in refCat]))
168 plt.plot(refXArr, refYArr, marker=refMarker, color=refColor, linestyle=
"")
170 if sourceCat
is not None:
171 srcXArr, srcYArr =
list(zip(*[src.get(srcCentroidKey)
for src
in sourceCat]))
172 plt.plot(srcXArr, srcYArr, marker=sourceMarker, color=sourceColor, linestyle=
"")
174 def makeLineSegmentData(refXYArr, srcXYArr, colorArr):
175 """Make a list of line segement data 177 This is used to draw line segements between ref and src positions in the specified color 181 The returned data has the format: 182 [(refX0, srcX0), (refY0, srcY0), color0, (refX1, srcX1), (refY1, srcY1), color1,...] 184 if len(refXYArr) != len(srcXYArr):
185 raise RuntimeError(
"len(refXYArr) = %d != %d = len(srcXYArr)" %
186 (len(refXYArr), len(srcXYArr)))
187 if len(refXYArr) != len(colorArr):
188 raise RuntimeError(
"len(refXYArr) = %d != %d = len(colorArr)" %
189 (len(refXYArr), len(colorArr)))
191 refXArr, refYArr =
list(zip(*refXYArr))
192 srcXArr, srcYArr =
list(zip(*srcXYArr))
193 refSrcXArr =
list(zip(refXArr, srcXArr))
194 refSrcYArr =
list(zip(refYArr, srcYArr))
196 for xycolor
in zip(refSrcXArr, refSrcYArr, colorArr):
201 refXYArr, srcXYArr = \
202 list(zip(*[(match[0].get(refCentroidKey), match[1].get(srcCentroidKey))
for match
in matches]))
204 def plotSourceCircles(matches, color):
205 srcXYArr = [match[1].get(srcCentroidKey)
for match
in matches]
206 srcXArr, srcYArr =
list(zip(*srcXYArr))
207 plt.plot(srcXArr, srcYArr,
"o", mec=color, mfc=
"none", ms=10,)
209 if callable(matchColor):
211 matchColorArr = [matchColor(match)
for match
in matches]
214 matchColorSet =
set(matchColorArr)
215 for color
in matchColorSet:
216 subMatches = [match
for match
in matches
if matchColor(match) == color]
217 plotSourceCircles(subMatches, color=color)
219 matchColorArr = [matchColor]*len(refXYArr)
220 plotSourceCircles(matches, color=matchColor)
222 lineSegData = makeLineSegmentData(refXYArr, srcXYArr, matchColorArr)
223 plt.plot(*lineSegData)
def plotAstrometry(matches, refCat=None, sourceCat=None, refMarker="x", refColor="r", sourceMarker="+", sourceColor="g", matchColor="y")
PointKey< double > Point2DKey
daf::base::PropertySet * set
def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
daf::base::PropertyList * list