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

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

""" 

The seisan.core test suite. 

""" 

 

from obspy.core.utcdatetime import UTCDateTime 

from obspy.seisan.core import _getVersion, isSEISAN, readSEISAN 

import numpy as np 

import os 

import unittest 

 

 

class CoreTestCase(unittest.TestCase): 

    """ 

    Test cases for SEISAN core interfaces. 

    """ 

    def setUp(self): 

        # directory where the test files are located 

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

 

    def test_getVersion(self): 

        """ 

        Tests resulting version strings of SEISAN file. 

        """ 

        # 1 - big endian, 32 bit 

        file = os.path.join(self.path, '1996-06-03-1917-52S.TEST__002') 

        data = open(file, 'rb').read(80 * 12) 

        self.assertEqual(_getVersion(data), ('>', 32, 7)) 

        # 2 - little endian, 32 bit 

        file = os.path.join(self.path, '2001-01-13-1742-24S.KONO__004') 

        data = open(file, 'rb').read(80 * 12) 

        self.assertEqual(_getVersion(data), ('<', 32, 7)) 

 

    def test_isSEISAN(self): 

        """ 

        Tests SEISAN file check. 

        """ 

        # 1 - big endian, 32 bit 

        file = os.path.join(self.path, '1996-06-03-1917-52S.TEST__002') 

        self.assertTrue(isSEISAN(file)) 

        # 2 - little endian, 32 bit 

        file = os.path.join(self.path, '2001-01-13-1742-24S.KONO__004') 

        self.assertTrue(isSEISAN(file)) 

 

    def test_readSEISAN(self): 

        """ 

        Test SEISAN file reader. 

        """ 

        # 1 - big endian, 32 bit 

        file = os.path.join(self.path, '9701-30-1048-54S.MVO_21_1') 

        st1 = readSEISAN(file) 

        st1.verify() 

        self.assertEqual(len(st1), 21) 

        self.assertEqual(st1[20].stats.network, '') 

        self.assertEqual(st1[20].stats.station, 'MBGB') 

        self.assertEqual(st1[20].stats.location, 'J') 

        self.assertEqual(st1[20].stats.channel, 'SBE') 

        self.assertEqual(st1[20].stats.starttime, 

                         UTCDateTime('1997-01-30T10:48:54.040000Z')) 

        self.assertEqual(st1[20].stats.endtime, 

                         UTCDateTime('1997-01-30T10:49:42.902881Z')) 

        self.assertAlmostEqual(st1[20].stats.sampling_rate, 75.2, 1) 

        self.assertEqual(st1[20].stats.npts, 3675) 

        self.assertAlmostEqual(st1[20].stats.delta, 0.0133, 4) 

        datafile = os.path.join(self.path, 'MBGBSBJE') 

        # compare with ASCII values of trace 

        # XXX: extracted ASCII file contains less values than the original 

        # Seisan file! 

        self.assertEqual(list(st1[20].data[0:3665]), 

                         list(np.fromfile(datafile, dtype=int, sep=' '))) 

        # 2 - little endian, 32 bit 

        file = os.path.join(self.path, '2001-01-13-1742-24S.KONO__004') 

        st2 = readSEISAN(file) 

        st2.verify() 

        self.assertEqual(len(st2), 4) 

        self.assertEqual(list(st2[0].data[0:3]), [492, 519, 542]) 

 

    def test_readSEISANHeadOnly(self): 

        """ 

        Test SEISAN file reader with headonly flag. 

        """ 

        # 1 - big endian, 32 bit 

        file = os.path.join(self.path, '9701-30-1048-54S.MVO_21_1') 

        st1 = readSEISAN(file, headonly=True) 

        self.assertEqual(len(st1), 21) 

        self.assertEqual(st1[0].stats.network, '') 

        self.assertEqual(st1[0].stats.station, 'MBGA') 

        self.assertEqual(st1[0].stats.location, 'J') 

        self.assertEqual(st1[0].stats.channel, 'SBZ') 

        self.assertEqual(st1[0].stats.starttime, 

                         UTCDateTime('1997-01-30T10:48:54.040000Z')) 

        self.assertEqual(st1[0].stats.endtime, 

                         UTCDateTime('1997-01-30T10:49:42.902881Z')) 

        self.assertAlmostEqual(st1[0].stats.sampling_rate, 75.2, 1) 

        self.assertEqual(st1[0].stats.npts, 3675) 

        self.assertAlmostEqual(st1[20].stats.delta, 0.0133, 4) 

        self.assertEqual(list(st1[0].data), [])  # no data 

 

 

def suite(): 

    return unittest.makeSuite(CoreTestCase, 'test') 

 

 

if __name__ == '__main__': 

    unittest.main(defaultTest='suite')