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

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

""" 

obspy.imaging - Plotting Routines for ObsPy 

=========================================== 

This module provides routines for plotting and displaying often used in 

seismology. It can currently plot waveform data, generate spectrograms and draw 

beachballs. The module :mod:`obspy.imaging` depends on the plotting module 

`matplotlib <http://matplotlib.sourceforge.net/>`_. 

 

 

:copyright: 

    The ObsPy Development Team (devs@obspy.org) 

:license: 

    GNU General Public License (GPL) 

    (http://www.gnu.org/licenses/gpl.txt) 

 

 

Seismograms 

----------- 

This submodule can plot multiple :class:`~obspy.core.trace.Trace` in one 

:class:`~obspy.core.stream.Stream` object and has various other optional 

arguments to adjust the plot, such as color and tick format changes. 

 

Additionally the start- and endtime of the plot can be given as 

:class:`~obspy.core.utcdatetime.UTCDateTime` objects. 

 

Examples files may be retrieved via http://examples.obspy.org. 

 

>>> from obspy import read 

>>> st = read() 

>>> print(st)  # doctest: +ELLIPSIS 

3 Trace(s) in Stream: 

BW.RJOB..EHZ | 2009-08-24T00:20:03.000000Z - ... | 100.0 Hz, 3000 samples 

BW.RJOB..EHN | 2009-08-24T00:20:03.000000Z - ... | 100.0 Hz, 3000 samples 

BW.RJOB..EHE | 2009-08-24T00:20:03.000000Z - ... | 100.0 Hz, 3000 samples 

>>> st.plot(color='gray', tick_format='%I:%M %p', 

...         starttime=st[0].stats.starttime, 

...         endtime=st[0].stats.starttime+20) 

 

.. plot:: 

 

    from obspy import read 

    st = read() 

    st.plot(color='gray', tick_format='%I:%M %p', 

            starttime=st[0].stats.starttime, 

            endtime=st[0].stats.starttime+20) 

 

Spectrograms 

------------ 

The :mod:`obspy.imaging.spectrogram` submodule plots spectrograms. 

 

The spectrogram will on default have 90% overlap and a maximum sliding window 

size of 4096 points. For more info see 

:func:`obspy.imaging.spectrogram.spectrogram`. 

 

>>> from obspy import read 

>>> st = read() 

>>> st[0].spectrogram(log=True) #doctest: +SKIP 

 

.. plot:: 

 

    from obspy import read 

    st = read() 

    st[0].spectrogram(log=True) 

 

Beachballs 

---------- 

Draws a beach ball diagram of an earthquake focal mechanism. 

 

.. note:: 

    ObsPy ships with two engines for beachball generation. 

 

    (1) :mod:`obspy.imaging.beachball` 

        is based on the program from the 

        `Generic Mapping Tools (GMT)`_ and the MATLAB script `bb.m`_ written by 

        Andy Michael and Oliver Boyd, which both have known limitations. 

    (2) :mod:`obspy.imaging.mopad_wrapper` 

        is based on the the *Moment tensor Plotting and Decomposition tool* 

        (MoPaD) [Krieger2012]_. MoPaD is more correct, however it consumes much 

        more processing time. 

 

    The function calls for creating beachballs are similar in both modules. The 

    following examples are based on the first module, however those example 

    will also work with MoPaD by using 

 

    >>> from obspy.imaging.mopad_wrapper import Beachball 

 

    and 

 

    >>> from obspy.imaging.mopad_wrapper import Beach 

 

    respectively. 

 

.. _`Generic Mapping Tools (GMT)`: http://gmt.soest.hawaii.edu 

.. _`bb.m`: http://www.ceri.memphis.edu/people/olboyd/Software/Software.html 

 

 

.. rubric:: Examples 

 

(1) The focal mechanism can be given by 3 (strike, dip, and rake) components. 

    The strike is of the first plane, clockwise relative to north. The dip is 

    of the first plane, defined clockwise and perpendicular to strike, relative 

    to horizontal such that 0 is horizontal and 90 is vertical. The rake is of 

    the first focal plane solution. 90 moves the hanging wall up-dip (thrust), 

    0 moves it in the strike direction (left-lateral), -90 moves it down-dip 

    (normal), and 180 moves it opposite to strike (right-lateral). 

 

    >>> from obspy.imaging.beachball import Beachball 

    >>> np1 = [150, 87, 1] 

    >>> Beachball(np1) #doctest: +ELLIPSIS 

    <matplotlib.figure.Figure object at 0x...> 

 

    .. plot:: 

 

        from obspy.imaging.beachball import Beachball 

        np1 = [150, 87, 1] 

        Beachball(np1) 

 

(2) The focal mechanism can also be specified using the 6 independent 

    components of the moment tensor (M11, M22, M33, M12, M13, M23). For 

    :func:`obspy.imaging.beachball.Beachball` (1, 2, 3) corresponds to 

    (Up, South, East) which is equvalent to (r, theta, phi). For 

    :func:`obspy.imaging.mopad_wrapper.Beachball` the coordinate system can be 

    chosen and includes the choices 'NED' (North, East, Down), 'USE' (Up, 

    South, East), 'NWU' (North, West, Up) or 'XYZ'. 

 

    >>> from obspy.imaging.beachball import Beachball 

    >>> mt = [-2.39, 1.04, 1.35, 0.57, -2.94, -0.94] 

    >>> Beachball(mt) #doctest: +ELLIPSIS 

    <matplotlib.figure.Figure object at 0x...> 

 

    .. plot:: 

 

        from obspy.imaging.beachball import Beachball 

        mt = [-2.39, 1.04, 1.35, 0.57, -2.94, -0.94] 

        Beachball(mt) 

 

    For more info see :func:`obspy.imaging.beachball.Beachball` and 

    :func:`obspy.imaging.mopad_wrapper.Beachball`. 

 

(3) Plot the beach ball as matplotlib collection into an existing plot. 

 

    >>> import matplotlib.pyplot as plt 

    >>> from obspy.imaging.beachball import Beach 

    >>> 

    >>> np1 = [150, 87, 1] 

    >>> mt = [-2.39, 1.04, 1.35, 0.57, -2.94, -0.94] 

    >>> beach1 = Beach(np1, xy=(-70, 80), width=30) 

    >>> beach2 = Beach(mt, xy=(50, 50), width=50) 

    >>> 

    >>> plt.plot([-100, 100], [0, 100], "rv", ms=20) #doctest: +ELLIPSIS 

    [<matplotlib.lines.Line2D object at 0x...>] 

    >>> ax = plt.gca() 

    >>> ax.add_collection(beach1) #doctest: +SKIP 

    >>> ax.add_collection(beach2) #doctest: +SKIP 

    >>> ax.set_aspect("equal") 

    >>> ax.set_xlim((-120, 120)) 

    (-120, 120) 

    >>> ax.set_ylim((-20, 120)) 

    (-20, 120) 

 

    .. plot:: 

 

        import matplotlib.pyplot as plt 

        from obspy.imaging.beachball import Beach 

        np1 = [150, 87, 1] 

        mt = [-2.39, 1.04, 1.35, 0.57, -2.94, -0.94] 

        beach1 = Beach(np1, xy=(-70, 80), width=30) 

        beach2 = Beach(mt, xy=(50, 50), width=50) 

        plt.plot([-100, 100], [0, 100], "rv", ms=20) 

        ax = plt.gca() 

        ax.add_collection(beach1) 

        ax.add_collection(beach2) 

        ax.set_aspect("equal") 

        ax.set_xlim((-120, 120)) 

        ax.set_ylim((-20, 120)) 

 

    For more info see :func:`obspy.imaging.beachball.Beach` and 

    :func:`obspy.imaging.mopad_wrapper.Beach`. 

 

 

Saving plots into files 

----------------------- 

All plotting routines offer an ``outfile`` argument to save the result into a 

file. 

 

The ``outfile`` parameter is also used to automatically determine the file 

format. Available output formats mainly depend on your matplotlib settings. 

Common formats are png, svg, pdf or ps. 

 

>>> from obspy import read 

>>> st = read() 

>>> st.plot(outfile='graph.png') #doctest: +SKIP 

""" 

 

# Please do not import any modules using matplotlib - otherwise it will disturb 

# the test suite (running without X11 or any other display) 

# see tests/__init__.py for details