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
__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 ellipsesLib import *
26 import weakref
27 import numpy
28 
29 Separable = {
30  (Distortion, DeterminantRadius):SeparableDistortionDeterminantRadius,
31  (Distortion, TraceRadius):SeparableDistortionTraceRadius,
32  (Distortion, LogDeterminantRadius):SeparableDistortionLogDeterminantRadius,
33  (Distortion, LogTraceRadius):SeparableDistortionLogTraceRadius,
34  (ConformalShear, DeterminantRadius):SeparableConformalShearDeterminantRadius,
35  (ConformalShear, TraceRadius):SeparableConformalShearTraceRadius,
36  (ConformalShear, LogDeterminantRadius):SeparableConformalShearLogDeterminantRadius,
37  (ConformalShear, LogTraceRadius):SeparableConformalShearLogTraceRadius
38 }
39 
40 BaseCore.cast = lambda self: globals()[self.getName()].cast(self)
41 
43  """An interface for drawing the ellipse using matplotlib.
44 
45  This is typically initiated by calling Ellipse.plot(), which
46  adds the interface as the matplotlib attribute of the ellipse
47  object (this can be deleted later if desired).
48  """
49 
50  def __init__(self, ellipse, scale=1.0, **kwds):
51  import matplotlib.patches
52  self.__ellipse = weakref.proxy(ellipse)
53  self.scale = float(scale)
54  core = Axes(self.__ellipse.getCore())
55  core.scale(2.0 * scale)
56  self.patch = matplotlib.patches.Ellipse(
57  (self.__ellipse.getCenter().getX(), self.__ellipse.getCenter().getY()),
58  core.getA(), core.getB(), core.getTheta() * 180.0 / numpy.pi,
59  **kwds
60  )
61 
62  def __getattr__(self, name):
63  return getattr(self.patch, name)
64 
65  def update(self, show=True, rescale=True):
66  """Update the matplotlib representation to the current ellipse parameters.
67  """
68  import matplotlib.patches
69  core = _agl.Axes(self.__ellipse.getCore())
70  core.scale(2.0 * scale)
71  new_patch = matplotlib.patches.Ellipse(
72  (self.__ellipse.getCenter().getX(), self.__ellipse.getCenter().getY()),
73  core.a, core.b, core.theta * 180.0 / numpy.pi
74  )
75  new_patch.update_from(self.patch)
76  axes = self.patch.get_axes()
77  if axes is not None:
78  self.patch.remove()
79  axes.add_patch(new_patch)
80  self.patch = new_patch
81  if axes is not None:
82  if rescale: axes.autoscale_view()
83  if show: axes.figure.canvas.draw()
84 
85 def Ellipse_plot(self, axes=None, scale=1.0, show=True, rescale=True, **kwds):
86  """Plot the ellipse in matplotlib, adding a MatplotlibInterface
87  object as the 'matplotlib' attribute of the ellipse.
88 
89  Aside from those below, keyword arguments for the
90  matplotlib.patches.Patch constructor are also accepted
91  ('facecolor', 'linestyle', etc.)
92 
93  Arguments:
94  axes -------- A matplotlib.axes.Axes object, or None to use
95  matplotlib.pyplot.gca().
96  scale ------- Scale the displayed ellipse by this factor.
97  show -------- If True, update the figure automatically. Set
98  to False for batch processing.
99  rescale ----- If True, rescale the axes.
100  """
101  import matplotlib.pyplot
102  self.matplotlib = self.MatplotlibInterface(self, scale, **kwds)
103  if axes is None:
104  axes = matplotlib.pyplot.gca()
105  axes.add_patch(self.matplotlib.patch)
106  if rescale: axes.autoscale_view()
107  if show: axes.figure.canvas.draw()
108  return self.matplotlib.patch
109 
110 
111 Ellipse.MatplotlibInterface = EllipseMatplotlibInterface
112 Ellipse.plot = Ellipse_plot
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a...
Definition: Axes.h:45