def test_get_mean_and_stddevs(self): """ Tests mean and standard deviations without amplification """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() rctx = RuptureContext() rctx.mag = 6.0 dctx = DistancesContext() # Test values at the given distances and those outside range dctx.rjb = np.array([0.5, 1.0, 10.0, 100.0, 500.0]) sctx = SitesContext() stddevs = [const.StdDev.TOTAL] expected_mean = np.array([2.0, 2.0, 1.0, 0.5, 1.0E-20]) # PGA mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx, imt_module.PGA(), stddevs) np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5) np.testing.assert_array_almost_equal(sigma[0], 0.5 * np.ones(5), 5) # SA mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx, imt_module.SA(1.0), stddevs) np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5) np.testing.assert_array_almost_equal(sigma[0], 0.8 * np.ones(5), 5) # PGV mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx, imt_module.PGV(), stddevs) np.testing.assert_array_almost_equal(np.exp(mean), 10. * expected_mean, 5) np.testing.assert_array_almost_equal(sigma[0], 0.5 * np.ones(5), 5)
def test_correct_instantiation(self): """ Verify that the data is loaded successfully """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() np.testing.assert_array_almost_equal(gsim.distances, self.hdf5["Distances"][:]) np.testing.assert_array_almost_equal(gsim.m_w, self.hdf5["Mw"][:]) self.assertEqual(gsim.distance_type, "rjb") self.assertSetEqual(gsim.REQUIRES_SITES_PARAMETERS, set(("vs30",))) self.assertSetEqual(gsim.REQUIRES_DISTANCES, set(("rjb",))) self.assertSetEqual( gsim.DEFINED_FOR_INTENSITY_MEASURE_TYPES, set((imt_module.PGA, imt_module.PGV, imt_module.SA))) self.assertSetEqual(gsim.DEFINED_FOR_STANDARD_DEVIATION_TYPES, set((const.StdDev.TOTAL,))) # Verify correctly parsed IMLs and standard deviations for iml in ["PGA", "PGV", "SA", "T"]: np.testing.assert_array_almost_equal( gsim.imls[iml], self.hdf5["IMLs/" + iml][:]) np.testing.assert_array_almost_equal( gsim.stddevs["Total"][iml], self.hdf5["Total/" + iml][:])
def test_retreival_tables_good_no_interp(self): """ Tests the retreival of the IML tables for 'good' conditions without applying magnitude interpolations """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() # PGA np.testing.assert_array_almost_equal( gsim._return_tables(6.0, imt_module.PGA(), "IMLs"), np.array([2., 1., 0.5])) # PGV np.testing.assert_array_almost_equal( gsim._return_tables(6.0, imt_module.PGV(), "IMLs"), np.array([20., 10., 5.]), 5) # SA(1.0) np.testing.assert_array_almost_equal( gsim._return_tables(6.0, imt_module.SA(1.0), "IMLs"), np.array([2.0, 1., 0.5])) # Also for standard deviations np.testing.assert_array_almost_equal( gsim._return_tables(6.0, imt_module.PGA(), "Total"), 0.5 * np.ones(3)) np.testing.assert_array_almost_equal( gsim._return_tables(6.0, imt_module.SA(1.0), "Total"), 0.8 * np.ones(3))
def test_get_mean_and_stddevs_good(self): """ Tests the full execution of the GMPE tables for valid data """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() rctx = RuptureContext() rctx.mag = 6.0 rctx.rake = 90.0 dctx = DistancesContext() # Test values at the given distances and those outside range dctx.rjb = np.array([0.5, 1.0, 10.0, 100.0, 500.0]) sctx = SitesContext() stddevs = [const.StdDev.TOTAL] expected_mean = np.array([20.0, 20.0, 10.0, 5.0, 1.0E-19]) # PGA mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx, imt_module.PGA(), stddevs) np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5) np.testing.assert_array_almost_equal(sigma[0], 0.25 * np.ones(5), 5) # SA mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx, imt_module.SA(1.0), stddevs) np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5) np.testing.assert_array_almost_equal(sigma[0], 0.4 * np.ones(5), 5)
def test_instantiation(self): """ Tests instantiation without amplification """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() self.assertIsNone(gsim.amplification) self.assertSetEqual(gsim.REQUIRES_SITES_PARAMETERS, set(())) self.assertSetEqual(gsim.REQUIRES_RUPTURE_PARAMETERS, set(("mag", )))
def test_instantiation(self): """ Tests instantiation without amplification """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() self.assertIsNone(gsim.amplification) self.assertSetEqual(gsim.REQUIRES_SITES_PARAMETERS, set(())) self.assertSetEqual(gsim.REQUIRES_RUPTURE_PARAMETERS, set(("mag",)))
def test_instantiation(self): """ Tests instantiation of class """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() expected_rupture_set = set(("mag", "rake")) self.assertSetEqual(gsim.REQUIRES_RUPTURE_PARAMETERS, expected_rupture_set) self.assertEqual(gsim.amplification.parameter, "rake") self.assertEqual(gsim.amplification.element, "Rupture") self.assertSetEqual(gsim.REQUIRES_SITES_PARAMETERS, set())
def test_retreival_tables_outside_period_range(self): """ Tests that an error is raised when inputting a period value outside the supported range """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() with self.assertRaises(ValueError) as ve: gsim._return_tables(6.0, imt_module.SA(2.5), "IMLs") self.assertEqual( str(ve.exception), "Spectral period 2.500 outside of valid range (0.100 to 2.000)")
def test_retreival_tables_outside_mag_range(self): """ Tests that an error is raised when inputting a magnitude value outside the supported range """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() with self.assertRaises(ValueError) as ve: gsim._return_tables(4.5, imt_module.PGA(), "IMLs") self.assertEqual( str(ve.exception), "Magnitude 4.50 outside of supported range (5.00 to 7.00)")
def test_instantiation(self): """ Runs both instantiation checks The table file contains data for Inter and intra event standard deviation, as well as an IMT that is not recognised by OpenQuake """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() expected_stddev_set = set( (const.StdDev.TOTAL, const.StdDev.INTER_EVENT, const.StdDev.INTRA_EVENT)) self.assertSetEqual(gsim.DEFINED_FOR_STANDARD_DEVIATION_TYPES, expected_stddev_set) expected_imt_set = set((imt_module.PGA, imt_module.PGV, imt_module.SA)) self.assertSetEqual(gsim.DEFINED_FOR_INTENSITY_MEASURE_TYPES, expected_imt_set)
def test_instantiation(self): """ Runs both instantiation checks The table file contains data for Inter and intra event standard deviation, as well as an IMT that is not recognised by OpenQuake """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() expected_stddev_set = set((const.StdDev.TOTAL, const.StdDev.INTER_EVENT, const.StdDev.INTRA_EVENT)) self.assertSetEqual(gsim.DEFINED_FOR_STANDARD_DEVIATION_TYPES, expected_stddev_set) expected_imt_set = set((imt_module.PGA, imt_module.PGV, imt_module.SA)) self.assertSetEqual(gsim.DEFINED_FOR_INTENSITY_MEASURE_TYPES, expected_imt_set)
def test_get_mean_stddevs_unsupported_stddev(self): """ Tests the execution of the GMPE with an unsupported standard deviation type """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() rctx = RuptureContext() rctx.mag = 6.0 dctx = DistancesContext() # Test values at the given distances and those outside range dctx.rjb = np.array([0.5, 1.0, 10.0, 100.0, 500.0]) sctx = SitesContext() sctx.vs30 = 1000. * np.ones(5) stddevs = [const.StdDev.TOTAL, const.StdDev.INTER_EVENT] with self.assertRaises(ValueError) as ve: gsim.get_mean_and_stddevs(sctx, rctx, dctx, imt_module.PGA(), stddevs) self.assertEqual(str(ve.exception), "Standard Deviation type Inter event not supported")
def test_retreival_tables_good_interp(self): """ Tests the retreival of the IML tables for 'good' conditions with magnitude interpolations """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() expected_table_pgv = np.array([midpoint(20., 40.), midpoint(10., 20.), midpoint(5., 10.)]) np.testing.assert_array_almost_equal( gsim._return_tables(6.5, imt_module.PGV(), "IMLs"), expected_table_pgv, 5) expected_table_sa1 = np.array([midpoint(2., 4.), midpoint(1., 2.), midpoint(0.5, 1.)]) np.testing.assert_array_almost_equal( gsim._return_tables(6.5, imt_module.SA(1.0), "IMLs"), expected_table_sa1)
def test_retreival_tables_good_interp(self): """ Tests the retreival of the IML tables for 'good' conditions with magnitude interpolations """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() expected_table_pgv = np.array( [midpoint(20., 40.), midpoint(10., 20.), midpoint(5., 10.)]) np.testing.assert_array_almost_equal( gsim._return_tables(6.5, imt_module.PGV(), "IMLs"), expected_table_pgv, 5) expected_table_sa1 = np.array( [midpoint(2., 4.), midpoint(1., 2.), midpoint(0.5, 1.)]) np.testing.assert_array_almost_equal( gsim._return_tables(6.5, imt_module.SA(1.0), "IMLs"), expected_table_sa1)
def test_correct_instantiation(self): """ Verify that the data is loaded successfully """ gsim = GMPETable(gmpe_table=self.TABLE_FILE) gsim.init() np.testing.assert_array_almost_equal(gsim.distances, self.hdf5["Distances"][:]) np.testing.assert_array_almost_equal(gsim.m_w, self.hdf5["Mw"][:]) self.assertEqual(gsim.distance_type, "rjb") self.assertSetEqual(gsim.REQUIRES_SITES_PARAMETERS, set(("vs30", ))) self.assertSetEqual(gsim.REQUIRES_DISTANCES, set(("rjb", ))) self.assertSetEqual( gsim.DEFINED_FOR_INTENSITY_MEASURE_TYPES, set((imt_module.PGA, imt_module.PGV, imt_module.SA))) self.assertSetEqual(gsim.DEFINED_FOR_STANDARD_DEVIATION_TYPES, set((const.StdDev.TOTAL, ))) # Verify correctly parsed IMLs and standard deviations for iml in ["PGA", "PGV", "SA", "T"]: np.testing.assert_array_almost_equal(gsim.imls[iml], self.hdf5["IMLs/" + iml][:]) np.testing.assert_array_almost_equal(gsim.stddevs["Total"][iml], self.hdf5["Total/" + iml][:])