LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Functions | Variables
lsst.meas.astrom.display Namespace Reference

Functions

def displayAstrometry
 
def plotAstrometry
 

Variables

list __all__ = ["displayAstrometry", "plotAstrometry"]
 

Function Documentation

def lsst.meas.astrom.display.displayAstrometry (   refCat = None,
  sourceCat = None,
  distortedCentroidKey = None,
  bbox = None,
  exposure = None,
  matches = None,
  frame = 1,
  title = "",
  pause = True 
)
Show an astrometry debug image

- reference objects in refCat are shown as red X
- sources in sourceCat are shown as green +
- distorted sources in sourceCat (position given by distortedCentroidKey) are shown as green o
- matches are shown as a yellow circle around the source and a yellow line
    connecting the reference object and source
- if both exposure and bbox are None, no image is displayed

@param[in] refCat  reference object catalog; must have fields "centroid_x" and "centroid_y"
@param[in] sourceCat  source catalog; must have field "slot_Centroid_x" and "slot_Centroid_y"
@param[in] distortedCentroidKey  key for sourceCat with field to use for distorted positions, or None
@param[in] exposure  exposure to display, or None for a blank exposure
@param[in] bbox  bounding box of exposure; used if exposure is None for a blank image
@param[in] matches  list of matches (an lsst.afw.table.ReferenceMatchVector), or None
@param[in] frame  frame number for ds9 display
@param[in] title  title for ds9 display
@param[in] pause  pause for inspection of display? This is done by dropping into pdb.

Definition at line 13 of file display.py.

13 
14  matches=None, frame=1, title="", pause=True):
15  """Show an astrometry debug image
16 
17  - reference objects in refCat are shown as red X
18  - sources in sourceCat are shown as green +
19  - distorted sources in sourceCat (position given by distortedCentroidKey) are shown as green o
20  - matches are shown as a yellow circle around the source and a yellow line
21  connecting the reference object and source
22  - if both exposure and bbox are None, no image is displayed
23 
24  @param[in] refCat reference object catalog; must have fields "centroid_x" and "centroid_y"
25  @param[in] sourceCat source catalog; must have field "slot_Centroid_x" and "slot_Centroid_y"
26  @param[in] distortedCentroidKey key for sourceCat with field to use for distorted positions, or None
27  @param[in] exposure exposure to display, or None for a blank exposure
28  @param[in] bbox bounding box of exposure; used if exposure is None for a blank image
29  @param[in] matches list of matches (an lsst.afw.table.ReferenceMatchVector), or None
30  @param[in] frame frame number for ds9 display
31  @param[in] title title for ds9 display
32  @param[in] pause pause for inspection of display? This is done by dropping into pdb.
33  """
34  import lsst.afw.display.ds9 as ds9
35 
36  if exposure is not None:
37  ds9.mtv(exposure, frame=frame, title=title)
38  elif bbox is not None:
39  ds9.mtv(exposure=ExposureF(bbox), frame=frame, title=title)
40 
41  with ds9.Buffering():
42  if refCat is not None:
43  refCentroidKey = Point2DKey(refCat.schema["centroid"])
44  for refObj in refCat:
45  rx, ry = refObj.get(refCentroidKey)
46  ds9.dot("x", rx, ry, size=10, frame=frame, ctype=ds9.RED)
47 
48  if sourceCat is not None:
49  sourceCentroidKey = Point2DKey(sourceCat.schema["slot_Centroid"])
50  for source in sourceCat:
51  sx, sy = source.get(sourceCentroidKey)
52  ds9.dot("+", sx, sy, size=10, frame=frame, ctype=ds9.GREEN)
53  if distortedCentroidKey is not None:
54  dx, dy = source.get(distortedCentroidKey)
55  ds9.dot("o", dx, dy, size=10, frame=frame, ctype=ds9.GREEN)
56  ds9.line([(sx, sy), (dx, dy)], ctype=ds9.GREEN, frame=frame)
57 
58  if matches is not None:
59  refCentroidKey = Point2DKey(matches[0].first.schema["centroid"])
60  sourceCentroidKey = Point2DKey(matches[0].second.schema["slot_Centroid"])
61  radArr = np.ndarray(len(matches))
62 
63  for i, m in enumerate(matches):
64  refCentroid = m.first.get(refCentroidKey)
65  sourceCentroid = m.second.get(sourceCentroidKey)
66  radArr[i] = math.hypot(*(refCentroid - sourceCentroid))
67  sx, sy = sourceCentroid
68  ds9.dot("o", sx, sy, size=10, frame=frame, ctype=ds9.YELLOW)
69  ds9.line([refCentroid, sourceCentroid], ctype=ds9.YELLOW)
70 
71  print("<match radius> = %.4g +- %.4g [%d matches]" %
72  (radArr.mean(), radArr.std(), len(matches)))
73 
74  if pause:
75  print("Dropping into debugger to allow inspection of display. Type 'continue' when done.")
76  import pdb;pdb.set_trace()
PointKey< double > Point2DKey
Definition: aggregates.h:111
def lsst.meas.astrom.display.plotAstrometry (   matches,
  refCat = None,
  sourceCat = None,
  refMarker = "x",
  refColor = "r",
  sourceMarker = "+",
  sourceColor = "g",
  matchColor = "y" 
)
Plot reference objects, sources and matches

By default:
- reference objects in refCat are shown as red X
- sources in sourceCat are shown as green +
- matches are shown as a yellow circle around the source and a line
    connecting the reference object to the source

@param[in] matches  list of matches
@param[in] refCat  reference object catalog, or None to not plot reference objects
@param[in] sourceCat  source catalog, or None to not plot sources
@param[in] refMarker  pyplot marker for reference objects
@param[in] refColor  pyplot color for reference objects
@param[in] sourceMarker  pyplot marker for sources
@param[in] sourceColor  pyplot color for sources
@param[in] matchColor  color for matches; can be a constant
    or a function taking one match and returning a string

Definition at line 85 of file display.py.

85 
86  matchColor="y"):
87  """Plot reference objects, sources and matches
88 
89  By default:
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
94 
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
104  """
105  # delay importing plt to give users a chance to set the backend before calling this function
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"])
111 
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="")
115 
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="")
119 
120  def makeLineSegmentData(refXYArr, srcXYArr, colorArr):
121  """Make a list of line segement data
122 
123  This is used to draw line segements between ref and src positions in the specified color
124 
125  The returned data has the format:
126  [(refX0, srcX0), (refY0, srcY0), color0, (refX1, srcX1), (refY1, srcY1), color1,...]
127  """
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)))
134 
135  refXArr, refYArr = zip(*refXYArr)
136  srcXArr, srcYArr = zip(*srcXYArr)
137  refSrcXArr = zip(refXArr, srcXArr)
138  refSrcYArr = zip(refYArr, srcYArr)
139  dataList = []
140  for xycolor in zip(refSrcXArr, refSrcYArr, colorArr):
141  for val in xycolor:
142  dataList.append(val)
143  return dataList
144 
145  refXYArr, srcXYArr = \
146  zip(*[(match[0].get(refCentroidKey), match[1].get(srcCentroidKey)) for match in matches])
147 
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,)
152 
153  if callable(matchColor):
154  # different matches have different colors
155  matchColorArr = [matchColor(match) for match in matches]
156 
157  # plot circles for each color separately
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)
162  else:
163  matchColorArr = [matchColor]*len(refXYArr)
164  plotSourceCircles(matches, color=matchColor)
165 
166  lineSegData = makeLineSegmentData(refXYArr, srcXYArr, matchColorArr)
167  plt.plot(*lineSegData)
168 
169  plt.show()
PointKey< double > Point2DKey
Definition: aggregates.h:111

Variable Documentation

list lsst.meas.astrom.display.__all__ = ["displayAstrometry", "plotAstrometry"]

Definition at line 10 of file display.py.