Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

25from .ellipsesLib import * 

26 

27Separable = { 

28 (Distortion, DeterminantRadius): SeparableDistortionDeterminantRadius, 

29 (Distortion, TraceRadius): SeparableDistortionTraceRadius, 

30 (Distortion, LogDeterminantRadius): SeparableDistortionLogDeterminantRadius, 

31 (Distortion, LogTraceRadius): SeparableDistortionLogTraceRadius, 

32 (ConformalShear, DeterminantRadius): SeparableConformalShearDeterminantRadius, 

33 (ConformalShear, TraceRadius): SeparableConformalShearTraceRadius, 

34 (ConformalShear, LogDeterminantRadius): SeparableConformalShearLogDeterminantRadius, 

35 (ConformalShear, LogTraceRadius): SeparableConformalShearLogTraceRadius 

36} 

37 

38 

39class EllipseMatplotlibInterface: 

40 """An interface for drawing the ellipse using matplotlib. 

41 

42 This is typically initiated by calling Ellipse.plot(), which 

43 returns an instance of this class. 

44 """ 

45 

46 def __init__(self, ellipse, scale=1.0, **kwds): 

47 import matplotlib.patches 

48 import weakref 

49 import numpy as np 

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 / np.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 import numpy as np 

68 core = _agl.Axes(self.__ellipse.getCore()) 

69 core.scale(2.0 * scale) 

70 new_patch = matplotlib.patches.Ellipse( 

71 (self.__ellipse.getCenter().getX(), self.__ellipse.getCenter().getY()), 

72 core.a, core.b, core.theta * 180.0 / np.pi 

73 ) 

74 new_patch.update_from(self.patch) 

75 axes = self.patch.get_axes() 

76 if axes is not None: 

77 self.patch.remove() 

78 axes.add_patch(new_patch) 

79 self.patch = new_patch 

80 if axes is not None: 

81 if rescale: 

82 axes.autoscale_view() 

83 if show: 

84 axes.figure.canvas.draw() 

85 

86 

87def Ellipse_plot(self, axes=None, scale=1.0, show=True, rescale=True, **kwds): 

88 """Plot the ellipse in matplotlib, adding a MatplotlibInterface 

89 object as the 'matplotlib' attribute of the ellipse. 

90 

91 Aside from those below, keyword arguments for the 

92 matplotlib.patches.Patch constructor are also accepted 

93 ('facecolor', 'linestyle', etc.) 

94 

95 Parameters 

96 ---------- 

97 axes : `matplotlib.axes.Axes`, optional 

98 Axes to plot on. Defaults to matplotlib.pyplot.gca(). 

99 scale : `float`, optional 

100 Scale the displayed ellipse by this factor. 

101 show : `bool`, optional 

102 If True, update the figure automatically. Set to False for batch 

103 processing. 

104 rescale : `bool`, optional 

105 If True, rescale the axes. 

106 

107 Returns 

108 ------- 

109 interface : `EllipseMatplotlibInterface` 

110 An object that allows the matplotlib patch to be updated when the 

111 ellipse modified. 

112 """ 

113 import matplotlib.pyplot 

114 interface = self.MatplotlibInterface(self, scale, **kwds) 

115 if axes is None: 

116 axes = matplotlib.pyplot.gca() 

117 axes.add_patch(interface.patch) 

118 if rescale: 

119 axes.autoscale_view() 

120 if show: 

121 axes.figure.canvas.draw() 

122 return interface 

123 

124 

125Ellipse.MatplotlibInterface = EllipseMatplotlibInterface 

126Ellipse.plot = Ellipse_plot