87 """Plot reference objects, sources and matches
90 - reference objects in refCat are shown as red X
91 - sources in sourceCat are shown as green +
92 - matches are shown as a yellow circle around the source and a line
93 connecting the reference object to the source
95 @param[in] matches list of matches
96 @param[in] refCat reference object catalog, or None to not plot reference objects
97 @param[in] sourceCat source catalog, or None to not plot sources
98 @param[in] refMarker pyplot marker for reference objects
99 @param[in] refColor pyplot color for reference objects
100 @param[in] sourceMarker pyplot marker for sources
101 @param[in] sourceColor pyplot color for sources
102 @param[in] matchColor color for matches; can be a constant
103 or a function taking one match and returning a string
106 import matplotlib.pyplot
as plt
107 refSchema = matches[0][0].schema
108 refCentroidKey =
Point2DKey(refSchema[
"centroid"])
109 srcSchema = matches[0][1].schema
110 srcCentroidKey =
Point2DKey(srcSchema[
"slot_Centroid"])
112 if refCat
is not None:
113 refXArr, refYArr = zip(*[ref.get(refCentroidKey)
for ref
in refCat])
114 plt.plot(refXArr, refYArr, marker=refMarker, color=refColor, linestyle=
"")
116 if sourceCat
is not None:
117 srcXArr, srcYArr = zip(*[src.get(srcCentroidKey)
for src
in sourceCat])
118 plt.plot(srcXArr, srcYArr, marker=sourceMarker, color=sourceColor, linestyle=
"")
120 def makeLineSegmentData(refXYArr, srcXYArr, colorArr):
121 """Make a list of line segement data
123 This is used to draw line segements between ref and src positions in the specified color
125 The returned data has the format:
126 [(refX0, srcX0), (refY0, srcY0), color0, (refX1, srcX1), (refY1, srcY1), color1,...]
128 if len(refXYArr) != len(srcXYArr):
129 raise RuntimeError(
"len(refXYArr) = %d != %d = len(srcXYArr)" %
130 (len(refXYArr), len(srcXYArr)))
131 if len(refXYArr) != len(colorArr):
132 raise RuntimeError(
"len(refXYArr) = %d != %d = len(colorArr)" %
133 (len(refXYArr), len(colorArr)))
135 refXArr, refYArr = zip(*refXYArr)
136 srcXArr, srcYArr = zip(*srcXYArr)
137 refSrcXArr = zip(refXArr, srcXArr)
138 refSrcYArr = zip(refYArr, srcYArr)
140 for xycolor
in zip(refSrcXArr, refSrcYArr, colorArr):
145 refXYArr, srcXYArr = \
146 zip(*[(match[0].get(refCentroidKey), match[1].get(srcCentroidKey))
for match
in matches])
148 def plotSourceCircles(matches, color):
149 srcXYArr = [match[1].get(srcCentroidKey)
for match
in matches]
150 srcXArr, srcYArr = zip(*srcXYArr)
151 plt.plot(srcXArr, srcYArr,
"o", mec=color, mfc=
"none", ms=10,)
153 if callable(matchColor):
155 matchColorArr = [matchColor(match)
for match
in matches]
158 matchColorSet = set(matchColorArr)
159 for color
in matchColorSet:
160 subMatches = [match
for match
in matches
if matchColor(match) == color]
161 plotSourceCircles(subMatches, color=color)
163 matchColorArr = [matchColor]*len(refXYArr)
164 plotSourceCircles(matches, color=matchColor)
166 lineSegData = makeLineSegmentData(refXYArr, srcXYArr, matchColorArr)
167 plt.plot(*lineSegData)
PointKey< double > Point2DKey