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

#!/usr/bin/env python 

# -*- coding: utf-8 -*- 

""" 

The array_analysis test suite. 

""" 

 

import unittest 

import numpy as np 

from obspy.signal.array_analysis import array_rotation_strain, get_geometry 

 

 

class ArrayTestCase(unittest.TestCase): 

    """ 

    Test cases for array_analysis functions. 

    """ 

    def setUp(self): 

        self.array_coords = np.array([[0.0, 0.0, 0.0], 

                                      [-5.0, 7.0, 0.0], 

                                      [5.0, 7.0, 0.0], 

                                      [10.0, 0.0, 0.0], 

                                      [5.0, -7.0, 0.0], 

                                      [-5.0, -7.0, 0.0], 

                                      [-10.0, 0.0, 0.0]]) 

        self.subarray = np.array([0, 1, 2, 3, 4, 5, 6]) 

        self.ts1 = np.empty((1000, 7)) * np.NaN 

        self.ts2 = np.empty((1000, 7)) * np.NaN 

        self.ts3 = np.empty((1000, 7)) * np.NaN 

        self.sigmau = 0.0001 

        self.Vp = 1.93 

        self.Vs = 0.326 

 

    def tearDown(self): 

        pass 

 

    def test_array_rotation(self): 

        # tests function array_rotation_strain with synthetic data with pure 

        # rotation and no strain 

        array_coords = self.array_coords 

        subarray = self.subarray 

        ts1 = self.ts1 

        ts2 = self.ts2 

        ts3 = self.ts3 

        sigmau = self.sigmau 

        Vp = self.Vp 

        Vs = self.Vs 

 

        rotx = 0.00001 * np.exp(-1 * np.square(np.linspace(-2, 2, 1000))) * \ 

                np.sin(np.linspace(-30 * np.pi, 30 * np.pi, 1000)) 

        roty = 0.00001 * np.exp(-1 * np.square(np.linspace(-2, 2, 1000))) * \ 

                np.sin(np.linspace(-20 * np.pi, 20 * np.pi, 1000)) 

        rotz = 0.00001 * np.exp(-1 * np.square(np.linspace(-2, 2, 1000))) * \ 

                np.sin(np.linspace(-10 * np.pi, 10 * np.pi, 1000)) 

 

        for stat in xrange(7): 

            for t in xrange(1000): 

                ts1[t, stat] = -1. * array_coords[stat, 1] * rotz[t] 

                ts2[t, stat] = array_coords[stat, 0] * rotz[t] 

                ts3[t, stat] = array_coords[stat, 1] * rotx[t] - \ 

                        array_coords[stat, 0] * roty[t] 

 

        out = array_rotation_strain(subarray, ts1, ts2, ts3, Vp, Vs, 

                                    array_coords, sigmau) 

 

        np.testing.assert_array_almost_equal(rotx, out['ts_w1'], decimal=12) 

        np.testing.assert_array_almost_equal(roty, out['ts_w2'], decimal=12) 

        np.testing.assert_array_almost_equal(rotz, out['ts_w3'], decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_s'], 

                decimal=15) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_d'], 

                decimal=15) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_M'], 

                decimal=12) 

 

    def test_array_dilation(self): 

        # tests function array_rotation_strain with synthetic data with pure 

        # dilation and no rotation or shear strain 

        array_coords = self.array_coords 

        subarray = self.subarray 

        ts1 = self.ts1 

        ts2 = self.ts2 

        ts3 = self.ts3 

        sigmau = self.sigmau 

        Vp = self.Vp 

        Vs = self.Vs 

 

        eta = 1 - 2 * Vs ** 2 / Vp ** 2 

 

        dilation = .00001 * np.exp(-1 * \ 

                np.square(np.linspace(-2, 2, 1000))) * \ 

                np.sin(np.linspace(-40 * np.pi, 40 * np.pi, 1000)) 

 

        for stat in xrange(7): 

            for t in xrange(1000): 

                ts1[t, stat] = array_coords[stat, 0] * dilation[t] 

                ts2[t, stat] = array_coords[stat, 1] * dilation[t] 

                ts3[t, stat] = array_coords[stat, 2] * dilation[t] 

 

        out = array_rotation_strain(subarray, ts1, ts2, ts3, Vp, Vs, 

                                    array_coords, sigmau) 

 

        # remember free surface boundary conditions! 

        # see Spudich et al, 1995, (A2) 

        np.testing.assert_array_almost_equal(dilation * (2 - 2 * eta), 

                out['ts_d'], decimal=12) 

        np.testing.assert_array_almost_equal(dilation * 2, out['ts_dh'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(abs(dilation * .5 * (1 + \ 

                2 * eta)), out['ts_s'], decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_sh'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_w1'], 

                decimal=15) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_w2'], 

                decimal=15) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_w3'], 

                decimal=15) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_M'], 

                decimal=12) 

 

    def test_array_horizontal_shear(self): 

        # tests function array_rotation_strain with synthetic data with pure 

        # horizontal shear strain, no rotation or dilation 

        array_coords = self.array_coords 

        subarray = self.subarray 

        ts1 = self.ts1 

        ts2 = self.ts2 

        sigmau = self.sigmau 

        Vp = self.Vp 

        Vs = self.Vs 

 

        shear_strainh = .00001 * np.exp(-1 * \ 

                np.square(np.linspace(-2, 2, 1000))) * \ 

                np.sin(np.linspace(-10 * np.pi, 10 * np.pi, 1000)) 

 

        ts3 = np.zeros((1000, 7)) 

 

        for stat in xrange(7): 

            for t in xrange(1000): 

                ts1[t, stat] = array_coords[stat, 1] * shear_strainh[t] 

                ts2[t, stat] = array_coords[stat, 0] * shear_strainh[t] 

 

        out = array_rotation_strain(subarray, ts1, ts2, ts3, Vp, Vs, 

                                    array_coords, sigmau) 

 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_d'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_dh'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(abs(shear_strainh), out['ts_s'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(abs(shear_strainh), out['ts_sh'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_w1'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_w2'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_w3'], 

                decimal=12) 

        np.testing.assert_array_almost_equal(np.zeros(1000), out['ts_M'], 

                decimal=12) 

 

    def test_get_geometry(self): 

        """ 

        test get_geometry() in array_analysis.py 

        """ 

        ll = np.array([[24.5797167, 121.4842444, 385.106], 

                       [24.5797611, 121.4842333, 384.893], 

                       [24.5796694, 121.4842556, 385.106]]) 

 

        la = get_geometry(ll) 

 

        np.testing.assert_almost_equal(la[:, 0].sum(), 0., decimal=8) 

        np.testing.assert_almost_equal(la[:, 1].sum(), 0., decimal=8) 

        np.testing.assert_almost_equal(la[:, 2].sum(), 0., decimal=8) 

 

        ll = np.array([[10., 10., 10.], 

                       [0., 5., 5.], 

                       [0., 0., 0.]]) 

 

        la = get_geometry(ll, coordsys='xy') 

 

        np.testing.assert_almost_equal(la[:, 0].sum(), 0., decimal=8) 

        np.testing.assert_almost_equal(la[:, 1].sum(), 0., decimal=8) 

        np.testing.assert_almost_equal(la[:, 2].sum(), 0., decimal=8) 

 

 

def suite(): 

    return unittest.makeSuite(ArrayTestCase, 'test') 

 

 

if __name__ == '__main__': 

    unittest.main(defaultTest='suite')