예제 #1
0
 def test_number_sources(self):
     """
     Checks the correct number of sources
     """
     rate_grid1 = RateGrid(self.limits, [POINT_SOURCE, AREA_SOURCE],
                           area_discretisation=4.0)
     self.assertEqual(rate_grid1.number_sources(), 2)
예제 #2
0
 def test_simple_fault_rate_out_of_magnitude_range(self):
     """
     Tests the simple fault rates out of the magnitude range
     """
     rate_grid1 = RateGrid(self.limits, [SIMPLE_FAULT],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     rate_grid1.get_rates(6.0, 6.5)
     np.testing.assert_array_almost_equal(rate_grid1.rates, expected_rates)
예제 #3
0
 def test_point_rate_out_of_limits(self):
     """
     Tests the point rates when the point is outside the limits
     """
     rate_grid1 = RateGrid(self.limits, [OUTSIDE_POINT_SOURCE],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     rate_grid1.get_rates(5.0)
     np.testing.assert_array_almost_equal(rate_grid1.rates, expected_rates)
예제 #4
0
 def test_simple_fault_rate_out_of_magnitude_range(self):
     """
     Tests the simple fault rates out of the magnitude range
     """
     rate_grid1 = RateGrid(self.limits, [SIMPLE_FAULT],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     rate_grid1.get_rates(6.0, 6.5)
     np.testing.assert_array_almost_equal(rate_grid1.rates,
                                          expected_rates)
예제 #5
0
 def test_point_rate_out_of_limits(self):
     """
     Tests the point rates when the point is outside the limits
     """
     rate_grid1 = RateGrid(self.limits, [OUTSIDE_POINT_SOURCE],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     rate_grid1.get_rates(5.0)
     np.testing.assert_array_almost_equal(rate_grid1.rates,
                                          expected_rates)
예제 #6
0
 def test_area_rate(self):
     """
     Tests the area rates
     """
     rate_grid1 = RateGrid(self.limits, [AREA_SOURCE],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     expected_rates[:, 0, :] = 1.0 / 12.0
     expected_rates[:, 1, :] = 2.0 / 12.0
     rate_grid1.get_rates(5.0)
     np.testing.assert_array_almost_equal(rate_grid1.rates, expected_rates)
예제 #7
0
 def test_area_rate(self):
     """
     Tests the area rates
     """
     rate_grid1 = RateGrid(self.limits, [AREA_SOURCE],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     expected_rates[:, 0, :] = 1.0 / 12.0
     expected_rates[:, 1, :] = 2.0 / 12.0
     rate_grid1.get_rates(5.0)
     np.testing.assert_array_almost_equal(rate_grid1.rates,
                                          expected_rates)
예제 #8
0
 def test_characteristic_fault_rate(self):
     """
     Tests the simple fault rates
     """
     rate_grid1 = RateGrid(self.limits, [CHARACTERISTIC_FAULT],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     expected_rates[:, :, 0] = np.array([[10., 20.], [0., 30.]])
     expected_rates[:, :, 1] = np.array([[11., 22.], [0., 33.]])
     rate_grid1.get_rates(6.0)
     np.testing.assert_array_almost_equal(rate_grid1.rates,
                                          expected_rates / 126.0)
예제 #9
0
 def test_point_location_outside(self):
     """
     Checks that when the point is outside the box then (None, None) is
     returned
     """
     # Outside longitude box
     rate_grid1 = RateGrid(self.limits, [POINT_SOURCE],
                           area_discretisation=4.0)
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.85, 14.95)), (None, None))
     # Outside latitude box
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.95, 15.25)), (None, None))
예제 #10
0
 def test_characteristic_fault_rate(self):
     """
     Tests the simple fault rates
     """
     rate_grid1 = RateGrid(self.limits, [CHARACTERISTIC_FAULT],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     expected_rates[:, :, 0] = np.array([[10., 20.],
                                         [0., 30.]])
     expected_rates[:, :, 1] = np.array([[11., 22.],
                                         [0., 33.]])
     rate_grid1.get_rates(6.0)
     np.testing.assert_array_almost_equal(rate_grid1.rates,
                                          expected_rates / 126.0)
예제 #11
0
 def test_point_location_outside(self):
     """
     Checks that when the point is outside the box then (None, None) is
     returned
     """
     # Outside longitude box
     rate_grid1 = RateGrid(self.limits, [POINT_SOURCE],
                           area_discretisation=4.0)
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.85, 14.95)),
         (None, None))
     # Outside latitude box
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.95, 15.25)),
         (None, None))
예제 #12
0
 def test_source_input_equivalence(self):
     """
     Verify that the same source model gives the same rate grid results
     when input as a source model or as an xml
     """
     ratemodel1 = RateGrid(self.limits, [
         POINT_SOURCE, AREA_SOURCE, SIMPLE_FAULT, COMPLEX_FAULT,
         CHARACTERISTIC_FAULT,
         Dummy("Rubbish")
     ],
                           area_discretisation=4.0)
     ratemodel2 = RateGrid.from_model_files(self.limits,
                                            SOURCE_MODEL_FILE,
                                            complex_mesh_spacing=1.0,
                                            area_discretisation=4.0)
     ratemodel1.get_rates(5.0)
     ratemodel2.get_rates(5.0)
     np.testing.assert_array_almost_equal(ratemodel1.rates,
                                          ratemodel2.rates)
예제 #13
0
 def test_point_location_border(self):
     """
     Checks the correct identifier of the point location for the
     cases that the point is not on the border
     """
     rate_grid1 = RateGrid(self.limits, [POINT_SOURCE],
                           area_discretisation=4.0)
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.9, 14.9)),
         (0, 0))
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.9, 15.0)),
         (0, 1))
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(15.0, 14.9)),
         (1, 0))
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(15.0, 15.0)),
         (1, 1))
예제 #14
0
 def test_source_input_equivalence(self):
     """
     Verify that the same source model gives the same rate grid results
     when input as a source model or as an xml
     """
     ratemodel1 = RateGrid(self.limits,
                           [POINT_SOURCE,
                            AREA_SOURCE,
                            SIMPLE_FAULT,
                            COMPLEX_FAULT,
                            CHARACTERISTIC_FAULT,
                            Dummy("Rubbish")],
                           area_discretisation=4.0)
     ratemodel2 = RateGrid.from_model_files(self.limits,
                                            SOURCE_MODEL_FILE,
                                            complex_mesh_spacing=1.0,
                                            area_discretisation=4.0)
     ratemodel1.get_rates(5.0)
     ratemodel2.get_rates(5.0)
     np.testing.assert_array_almost_equal(ratemodel1.rates,
                                          ratemodel2.rates)
예제 #15
0
 def test_instantiation(self):
     """
     Tests a simple instantiation with one area source
     """
     rate_grid1 = RateGrid(self.limits, [AREA_SOURCE],
                           area_discretisation=4.0)
     np.testing.assert_array_almost_equal(rate_grid1.xlim,
                                          np.array([14.9, 15.0, 15.1]))
     np.testing.assert_array_almost_equal(rate_grid1.ylim,
                                          np.array([14.9, 15.0, 15.1]))
     np.testing.assert_array_almost_equal(rate_grid1.zlim,
                                          np.array([0., 10., 20.]))
     np.testing.assert_array_almost_equal(rate_grid1.rates,
                                          np.zeros([2, 2, 2]))
예제 #16
0
 def test_point_location_border(self):
     """
     Checks the correct identifier of the point location for the
     cases that the point is not on the border
     """
     rate_grid1 = RateGrid(self.limits, [POINT_SOURCE],
                           area_discretisation=4.0)
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.9, 14.9)), (0, 0))
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(14.9, 15.0)), (0, 1))
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(15.0, 14.9)), (1, 0))
     self.assertTupleEqual(
         rate_grid1._get_point_location(Point(15.0, 15.0)), (1, 1))
예제 #17
0
 def test_point_rate_simple(self):
     """
     Tests the point rates when the point is inside the limits
     """
     rate_grid1 = RateGrid(self.limits, [POINT_SOURCE],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     expected_rates[1, 1, 0] = 1.0
     rate_grid1.get_rates(5.0)
     np.testing.assert_array_almost_equal(rate_grid1.rates,
                                          expected_rates)
     # Tests the case when Mmin is outside the magnitude range
     rate_grid2 = RateGrid(self.limits, [POINT_SOURCE],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     rate_grid2.get_rates(6.0)
     np.testing.assert_array_almost_equal(rate_grid2.rates,
                                          expected_rates)
     # Tests the case when Mmax is set below the rate of the source
     rate_grid3 = RateGrid(self.limits, [POINT_SOURCE],
                           area_discretisation=4.0)
     expected_rates = np.zeros([2, 2, 2])
     rate_grid3.get_rates(4.0, 4.5)
     np.testing.assert_array_almost_equal(rate_grid3.rates,
                                          expected_rates)