lsst.afw  14.0-25-g0e8fc950e+6
__init__.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 """lsst.afw.geom.ellipses
24 """
25 from __future__ import absolute_import
26 from .ellipsesLib import *
27 
28 Separable = {
29  (Distortion, DeterminantRadius): SeparableDistortionDeterminantRadius,
30  (Distortion, TraceRadius): SeparableDistortionTraceRadius,
31  (Distortion, LogDeterminantRadius): SeparableDistortionLogDeterminantRadius,
32  (Distortion, LogTraceRadius): SeparableDistortionLogTraceRadius,
33  (ConformalShear, DeterminantRadius): SeparableConformalShearDeterminantRadius,
34  (ConformalShear, TraceRadius): SeparableConformalShearTraceRadius,
35  (ConformalShear, LogDeterminantRadius): SeparableConformalShearLogDeterminantRadius,
36  (ConformalShear, LogTraceRadius): SeparableConformalShearLogTraceRadius
37 }
38 
39 
41  """An interface for drawing the ellipse using matplotlib.
42 
43  This is typically initiated by calling Ellipse.plot(), which
44  adds the interface as the matplotlib attribute of the ellipse
45  object (this can be deleted later if desired).
46  """
47 
48  def __init__(self, ellipse, scale=1.0, **kwds):
49  import matplotlib.patches
50  self.__ellipse = weakref.proxy(ellipse)
51  self.scale = float(scale)
52  core = Axes(self.__ellipse.getCore())
53  core.scale(2.0 * scale)
54  self.patch = matplotlib.patches.Ellipse(
55  (self.__ellipse.getCenter().getX(), self.__ellipse.getCenter().getY()),
56  core.getA(), core.getB(), core.getTheta() * 180.0 / numpy.pi,
57  **kwds
58  )
59 
60  def __getattr__(self, name):
61  return getattr(self.patch, name)
62 
63  def update(self, show=True, rescale=True):
64  """Update the matplotlib representation to the current ellipse parameters.
65  """
66  import matplotlib.patches
67  core = _agl.Axes(self.__ellipse.getCore())
68  core.scale(2.0 * scale)
69  new_patch = matplotlib.patches.Ellipse(
70  (self.__ellipse.getCenter().getX(), self.__ellipse.getCenter().getY()),
71  core.a, core.b, core.theta * 180.0 / numpy.pi
72  )
73  new_patch.update_from(self.patch)
74  axes = self.patch.get_axes()
75  if axes is not None:
76  self.patch.remove()
77  axes.add_patch(new_patch)
78  self.patch = new_patch
79  if axes is not None:
80  if rescale:
81  axes.autoscale_view()
82  if show:
83  axes.figure.canvas.draw()
84 
85 
86 def Ellipse_plot(self, axes=None, scale=1.0, show=True, rescale=True, **kwds):
87  """Plot the ellipse in matplotlib, adding a MatplotlibInterface
88  object as the 'matplotlib' attribute of the ellipse.
89 
90  Aside from those below, keyword arguments for the
91  matplotlib.patches.Patch constructor are also accepted
92  ('facecolor', 'linestyle', etc.)
93 
94  Arguments:
95  axes -------- A matplotlib.axes.Axes object, or None to use
96  matplotlib.pyplot.gca().
97  scale ------- Scale the displayed ellipse by this factor.
98  show -------- If True, update the figure automatically. Set
99  to False for batch processing.
100  rescale ----- If True, rescale the axes.
101  """
102  import matplotlib.pyplot
103  self.matplotlib = self.MatplotlibInterface(self, scale, **kwds)
104  if axes is None:
105  axes = matplotlib.pyplot.gca()
106  axes.add_patch(self.matplotlib.patch)
107  if rescale:
108  axes.autoscale_view()
109  if show:
110  axes.figure.canvas.draw()
111  return self.matplotlib.patch
112 
113 
114 # Ellipse.MatplotlibInterface = EllipseMatplotlibInterface
115 # Ellipse.plot = Ellipse_plot
def Ellipse_plot(self, axes=None, scale=1.0, show=True, rescale=True, kwds)
Definition: __init__.py:86
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a...
Definition: Axes.h:47
def __init__(self, ellipse, scale=1.0, kwds)
Definition: __init__.py:48
def update(self, show=True, rescale=True)
Definition: __init__.py:63