Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/plot/hudson.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-10-11 11:01 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6import numpy as num 

7 

8from pyrocko import moment_tensor as pmt 

9 

10 

11def project(mt): 

12 ''' 

13 Calculate Hudson's (u, v) coordinates for a given moment tensor. 

14 

15 The moment tensor can be given as a 

16 :py:class:`pyrocko.moment_tensor.MomentTensor` object, or by anything that 

17 can be converted to a 3x3 NumPy matrix, or as the six independent moment 

18 tensor entries as ``(mnn, mee, mdd, mne, mnd, med)``. 

19 ''' 

20 

21 mt = pmt.values_to_matrix(mt) 

22 eig_m = pmt.eigh_check(mt)[0] 

23 m3, m2, m1 = eig_m / num.max(num.abs(eig_m)) 

24 u = -2./3. * (m1 + m3 - 2.0*m2) 

25 v = 1./3. * (m1 + m2 + m3) 

26 return u, v 

27 

28 

29def draw_axes(axes, color='black', fontsize=12, linewidth=1.5): 

30 

31 ''' 

32 Plot axes and annotations of Hudson's MT decomposition diagram. 

33 ''' 

34 

35 axes.set_axis_off() 

36 axes.set_aspect(1.0) 

37 

38 axes.set_xlim(-4./3.-0.1, 4./3.+0.1) 

39 axes.set_ylim(-1.1, 1.1) 

40 

41 axes.plot( 

42 [-4./3., 0., 4./3., 0., -4/3.], 

43 [-1./3., -1., 1./3., 1., -1./3.], 

44 zorder=-1, 

45 linewidth=linewidth, 

46 color=color) 

47 

48 axes.plot( 

49 [-1.0, 1.0], 

50 [0., 0.], 

51 zorder=-1, 

52 linewidth=linewidth, 

53 color=color) 

54 

55 axes.plot( 

56 [0., 0.], 

57 [-1., 1.], 

58 zorder=-1, 

59 linewidth=linewidth, 

60 color=color) 

61 

62 d = fontsize/3. 

63 for txt, pos, off, va, ha in [ 

64 ('+Isotropic', (0., 1.), (-d, d), 'bottom', 'right'), 

65 ('-Isotropic', (0., -1.), (d, -d), 'top', 'left'), 

66 ('-CLVD', (+1.0, 0.), (d, -d), 'top', 'left'), 

67 ('+CLVD', (-1.0, 0.), (-d, d), 'bottom', 'right')]: 

68 

69 axes.plot( 

70 pos[0], pos[1], 'o', 

71 color=color, 

72 markersize=fontsize/2.) 

73 

74 axes.annotate( 

75 txt, 

76 xy=pos, 

77 xycoords='data', 

78 xytext=off, 

79 textcoords='offset points', 

80 verticalalignment=va, 

81 horizontalalignment=ha, 

82 rotation=0.) 

83 

84 for txt, pos, off, va, ha in [ 

85 ('-Dipole', (2./3., -1./3.), (d, -d), 'top', 'left'), 

86 ('+Dipole', (-2./3., 1./3.), (-d, d), 'bottom', 'right'), 

87 ('-Crack', (4./9., -5./9.), (d, -d), 'top', 'left'), 

88 ('+Crack', (-4./9., 5./9.), (-d, d), 'bottom', 'right')]: 

89 

90 axes.plot( 

91 pos[0], pos[1], 'o', 

92 color=color, 

93 markersize=fontsize/2.) 

94 

95 axes.annotate( 

96 txt, 

97 xy=pos, 

98 xycoords='data', 

99 xytext=off, 

100 textcoords='offset points', 

101 verticalalignment=va, 

102 horizontalalignment=ha, 

103 rotation=0.)