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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

# 

# LSST Data Management System 

# Copyright 2008, 2009, 2010 LSST Corporation. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <http://www.lsstcorp.org/LegalNotices/>. 

# 

 

"""lsst.afw.geom.ellipses 

""" 

from .ellipsesLib import * 

 

Separable = { 

(Distortion, DeterminantRadius): SeparableDistortionDeterminantRadius, 

(Distortion, TraceRadius): SeparableDistortionTraceRadius, 

(Distortion, LogDeterminantRadius): SeparableDistortionLogDeterminantRadius, 

(Distortion, LogTraceRadius): SeparableDistortionLogTraceRadius, 

(ConformalShear, DeterminantRadius): SeparableConformalShearDeterminantRadius, 

(ConformalShear, TraceRadius): SeparableConformalShearTraceRadius, 

(ConformalShear, LogDeterminantRadius): SeparableConformalShearLogDeterminantRadius, 

(ConformalShear, LogTraceRadius): SeparableConformalShearLogTraceRadius 

} 

 

 

class EllipseMatplotlibInterface: 

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

 

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

adds the interface as the matplotlib attribute of the ellipse 

object (this can be deleted later if desired). 

""" 

 

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

import matplotlib.patches 

self.__ellipse = weakref.proxy(ellipse) 

self.scale = float(scale) 

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

core.scale(2.0 * scale) 

self.patch = matplotlib.patches.Ellipse( 

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

core.getA(), core.getB(), core.getTheta() * 180.0 / numpy.pi, 

**kwds 

) 

 

def __getattr__(self, name): 

return getattr(self.patch, name) 

 

def update(self, show=True, rescale=True): 

"""Update the matplotlib representation to the current ellipse parameters. 

""" 

import matplotlib.patches 

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

core.scale(2.0 * scale) 

new_patch = matplotlib.patches.Ellipse( 

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

core.a, core.b, core.theta * 180.0 / numpy.pi 

) 

new_patch.update_from(self.patch) 

axes = self.patch.get_axes() 

if axes is not None: 

self.patch.remove() 

axes.add_patch(new_patch) 

self.patch = new_patch 

if axes is not None: 

if rescale: 

axes.autoscale_view() 

if show: 

axes.figure.canvas.draw() 

 

 

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

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

object as the 'matplotlib' attribute of the ellipse. 

 

Aside from those below, keyword arguments for the 

matplotlib.patches.Patch constructor are also accepted 

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

 

Arguments: 

axes -------- A matplotlib.axes.Axes object, or None to use 

matplotlib.pyplot.gca(). 

scale ------- Scale the displayed ellipse by this factor. 

show -------- If True, update the figure automatically. Set 

to False for batch processing. 

rescale ----- If True, rescale the axes. 

""" 

import matplotlib.pyplot 

self.matplotlib = self.MatplotlibInterface(self, scale, **kwds) 

if axes is None: 

axes = matplotlib.pyplot.gca() 

axes.add_patch(self.matplotlib.patch) 

if rescale: 

axes.autoscale_view() 

if show: 

axes.figure.canvas.draw() 

return self.matplotlib.patch 

 

 

# Ellipse.MatplotlibInterface = EllipseMatplotlibInterface 

# Ellipse.plot = Ellipse_plot