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

#!/usr/bin/python 

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

""" 

The hoctavbands.core test suite. 

""" 

 

from obspy.signal import hoctavbands, util 

from scipy import signal 

import numpy as np 

import os 

import unittest 

 

 

# only tests for windowed data are implemented currently 

 

class HoctavbandsTestCase(unittest.TestCase): 

    """ 

    Test cases for half octav bands 

    """ 

    def setUp(self): 

        # directory where the test files are located 

        self.path = os.path.join(os.path.dirname(__file__), 'data') 

        file = os.path.join(self.path, '3cssan.hy.1.MBGA_Z') 

        f = open(file) 

        self.res = np.loadtxt(f) 

        f.close() 

        file = os.path.join(self.path, 'MBGA_Z.ASC') 

        f = open(file) 

        data = np.loadtxt(f) 

        f.close() 

        #self.path = os.path.dirname(__file__) 

        #self.res = np.loadtxt("3cssan.hy.1.MBGA_Z") 

        #data = np.loadtxt("MBGA_Z.ASC") 

        self.n = 256 

        self.fs = 75 

        self.smoothie = 3 

        self.fk = [2, 1, 0, -1, -2] 

        self.inc = int(0.05 * self.fs) 

        self.fc1 = 0.68 

        self.nofb = 8 

        #[0] Time (k*inc) 

        #[1] A_norm 

        #[2] dA_norm 

        #[3] dAsum 

        #[4] dA2sum 

        #[5] ct 

        #[6] dct 

        #[7] omega 

        #[8] domega 

        #[9] sigma 

        #[10] dsigma 

        #[11] logcep 

        #[12] logcep 

        #[13] logcep 

        #[14] dperiod 

        #[15] ddperiod 

        #[16] bwith 

        #[17] dbwith 

        #[18] cfreq 

        #[19] dcfreq 

        #[20] hob1 

        #[21] hob2 

        #[22] hob3 

        #[23] hob4 

        #[24] hob5 

        #[25] hob6 

        #[26] hob7 

        #[27] hob8 

        #[28] phi12 

        #[29] dphi12 

        #[30] phi13 

        #[31] dphi13 

        #[32] phi23 

        #[33] dphi23 

        #[34] lv_h1 

        #[35] lv_h2 

        #[36] lv_h3 

        #[37] dlv_h1 

        #[38] dlv_h2 

        #[39] dlv_h3 

        #[40] rect 

        #[41] drect 

        #[42] plan 

        #[43] dplan 

        self.data_win, self.nwin, self.no_win = \ 

            util.enframe(data, signal.hamming(self.n), self.inc) 

 

    def test_hoctavbands(self): 

        """ 

        """ 

        hob = hoctavbands.sonogram(self.data_win, self.fs, self.fc1, 

                                   self.nofb, self.no_win) 

        rms = np.sqrt(np.sum((hob[:, 0] - self.res[:, 20]) ** 2) / 

                      np.sum(self.res[:, 20] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

        rms = np.sqrt(np.sum((hob[:, 1] - self.res[:, 21]) ** 2) / 

                      np.sum(self.res[:, 21] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

        rms = np.sqrt(np.sum((hob[:, 2] - self.res[:, 22]) ** 2) / 

                      np.sum(self.res[:, 22] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

        rms = np.sqrt(np.sum((hob[:, 3] - self.res[:, 23]) ** 2) / 

                      np.sum(self.res[:, 23] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

        rms = np.sqrt(np.sum((hob[:, 4] - self.res[:, 24]) ** 2) / 

                      np.sum(self.res[:, 24] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

        rms = np.sqrt(np.sum((hob[:, 5] - self.res[:, 25]) ** 2) / 

                      np.sum(self.res[:, 25] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

        rms = np.sqrt(np.sum((hob[:, 6] - self.res[:, 26]) ** 2) / 

                      np.sum(self.res[:, 26] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

        rms = np.sqrt(np.sum((hob[:, 7] - self.res[:, 27]) ** 2) / 

                      np.sum(self.res[:, 27] ** 2)) 

        self.assertEqual(rms < 1.0e-5, True) 

 

 

def suite(): 

    return unittest.makeSuite(HoctavbandsTestCase, 'test') 

 

 

if __name__ == '__main__': 

    unittest.main(defaultTest='suite')