LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
Functions
lsst.meas.astrom.display Namespace Reference

Functions

def displayAstrometry (refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
 
def plotAstrometry (matches, refCat=None, sourceCat=None, refMarker="x", refColor="r", sourceMarker="+", sourceColor="g", matchColor="y")
 

Function Documentation

◆ displayAstrometry()

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.

Parameters
----------
refCat : `lsst.afw.table.SimpleCatalog`
    reference object catalog; must have fields "centroid_x" an
    "centroid_y"
sourceCat : `lsst.afw.table.SourceCatalg`
    source catalog; must have field "slot_Centroid_x" and "slot_Centroid_y"
distortedCentroidKey : `lsst.afw.table.Key`
    key for sourceCat with field to use for distorted positions
exposure : `lsst.afw.image.Exposure`
    exposure to display
bbox : `lsst.geom.Box2I`
    bounding box of exposure; Used if the exposure is `None`
matches : `list` of `lsst.afw.table.ReferenceMatch`
    List of matched objects
frame : `int`
    frame number for display
title : `str`
    title for display
pause : `bool`
    pause for inspection of display? This is done by dropping into pdb.

Notes
-----

- 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

Definition at line 33 of file display.py.

33 def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None,
34  matches=None, frame=1, title="", pause=True):
35  """Show an astrometry debug image.
36 
37  Parameters
38  ----------
39  refCat : `lsst.afw.table.SimpleCatalog`
40  reference object catalog; must have fields "centroid_x" an
41  "centroid_y"
42  sourceCat : `lsst.afw.table.SourceCatalg`
43  source catalog; must have field "slot_Centroid_x" and "slot_Centroid_y"
44  distortedCentroidKey : `lsst.afw.table.Key`
45  key for sourceCat with field to use for distorted positions
46  exposure : `lsst.afw.image.Exposure`
47  exposure to display
48  bbox : `lsst.geom.Box2I`
49  bounding box of exposure; Used if the exposure is `None`
50  matches : `list` of `lsst.afw.table.ReferenceMatch`
51  List of matched objects
52  frame : `int`
53  frame number for display
54  title : `str`
55  title for display
56  pause : `bool`
57  pause for inspection of display? This is done by dropping into pdb.
58 
59  Notes
60  -----
61 
62  - reference objects in refCat are shown as red X
63  - sources in sourceCat are shown as green +
64  - distorted sources in sourceCat (position given by distortedCentroidKey)
65  are shown as green o
66  - matches are shown as a yellow circle around the source and a yellow line
67  connecting the reference object and source
68  - if both exposure and bbox are `None`, no image is displayed
69 
70  """
71  disp = afwDisplay.getDisplay(frame=frame)
72 
73  if exposure is not None:
74  disp.mtv(exposure, title=title)
75  elif bbox is not None:
76  disp.mtv(exposure=ExposureF(bbox), title=title)
77 
78  with disp.Buffering():
79  if refCat is not None:
80  refCentroidKey = Point2DKey(refCat.schema["centroid"])
81  for refObj in refCat:
82  rx, ry = refObj.get(refCentroidKey)
83  disp.dot("x", rx, ry, size=10, ctype=afwDisplay.RED)
84 
85  if sourceCat is not None:
86  sourceCentroidKey = Point2DKey(sourceCat.schema["slot_Centroid"])
87  for source in sourceCat:
88  sx, sy = source.get(sourceCentroidKey)
89  disp.dot("+", sx, sy, size=10, ctype=afwDisplay.GREEN)
90  if distortedCentroidKey is not None:
91  dx, dy = source.get(distortedCentroidKey)
92  disp.dot("o", dx, dy, size=10, ctype=afwDisplay.GREEN)
93  disp.line([(sx, sy), (dx, dy)], ctype=afwDisplay.GREEN)
94 
95  if matches is not None:
96  refCentroidKey = Point2DKey(matches[0].first.schema["centroid"])
97  sourceCentroidKey = Point2DKey(matches[0].second.schema["slot_Centroid"])
98  radArr = np.ndarray(len(matches))
99 
100  for i, m in enumerate(matches):
101  refCentroid = m.first.get(refCentroidKey)
102  sourceCentroid = m.second.get(sourceCentroidKey)
103  radArr[i] = math.hypot(*(refCentroid - sourceCentroid))
104  sx, sy = sourceCentroid
105  disp.dot("o", sx, sy, size=10, ctype=afwDisplay.YELLOW)
106  disp.line([refCentroid, sourceCentroid], ctype=afwDisplay.YELLOW)
107 
108  print("<match radius> = %.4g +- %.4g [%d matches]" %
109  (radArr.mean(), radArr.std(), len(matches)))
110 
111  if pause:
112  print("Dropping into debugger to allow inspection of display. Type 'continue' when done.")
113  import pdb
114  pdb.set_trace()
115 
116 

◆ plotAstrometry()

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

Parameters
----------
matches : `list` of `lsst.afw.table.ReferenceMatch`
    list of matches
refCat : `lsst.afw.table.SimpleCatalog`
    reference object catalog, or None to not plot reference objects
sourceCat : `lsst.afw.table.SourceCatalog`
    source catalog, or None to not plot sources
refMarker : `str`
    pyplot marker for reference objects
refColor : `str`
    pyplot color for reference objects
sourceMarker : `str`
    pyplot marker for sources
sourceColor : `str`
    pyplot color for sources
matchColor : `str`
    color for matches; can be a constant
    or a function taking one match and returning a string

Notes
-----
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

Definition at line 117 of file display.py.

117 def plotAstrometry(
118  matches,
119  refCat=None,
120  sourceCat=None,
121  refMarker="x",
122  refColor="r",
123  sourceMarker="+",
124  sourceColor="g",
125  matchColor="y"
126 ):
127  """Plot reference objects, sources and matches
128 
129  Parameters
130  ----------
131  matches : `list` of `lsst.afw.table.ReferenceMatch`
132  list of matches
133  refCat : `lsst.afw.table.SimpleCatalog`
134  reference object catalog, or None to not plot reference objects
135  sourceCat : `lsst.afw.table.SourceCatalog`
136  source catalog, or None to not plot sources
137  refMarker : `str`
138  pyplot marker for reference objects
139  refColor : `str`
140  pyplot color for reference objects
141  sourceMarker : `str`
142  pyplot marker for sources
143  sourceColor : `str`
144  pyplot color for sources
145  matchColor : `str`
146  color for matches; can be a constant
147  or a function taking one match and returning a string
148 
149  Notes
150  -----
151  By default:
152 
153  - reference objects in refCat are shown as red X
154  - sources in sourceCat are shown as green +
155  - matches are shown as a yellow circle around the source and a line
156  connecting the reference object to the source
157  """
158  # delay importing plt to give users a chance to set the backend before calling this function
159  import matplotlib.pyplot as plt
160  refSchema = matches[0][0].schema
161  refCentroidKey = Point2DKey(refSchema["centroid"])
162  srcSchema = matches[0][1].schema
163  srcCentroidKey = Point2DKey(srcSchema["slot_Centroid"])
164 
165  if refCat is not None:
166  refXArr, refYArr = list(zip(*[ref.get(refCentroidKey) for ref in refCat]))
167  plt.plot(refXArr, refYArr, marker=refMarker, color=refColor, linestyle="")
168 
169  if sourceCat is not None:
170  srcXArr, srcYArr = list(zip(*[src.get(srcCentroidKey) for src in sourceCat]))
171  plt.plot(srcXArr, srcYArr, marker=sourceMarker, color=sourceColor, linestyle="")
172 
173  def makeLineSegmentData(refXYArr, srcXYArr, colorArr):
174  """Make a list of line segement data
175 
176  This is used to draw line segements between ref and src positions in the specified color
177 
178  Notes
179  -----
180  The returned data has the format:
181  [(refX0, srcX0), (refY0, srcY0), color0, (refX1, srcX1), (refY1, srcY1), color1,...]
182  """
183  if len(refXYArr) != len(srcXYArr):
184  raise RuntimeError("len(refXYArr) = %d != %d = len(srcXYArr)" %
185  (len(refXYArr), len(srcXYArr)))
186  if len(refXYArr) != len(colorArr):
187  raise RuntimeError("len(refXYArr) = %d != %d = len(colorArr)" %
188  (len(refXYArr), len(colorArr)))
189 
190  refXArr, refYArr = list(zip(*refXYArr))
191  srcXArr, srcYArr = list(zip(*srcXYArr))
192  refSrcXArr = list(zip(refXArr, srcXArr))
193  refSrcYArr = list(zip(refYArr, srcYArr))
194  dataList = []
195  for xycolor in zip(refSrcXArr, refSrcYArr, colorArr):
196  for val in xycolor:
197  dataList.append(val)
198  return dataList
199 
200  refXYArr, srcXYArr = \
201  list(zip(*[(match[0].get(refCentroidKey), match[1].get(srcCentroidKey)) for match in matches]))
202 
203  def plotSourceCircles(matches, color):
204  srcXYArr = [match[1].get(srcCentroidKey) for match in matches]
205  srcXArr, srcYArr = list(zip(*srcXYArr))
206  plt.plot(srcXArr, srcYArr, "o", mec=color, mfc="none", ms=10,)
207 
208  if callable(matchColor):
209  # different matches have different colors
210  matchColorArr = [matchColor(match) for match in matches]
211 
212  # plot circles for each color separately
213  matchColorSet = set(matchColorArr)
214  for color in matchColorSet:
215  subMatches = [match for match in matches if matchColor(match) == color]
216  plotSourceCircles(subMatches, color=color)
217  else:
218  matchColorArr = [matchColor]*len(refXYArr)
219  plotSourceCircles(matches, color=matchColor)
220 
221  lineSegData = makeLineSegmentData(refXYArr, srcXYArr, matchColorArr)
222  plt.plot(*lineSegData)
223 
224  plt.show()
lsst::afw::table::Point2DKey
PointKey< double > Point2DKey
Definition: aggregates.h:118
list
daf::base::PropertyList * list
Definition: fits.cc:913
lsst::meas::astrom.display.plotAstrometry
def plotAstrometry(matches, refCat=None, sourceCat=None, refMarker="x", refColor="r", sourceMarker="+", sourceColor="g", matchColor="y")
Definition: display.py:117
lsst::meas::astrom.display.displayAstrometry
def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
Definition: display.py:33
set
daf::base::PropertySet * set
Definition: fits.cc:912