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

#!/usr/bin/env python 

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

""" 

The calibration test suite. 

""" 

 

import os 

import unittest 

import numpy as np 

from obspy import read 

from obspy.signal.calibration import relcalstack 

 

 

class CalibrationTestCase(unittest.TestCase): 

    """ 

    Calibration test case 

    """ 

    def setUp(self): 

        # directory where the test files are located 

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

 

    def test_relcal_sts2_vs_unknown(self): 

        """ 

        Test relative calibration of unknown instrument vs STS2 in the same 

        time range. Window length is set to 20 s, smoothing rate to 10. 

        """ 

        st1 = read(os.path.join(self.path, 'ref_STS2')) 

        st2 = read(os.path.join(self.path, 'ref_unknown')) 

        calfile = os.path.join(self.path, 'STS2_simp.cal') 

 

        freq, amp, phase = relcalstack(st1, st2, calfile, 20, smooth=10, 

                                       save_data=False) 

 

        # read in the reference responses 

        un_resp = np.loadtxt(os.path.join(self.path, 'unknown.resp')) 

        kn_resp = np.loadtxt(os.path.join(self.path, 'STS2.refResp')) 

 

        # test if freq, amp and phase match the reference values 

        np.testing.assert_array_almost_equal(freq, un_resp[:, 0], 

                                             decimal=4) 

        np.testing.assert_array_almost_equal(freq, kn_resp[:, 0], 

                                             decimal=4) 

        np.testing.assert_array_almost_equal(amp, un_resp[:, 1], 

                                             decimal=4) 

        np.testing.assert_array_almost_equal(phase, un_resp[:, 2], 

                                             decimal=4) 

 

    def test_relcalUsingTraces(self): 

        """ 

        Tests using traces instead of stream objects as input parameters. 

        """ 

        st1 = read(os.path.join(self.path, 'ref_STS2')) 

        st2 = read(os.path.join(self.path, 'ref_unknown')) 

        calfile = os.path.join(self.path, 'STS2_simp.cal') 

        # stream 

        freq, amp, phase = relcalstack(st1, st2, calfile, 20, smooth=10, 

                                       save_data=False) 

        # traces 

        freq2, amp2, phase2 = relcalstack(st1[0], st2[0], calfile, 20, 

                                          smooth=10, save_data=False) 

        np.testing.assert_array_almost_equal(freq, freq2, decimal=4) 

        np.testing.assert_array_almost_equal(amp, amp2, decimal=4) 

        np.testing.assert_array_almost_equal(phase, phase2, decimal=4) 

 

 

def suite(): 

    return unittest.makeSuite(CalibrationTestCase, 'test') 

 

 

if __name__ == '__main__': 

    unittest.main(defaultTest='suite')