Ejemplo n.º 1
0
    def test_calculate_activity_rate(self):
        # Tests for the calculation of the activity rate. At this point
        # this is really a circular test - an independent test would be
        # helpful in future!
        parser0 = ReadStrainCsv(STRAIN_FILE)
        self.strain_model = parser0.read_data()
        self.model = Shift([5.0])
        self.model.calculate_activity_rate(self.strain_model)

        expected_rate = np.array([[5.66232696e-14], [5.66232696e-14],
                                  [5.66232696e-14], [5.66232696e-14],
                                  [2.73091764e-12], [2.80389274e-12],
                                  [2.88207458e-12], [6.11293721e-12],
                                  [8.19834427e-12], [6.55082175e-12],
                                  [7.90822653e-11], [7.85391610e-11],
                                  [8.12633607e-11], [7.66785657e-11],
                                  [4.07359524e-11], [2.16914046e-10],
                                  [4.74341943e-10], [1.99907599e-10],
                                  [3.55861556e-11], [1.69536101e-10],
                                  [1.69884622e-10], [1.70233341e-10],
                                  [5.06642764e-10]])

        np.testing.assert_array_almost_equal(
            np.log10(expected_rate),
            np.log10(self.model.strain.seismicity_rate))
Ejemplo n.º 2
0
 def test_check_invalid_longitude(self):
     '''
     Tests to ensure longitudes greater than 180.0 are returned in the
     range (-180. to 180.)
     '''
     self.model = ReadStrainCsv('some_random_file')
     self.model.strain.data = {'longitude': np.array([30., 180., 270.])}
     self.model._check_invalid_longitudes()
     np.testing.assert_array_almost_equal(
         self.model.strain.data['longitude'],
         np.array([30., 180., -90.]))
Ejemplo n.º 3
0
    def test_read_file(self):
        '''
        Tests the reader on a simple strain file
        '''
        self.model = ReadStrainCsv(IN_FILE)
        strain = self.model.read_data()
        # First test - check longitude and latitude
        exp_longitude = np.array(
            [-74.2, -74.1, -74., -73.9, -72.9, -72.8, 46.2, 46.3, 46.4, 176.9,
             177., 177.1, -74.1,  -74., -73.9, -73.8, -112.2, -112.1, -112.,
             -111.9, -111.8])
        exp_latitude = np.array(
            [-55.7, -55.7, -55.7, -55.7, -55.7, -55.7, -38.2, -38.2, -38.2,
             -38.2, -38.2, -38.2, -38.1, -38.1, -38.1,
             -38.1, -24.8, -24.8, -24.8, -24.8, -24.8])
        region = np.array([b'IPL', b'IPL', b'IPL', b'IPL', b'R', b'R', b'O',
                           b'O', b'O', b'C', b'C', b'C', b'S', b'S', b'S',
                           b'S', b'R', b'R', b'R', b'R', b'R'])
        str_2nd_inv = np.array(
            [0., 0.,   0., 0.0, 6.97660913e-07,
             4.64676812e-07, 3.51209339e-08, 3.59874978e-08, 3.69339952e-08,
             9.96827969e-08, 8.17414827e-08, 5.58344876e-08, 3.42756721e-07,
             3.42576969e-07, 3.55996685e-07, 3.35017194e-07, 1.11642096e-06,
             2.39838312e-06, 2.73038946e-06, 2.46489650e-06, 1.14653444e-06])

        np.testing.assert_array_almost_equal(exp_longitude,
                                             strain.data['longitude'])

        np.testing.assert_array_almost_equal(exp_latitude,
                                             strain.data['latitude'])

        np.testing.assert_array_equal(region, strain.data['region'])

        # Take from 4th value to avoid log10(0.) for IPL regions
        np.testing.assert_array_almost_equal(
            np.log10(str_2nd_inv[4:]),
            np.log10(strain.data['2nd_inv'][4:]))

        self.assertListEqual(
            strain.data_variables,
            ['longitude', 'latitude', 'exx', 'eyy', 'exy', '2nd_inv',
             'dilatation', 'err', 'e1h', 'e2h'])
Ejemplo n.º 4
0
 def test_check_invalid_longitude(self):
     '''
     Tests to ensure longitudes greater than 180.0 are returned in the
     range (-180. to 180.)
     '''
     self.model = ReadStrainCsv('some_random_file')
     self.model.strain.data = {'longitude': np.array([30., 180., 270.])}
     self.model._check_invalid_longitudes()
     np.testing.assert_array_almost_equal(
         self.model.strain.data['longitude'],
         np.array([30., 180., -90.]))
Ejemplo n.º 5
0
    def test_calculate_activity_rate(self):
        # Tests for the calculation of the activity rate. At this point
        # this is really a circular test - an independent test would be
        # helpful in future!
        parser0 = ReadStrainCsv(STRAIN_FILE)
        self.strain_model = parser0.read_data()
        self.model = Shift([5.0])
        self.model.calculate_activity_rate(self.strain_model)

        expected_rate = np.array([
            [5.66232696e-14], [5.66232696e-14],
            [5.66232696e-14], [5.66232696e-14], [2.73091764e-12],
            [2.80389274e-12], [2.88207458e-12], [6.11293721e-12],
            [8.19834427e-12], [6.55082175e-12], [7.90822653e-11],
            [7.85391610e-11], [8.12633607e-11], [7.66785657e-11],
            [4.07359524e-11], [2.16914046e-10], [4.74341943e-10],
            [1.99907599e-10], [3.55861556e-11], [1.69536101e-10],
            [1.69884622e-10], [1.70233341e-10], [5.06642764e-10]])

        np.testing.assert_array_almost_equal(
            np.log10(expected_rate),
            np.log10(self.model.strain.seismicity_rate))
Ejemplo n.º 6
0
    def test_read_file(self):
        '''
        Tests the reader on a simple strain file
        '''
        self.model = ReadStrainCsv(IN_FILE)
        strain =self.model.read_data()
        # First test - check longitude and latitude
        exp_longitude = np.array([ -74.2,  -74.1,  -74. ,  -73.9,  -72.9, 
            -72.8,   46.2,   46.3, 46.4,  176.9,  177. ,177.1,  -74.1,  -74.,
            -73.9,  -73.8,  -112.2, -112.1, -112. , -111.9, -111.8])
        exp_latitude = np.array([-55.7, -55.7, -55.7, -55.7, -55.7, -55.7, 
            -38.2, -38.2, -38.2,  -38.2, -38.2, -38.2, -38.1, -38.1, -38.1,
            -38.1, -24.8, -24.8, -24.8, -24.8, -24.8])
        region = np.array(['IPL', 'IPL', 'IPL', 'IPL', 'R', 'R', 'O', 'O', 
                           'O', 'C', 'C', 'C', 'S', 'S', 'S', 'S', 'R', 'R', 
                           'R', 'R', 'R'])
        str_2nd_inv = np.array([0., 0.,   0., 0.0, 6.97660913e-07,   
            4.64676812e-07, 3.51209339e-08, 3.59874978e-08, 3.69339952e-08,
            9.96827969e-08, 8.17414827e-08, 5.58344876e-08, 3.42756721e-07, 
            3.42576969e-07, 3.55996685e-07, 3.35017194e-07, 1.11642096e-06, 
            2.39838312e-06, 2.73038946e-06, 2.46489650e-06, 1.14653444e-06])

        np.testing.assert_array_almost_equal(exp_longitude,
                                             strain.data['longitude'])

        np.testing.assert_array_almost_equal(exp_latitude,
                                             strain.data['latitude'])
        
        np.testing.assert_array_equal(region, strain.data['region'])
        #self.assertListEqual(region, strain.data['region'])
        # Take from 4th value to avoid log10(0.) for IPL regions
        np.testing.assert_array_almost_equal(np.log10(str_2nd_inv[4:]),
            np.log10(strain.data['2nd_inv'][4:]))

        self.assertListEqual(strain.data_variables,
            ['longitude', 'latitude', 'exx', 'eyy', 'exy', '2nd_inv', 
             'dilatation', 'err', 'e1h', 'e2h'])
Ejemplo n.º 7
0
 def test_basic_instantiation(self):
     '''
     Tests the instantiation of the reader class (trivial)
     '''
     self.model = ReadStrainCsv('some_random_file')
     self.assertEqual(self.model.filename, 'some_random_file')
Ejemplo n.º 8
0
class TestStrainCsvReader(unittest.TestCase):
    '''
    Test suite for the strain csv reader
    '''
    def setUp(self):
        '''
        '''
        self.model = None
        self.filename = None

    def test_basic_instantiation(self):
        '''
        Tests the instantiation of the reader class (trivial)
        '''
        self.model = ReadStrainCsv('some_random_file')
        self.assertEqual(self.model.filename, 'some_random_file')

    def test_check_invalid_longitude(self):
        '''
        Tests to ensure longitudes greater than 180.0 are returned in the
        range (-180. to 180.)
        '''
        self.model = ReadStrainCsv('some_random_file')
        self.model.strain.data = {'longitude': np.array([30., 180., 270.])}
        self.model._check_invalid_longitudes()
        np.testing.assert_array_almost_equal(
            self.model.strain.data['longitude'],
            np.array([30., 180., -90.]))

    def test_read_file(self):
        '''
        Tests the reader on a simple strain file
        '''
        self.model = ReadStrainCsv(IN_FILE)
        strain = self.model.read_data()
        # First test - check longitude and latitude
        exp_longitude = np.array(
            [-74.2, -74.1, -74., -73.9, -72.9, -72.8, 46.2, 46.3, 46.4, 176.9,
             177., 177.1, -74.1,  -74., -73.9, -73.8, -112.2, -112.1, -112.,
             -111.9, -111.8])
        exp_latitude = np.array(
            [-55.7, -55.7, -55.7, -55.7, -55.7, -55.7, -38.2, -38.2, -38.2,
             -38.2, -38.2, -38.2, -38.1, -38.1, -38.1,
             -38.1, -24.8, -24.8, -24.8, -24.8, -24.8])
        region = np.array([b'IPL', b'IPL', b'IPL', b'IPL', b'R', b'R', b'O',
                           b'O', b'O', b'C', b'C', b'C', b'S', b'S', b'S',
                           b'S', b'R', b'R', b'R', b'R', b'R'])
        str_2nd_inv = np.array(
            [0., 0.,   0., 0.0, 6.97660913e-07,
             4.64676812e-07, 3.51209339e-08, 3.59874978e-08, 3.69339952e-08,
             9.96827969e-08, 8.17414827e-08, 5.58344876e-08, 3.42756721e-07,
             3.42576969e-07, 3.55996685e-07, 3.35017194e-07, 1.11642096e-06,
             2.39838312e-06, 2.73038946e-06, 2.46489650e-06, 1.14653444e-06])

        np.testing.assert_array_almost_equal(exp_longitude,
                                             strain.data['longitude'])

        np.testing.assert_array_almost_equal(exp_latitude,
                                             strain.data['latitude'])

        np.testing.assert_array_equal(region, strain.data['region'])

        # Take from 4th value to avoid log10(0.) for IPL regions
        np.testing.assert_array_almost_equal(
            np.log10(str_2nd_inv[4:]),
            np.log10(strain.data['2nd_inv'][4:]))

        self.assertListEqual(
            strain.data_variables,
            ['longitude', 'latitude', 'exx', 'eyy', 'exy', '2nd_inv',
             'dilatation', 'err', 'e1h', 'e2h'])
Ejemplo n.º 9
0
 def test_basic_instantiation(self):
     '''
     Tests the instantiation of the reader class (trivial)
     '''
     self.model = ReadStrainCsv('some_random_file')
     self.assertEqual(self.model.filename, 'some_random_file')
Ejemplo n.º 10
0
class TestStrainCsvReader(unittest.TestCase):
    '''
    Test suite for the strain csv reader
    '''
    def setUp(self):
        '''
        '''
        self.model = None
        self.filename = None

    def test_basic_instantiation(self):
        '''
        Tests the instantiation of the reader class (trivial)
        '''
        self.model = ReadStrainCsv('some_random_file')
        self.assertEqual(self.model.filename, 'some_random_file')

    def test_check_invalid_longitude(self):
        '''
        Tests to ensure longitudes greater than 180.0 are returned in the
        range (-180. to 180.)
        '''
        self.model = ReadStrainCsv('some_random_file')
        self.model.strain.data = {'longitude': np.array([30., 180., 270.])}
        self.model._check_invalid_longitudes()
        np.testing.assert_array_almost_equal(
            self.model.strain.data['longitude'],
            np.array([30., 180., -90.]))

    def test_read_file(self):
        '''
        Tests the reader on a simple strain file
        '''
        self.model = ReadStrainCsv(IN_FILE)
        strain =self.model.read_data()
        # First test - check longitude and latitude
        exp_longitude = np.array([ -74.2,  -74.1,  -74. ,  -73.9,  -72.9, 
            -72.8,   46.2,   46.3, 46.4,  176.9,  177. ,177.1,  -74.1,  -74.,
            -73.9,  -73.8,  -112.2, -112.1, -112. , -111.9, -111.8])
        exp_latitude = np.array([-55.7, -55.7, -55.7, -55.7, -55.7, -55.7, 
            -38.2, -38.2, -38.2,  -38.2, -38.2, -38.2, -38.1, -38.1, -38.1,
            -38.1, -24.8, -24.8, -24.8, -24.8, -24.8])
        region = np.array(['IPL', 'IPL', 'IPL', 'IPL', 'R', 'R', 'O', 'O', 
                           'O', 'C', 'C', 'C', 'S', 'S', 'S', 'S', 'R', 'R', 
                           'R', 'R', 'R'])
        str_2nd_inv = np.array([0., 0.,   0., 0.0, 6.97660913e-07,   
            4.64676812e-07, 3.51209339e-08, 3.59874978e-08, 3.69339952e-08,
            9.96827969e-08, 8.17414827e-08, 5.58344876e-08, 3.42756721e-07, 
            3.42576969e-07, 3.55996685e-07, 3.35017194e-07, 1.11642096e-06, 
            2.39838312e-06, 2.73038946e-06, 2.46489650e-06, 1.14653444e-06])

        np.testing.assert_array_almost_equal(exp_longitude,
                                             strain.data['longitude'])

        np.testing.assert_array_almost_equal(exp_latitude,
                                             strain.data['latitude'])
        
        np.testing.assert_array_equal(region, strain.data['region'])
        #self.assertListEqual(region, strain.data['region'])
        # Take from 4th value to avoid log10(0.) for IPL regions
        np.testing.assert_array_almost_equal(np.log10(str_2nd_inv[4:]),
            np.log10(strain.data['2nd_inv'][4:]))

        self.assertListEqual(strain.data_variables,
            ['longitude', 'latitude', 'exx', 'eyy', 'exy', '2nd_inv', 
             'dilatation', 'err', 'e1h', 'e2h'])