def test1(self): site1_pga_poe_expected = [0.0639157, 0.03320212, 0.02145989] site2_pga_poe_expected = [0.06406232, 0.02965879, 0.01864331] site1_pgd_poe_expected = [0.16146619, 0.1336553] site2_pgd_poe_expected = [0.15445961, 0.13437589] curves = hazard_curves_poissonian(self.sources, self.sites, self.imts, self.time_span, self.gsims, self.truncation_level) self.assertIsInstance(curves, dict) self.assertEqual(set(curves.keys()), set([imt.PGA(), imt.PGD()])) pga_curves = curves[imt.PGA()] self.assertIsInstance(pga_curves, numpy.ndarray) self.assertEqual(pga_curves.shape, (2, 3)) # two sites, three IMLs site1_pga_poe, site2_pga_poe = pga_curves self.assertTrue(numpy.allclose(site1_pga_poe, site1_pga_poe_expected), str(site1_pga_poe)) self.assertTrue(numpy.allclose(site2_pga_poe, site2_pga_poe_expected), str(site2_pga_poe)) pgd_curves = curves[imt.PGD()] self.assertIsInstance(pgd_curves, numpy.ndarray) self.assertEqual(pgd_curves.shape, (2, 2)) # two sites, two IMLs site1_pgd_poe, site2_pgd_poe = pgd_curves self.assertTrue(numpy.allclose(site1_pgd_poe, site1_pgd_poe_expected), str(site1_pgd_poe)) self.assertTrue(numpy.allclose(site2_pgd_poe, site2_pgd_poe_expected), str(site2_pgd_poe))
def setUp(self): self.orig_make_contexts = ContextMaker.make_contexts ContextMaker.make_contexts = lambda self, sites, rupture: ( FakeSiteContext(sites), rupture, None) self.truncation_level = 3.4 self.imts = {'PGA': [1, 2, 3], 'PGD': [2, 4]} self.time_span = 49.2 rup11 = self.FakeRupture(0.23, const.TRT.ACTIVE_SHALLOW_CRUST) rup12 = self.FakeRupture(0.15, const.TRT.ACTIVE_SHALLOW_CRUST) rup21 = self.FakeRupture(0.04, const.TRT.VOLCANIC) self.source1 = self.FakeSource(1, [rup11, rup12], self.time_span, const.TRT.ACTIVE_SHALLOW_CRUST) self.source2 = self.FakeSource(2, [rup21], self.time_span, const.TRT.VOLCANIC) self.sources = [self.source1, self.source2] site1 = Site(Point(10, 20), 1, True, 2, 3) site2 = Site(Point(20, 30), 2, False, 4, 5) self.sites = SiteCollection([site1, site2]) gsim1 = self.FakeGSIM( self.truncation_level, self.imts, poes={ (site1.location.latitude, rup11, imt.PGA()): [0.1, 0.05, 0.03], (site2.location.latitude, rup11, imt.PGA()): [0.11, 0.051, 0.034], (site1.location.latitude, rup12, imt.PGA()): [0.12, 0.052, 0.035], (site2.location.latitude, rup12, imt.PGA()): [0.13, 0.053, 0.036], (site1.location.latitude, rup11, imt.PGD()): [0.4, 0.33], (site2.location.latitude, rup11, imt.PGD()): [0.39, 0.331], (site1.location.latitude, rup12, imt.PGD()): [0.38, 0.332], (site2.location.latitude, rup12, imt.PGD()): [0.37, 0.333], }) gsim2 = self.FakeGSIM(self.truncation_level, self.imts, poes={ (site1.location.latitude, rup21, imt.PGA()): [0.5, 0.3, 0.2], (site2.location.latitude, rup21, imt.PGA()): [0.4, 0.2, 0.1], (site1.location.latitude, rup21, imt.PGD()): [0.24, 0.08], (site2.location.latitude, rup21, imt.PGD()): [0.14, 0.09], }) self.gsims = { const.TRT.ACTIVE_SHALLOW_CRUST: gsim1, const.TRT.VOLCANIC: gsim2 }