LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
polygonContinued.py
Go to the documentation of this file.
1 __all__ = [] # import this module only for its side effects
2 
3 from lsst.utils import continueClass
4 from .polygon import Polygon
5 
6 
7 @continueClass # noqa F811
8 class Polygon:
9  def __repr__(self):
10  return "%s(%s)" % (self.__class__.__name__, [p for p in self.getVertices()])
11 
12  def __reduce__(self):
13  return self.__class__, (self.getVertices(),)
14 
15  def __iter__(self):
16  """Iterator over vertices"""
17  vertices = self.getVertices()
18  return iter(vertices)
19 
20  def __getitem__(self, i):
21  return [pt for pt in self][i]
22 
23  def __len__(self):
24  return self.getNumEdges()
25 
26  def __contains__(self, point):
27  """point in polygon?"""
28  return self.contains(point)
29 
30  def display(self, xy0=None, frame=1, ctype=None):
31  """Display polygon on existing frame in ds9"""
32  import lsst.geom
33  import lsst.afw.display.ds9 as ds9
34  xy0 = lsst.geom.Extent2D(0, 0) if xy0 is None else lsst.geom.Extent2D(xy0)
35  with ds9.Buffering():
36  for p1, p2 in self.getEdges():
37  ds9.line((p1 - xy0, p2 - xy0), frame=frame, ctype=ctype)
38 
39  def plot(self, axes=None, **kwargs):
40  """Plot polygon with matplotlib
41 
42  Parameters
43  ----------
44  axes : `matplotlib.axes.Axes`
45  Matplotlib axes to use, or None
46  kwargs : any
47  Additional arguments to `matplotlib.axes.Axes.plot`
48  or `matplotlib.axes.Axes.scatter`.
49 
50  Returns
51  -------
52  axes : `matplotlib.axes.Axes`
53  The axes used to make the plot (same as ``axes``, if provided).
54  """
55  import numpy
56  if axes is None:
57  import matplotlib.pyplot as plt
58  plt.figure()
59  axes = plt.axes()
60  for p1, p2 in self.getEdges():
61  x = (p1.getX(), p2.getX())
62  y = (p1.getY(), p2.getY())
63  axes.plot(x, y, **kwargs)
64  vertices = self.getVertices()
65  x = numpy.array([p[0] for p in vertices])
66  y = numpy.array([p[1] for p in vertices])
67  axes.scatter(x, y, **kwargs)
68  return axes
def plot(mag, width, centers, clusterId, marker="o", markersize=2, markeredgewidth=0, ltype='-', magType="model", clear=True)
Cartesian polygons.
Definition: Polygon.h:58