def test_depths_go_to_zero(self): # Depth information is meant to be discarded when a site collection is # created. s1 = Site(location=Point(10, 20, 30), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6) s2 = Site(location=Point(-1.2, -3.4, -5.6), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9) cll = SiteCollection([s1, s2]) cll_sites = list(cll) exp_s1 = Site(location=Point(10, 20, 0.0), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6) exp_s2 = Site(location=Point(-1.2, -3.4, 0.0), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9) for i, s in enumerate([exp_s1, exp_s2]): self.assertEqual(s, cll_sites[i])
def test(self): source_model = os.path.join(os.path.dirname(__file__), 'nankai.xml') groups = nrml.to_python( source_model, SourceConverter(investigation_time=50., rupture_mesh_spacing=2.)) site = Site(Point(135.68, 35.68), 400, z1pt0=100., z2pt5=1.) s_filter = SourceFilter(SiteCollection([site]), {}) imtls = DictArray({'PGV': [20, 40, 80]}) gsim_by_trt = {'Subduction Interface': SiMidorikawa1999SInter()} hcurves = calc_hazard_curves(groups, s_filter, imtls, gsim_by_trt) npt.assert_almost_equal([1.1262869e-01, 3.9968668e-03, 3.1005840e-05], hcurves['PGV'][0])
def test_international_date_line(self): maxdist = IntegrationDistance({'default': 40}) sitecol = SiteCollection([ Site(location=Point(179, 80), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6, backarc=True), Site(location=Point(-179, 80), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9, backarc=False) ]) srcfilter = SourceFilter(sitecol, maxdist) bb1, bb2 = srcfilter.get_bounding_boxes(mag=4) # bounding boxes in the form min_lon, min_lat, max_lon, max_lat aae(bb1, (176.928409, 79.640272, 181.071591, 80.359728)) aae(bb2, (-181.071591, 79.640272, -176.928409, 80.359728))
def setUp(self): d = os.path.dirname(os.path.dirname(__file__)) source_model = os.path.join(d, 'source_model/multi-point-source.xml') [self.sources] = nrml.parse( source_model, SourceConverter(investigation_time=50., rupture_mesh_spacing=2.)) self.site = Site(Point(0.1, 0.1), 800, True, z1pt0=100., z2pt5=1.) self.imt = PGA() self.iml = 0.1 self.truncation_level = 1 self.trt = 'Stable Continental Crust' self.gsims = {self.trt: Campbell2003()}
def test_get_bounding_boxes(self): maxdist = IntegrationDistance({'default': 40}) sitecol = SiteCollection([ Site(location=Point(10, 20, 30), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6, backarc=True), Site(location=Point(-1.2, -3.4, -5.6), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9, backarc=False) ]) srcfilter = SourceFilter(sitecol, maxdist) bb1, bb2 = srcfilter.get_bounding_boxes() # bounding boxes in the form min_lon, min_lat, max_lon, max_lat aae(bb1, (9.6171855, 19.640272, 10.3828145, 20.359728)) aae(bb2, (-1.5603623, -3.759728, -0.8396377, -3.040272))
def example_calc(apply): sitecol = SiteCollection([ Site(Point(30.0, 30.0), 760., True, 1.0, 1.0), Site(Point(30.25, 30.25), 760., True, 1.0, 1.0), Site(Point(30.4, 30.4), 760., True, 1.0, 1.0)]) mfd_1 = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0) mfd_2 = TruncatedGRMFD(4.5, 7.5, 0.1, 3.5, 1.1) sources = [PointSource('001', 'Point1', 'Active Shallow Crust', mfd_1, 1.0, WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0, Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 10.0)])), PointSource('002', 'Point2', 'Active Shallow Crust', mfd_2, 1.0, WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0, Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 10.0)]))] imtls = {'PGA': [0.01, 0.1, 0.2, 0.5, 0.8], 'SA(0.5)': [0.01, 0.1, 0.2, 0.5, 0.8]} gsims = {'Active Shallow Crust': akkar_bommer_2010.AkkarBommer2010()} return calc_hazard_curves(sources, sitecol, imtls, gsims, apply=apply)
def test_international_date_line(self): # from a bug affecting a calculation in New Zealand fname = gettemp(characteric_source) [[src]] = nrml.to_python(fname) os.remove(fname) maxdist = IntegrationDistance.new('200') sitecol = SiteCollection([ Site(location=Point(176.919, -39.489), vs30=760, vs30measured=True, z1pt0=100, z2pt5=5)]) srcfilter = SourceFilter(sitecol, maxdist) sites = srcfilter.get_close_sites(src) self.assertIsNotNone(sites)
def setUp(self): testfile = os.path.join(DATA, 'source_group_cluster.xml') sc = SourceConverter(area_source_discretization=10., rupture_mesh_spacing=10., investigation_time=1.) # This provides a SourceModel self.sg = getattr(nrml.to_python(testfile, sc), 'src_groups') self.imtls = DictArray({'PGA': [0.01, 0.1, 0.2, 0.3, 1.0]}) gsim = SadighEtAl1997() self.gsim_by_trt = {TRT.ACTIVE_SHALLOW_CRUST: gsim} site = Site(Point(1.0, -0.1), 800, z1pt0=30., z2pt5=1.) self.sites = SiteCollection([site])
class JB2009ApplyCorrelationTestCase(unittest.TestCase): SITECOL = SiteCollection([Site(Point(2, -40), 1, True, 1, 1), Site(Point(2, -40.1), 1, True, 1, 1), Site(Point(2, -39.9), 1, True, 1, 1)]) def test(self): numpy.random.seed(13) cormo = JB2009CorrelationModel(vs30_clustering=False) intra_residuals_sampled = numpy.random.normal(size=(3, 100000)) intra_residuals_correlated = cormo.apply_correlation( self.SITECOL, PGA(), intra_residuals_sampled ) inferred_corrcoef = numpy.corrcoef(intra_residuals_correlated) mean = intra_residuals_correlated.mean() std = intra_residuals_correlated.std() self.assertAlmostEqual(mean, 0, delta=0.002) self.assertAlmostEqual(std, 1, delta=0.002) actual_corrcoef = cormo._get_correlation_matrix(self.SITECOL, PGA()) numpy.testing.assert_almost_equal(inferred_corrcoef, actual_corrcoef, decimal=2)
def parse_sites(oqparam): if (oqparam.region is not None): assert oqparam.region.startswith('POLYGON') """ raise ValueError('More than one site is specified (N={len(site_ctx)}). Although ' 'technically faesible using OQ library, this is not reasonable ' 'for VPSHA calculations') """ # Convert region specifications to polygon: reg_lons = [ float(x.split(' ')[0]) for x in oqparam.region[9:-2].split(', ') ] reg_lats = [ float(x.split(' ')[1]) for x in oqparam.region[9:-2].split(', ') ] pts = [Point(lon, lat) for lon, lat in zip(reg_lons, reg_lats)] poly = Polygon(pts) # Convert polygon to sitecolllection: mesh = poly.discretize(oqparam.region_grid_spacing) sites = [ Site(Point(lon, lat, depth), vs30=oqparam.reference_vs30_value, z1pt0=oqparam.reference_depth_to_1pt0km_per_sec, z2pt5=oqparam.reference_depth_to_2pt5km_per_sec) for lon, lat, depth in zip(mesh.lons, mesh.lats, mesh.depths) ] sites_col = SiteCollection(sites) elif isinstance(oqparam.sites, list): sites = [ Site(Point(s[0], s[1], s[2]), vs30=oqparam.reference_vs30_value, z1pt0=oqparam.reference_depth_to_1pt0km_per_sec, z2pt5=oqparam.reference_depth_to_2pt5km_per_sec) for s in oqparam.sites ] sites_col = SiteCollection(sites) else: assert isinstance(oqparam.sites, SiteCollection) sites_col = oqparam.sites return sites_col
def _append_target_sites(self, distances, azimuth, origin_location, vs30, line_azimuth=90., origin_point=(0.5, 0.5), as_log=False, vs30measured=True, z1pt0=None, z2pt5=None, backarc=False): """ Appends the target sites along a line with respect to the rupture, given an already set origin target site """ for offset in distances: target_loc = origin_location.point_at(offset, 0., azimuth) self.target_sites.append( Site(target_loc, vs30, z1pt0, z2pt5, vs30measured=vs30measured, backarc=backarc)) self.target_sites_config = { "TYPE": "Line", "RMAX": distances[-1], "SPACING": np.nan if len(distances) < 2 else distances[1] - distances[0], # FIXME does it make sense? "AZIMUTH": line_azimuth, "ORIGIN": origin_point, "AS_LOG": as_log, "VS30": vs30, "VS30MEASURED": vs30measured, "Z1.0": z1pt0, "Z2.5": z2pt5, "BACKARC": backarc } self.target_sites = SiteCollection(self.target_sites) return self.target_sites
def setUp(self): self.src1 = _create_non_param_sourceA(15., 6.3, PMF([(0.6, 0), (0.4, 1)])) self.src2 = _create_non_param_sourceA(10., 6.0, PMF([(0.7, 0), (0.3, 1)])) self.src3 = _create_non_param_sourceA(10., 6.0, PMF([(0.7, 0), (0.3, 1)]), TRT.GEOTHERMAL) site = Site(Point(0.0, 0.0), 800, True, z1pt0=100., z2pt5=1.) s_filter = SourceFilter(SiteCollection([site]), {}) self.sites = s_filter self.imtls = DictArray({'PGA': [0.01, 0.1, 0.3]}) self.gsim_by_trt = {TRT.ACTIVE_SHALLOW_CRUST: SadighEtAl1997()}
def test_mearn_nearfault_distance_taper(self): rupture = self.make_rupture() site1 = Site(location=Point(27.9, 41), vs30=1200., vs30measured=True, z1pt0=2.36, z2pt5=2.) site2 = Site(location=Point(28.1, 41), vs30=1200., vs30measured=True, z1pt0=2.36, z2pt5=2.) sites = SiteCollection([site1, site2]) fields = ground_motion_fields(rupture, sites, [PGV()], ChiouYoungs2014NearFaultEffect(), truncation_level=0, realizations=1) gmf = fields[PGV()] self.assertAlmostEquals(2.27328758, gmf[0], delta=1e-4) self.assertAlmostEquals(3.38322998, gmf[1], delta=1e-4)
def setUp(self): self.src1 = _create_non_param_sourceA(15., 6.3, PMF([(0.6, 0), (0.4, 1)])) self.src2 = _create_non_param_sourceA(10., 6.0, PMF([(0.7, 0), (0.3, 1)])) self.src3 = _create_non_param_sourceA(10., 6.0, PMF([(0.7, 0), (0.3, 1)]), "Geothermal") site = Site(Point(0.0, 0.0), 800, z1pt0=100., z2pt5=1.) self.sites = SiteCollection([site]) self.imtls = DictArray({'PGA': [0.01, 0.1, 0.3]}) gsim = SadighEtAl1997() self.gsim_by_trt = {"Active Shallow Crust": gsim}
def get_target_sites_mesh(self, maximum_distance, spacing, vs30, vs30measured=True, z1pt0=None, z2pt5=None, backarc=False): """ Renders a two dimensional mesh of points over the rupture surface """ # Get bounding box of dilated rupture lowx, highx, lowy, highy = self._get_limits_maximum_rjb( maximum_distance) # Create bounding box lines and then resample at spacing ewline = Line([Point(lowx, highy, 0.), Point(highx, highy, 0.)]) nsline = Line([Point(lowx, highy, 0.), Point(lowx, lowy, 0.)]) ewline = ewline.resample(spacing) nsline = nsline.resample(spacing) xvals = np.array([pnt.longitude for pnt in ewline.points]) yvals = np.array([pnt.latitude for pnt in nsline.points]) gridx, gridy = np.meshgrid(xvals, yvals) numx, numy = np.shape(gridx) npts = numx * numy gridx = (np.reshape(gridx, npts, 1)).flatten() gridy = (np.reshape(gridy, npts, 1)).flatten() site_list = [] if not z1pt0: #z1pt0 = vs30_to_z1pt0_as08(vs30) z1pt0 = vs30_to_z1pt0_cy14(vs30) if not z2pt5: #z2pt5 = z1pt0_to_z2pt5(z1pt0) z2pt5 = vs30_to_z2pt5_cb14(vs30) for iloc in range(0, npts): site_list.append(Site(Point(gridx[iloc], gridy[iloc], 0.), vs30, vs30measured, z1pt0, z2pt5, backarc=backarc)) self.target_sites = SiteCollection(site_list) self.target_sites_config = { "TYPE": "Mesh", "RMAX": maximum_distance, "SPACING": spacing, "VS30": vs30, "VS30MEASURED": vs30measured, "Z1.0": z1pt0, "Z2.5": z2pt5, "BACKARC": backarc} return self.target_sites
def test_depths_go_to_zero(self): # Depth information is meant to be discarded when a site collection is # created. s1 = Site(location=Point(10, 20, 30), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6) s2 = Site(location=Point(-1.2, -3.4, -5.6), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9) cll = SiteCollection([s1, s2]) cll_sites = list(cll) exp_s1 = Site(location=Point(10, 20, 0.0), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6) exp_s2 = Site(location=Point(-1.2, -3.4, 0.0), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9) for i, s in enumerate([exp_s1, exp_s2]): self.assertEqual(s, cll_sites[i]) # test equality of site collections sc = SiteCollection([exp_s1, exp_s2]) self.assertEqual(cll, sc) # test nonequality of site collections # (see https://github.com/gem/oq-hazardlib/pull/403) sc._vs30 = numpy.array([numpy.nan, numpy.nan]) self.assertNotEqual(cll, sc)
def test_from_sites(self): s1 = Site(location=Point(10, 20, 30), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6) s2 = Site(location=Point(-1.2, -3.4, -5.6), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9) cll = SiteCollection([s1, s2]) assert_eq(cll.vs30, [1.2, 55.4]) assert_eq(cll.vs30measured, [True, False]) assert_eq(cll.z1pt0, [3.4, 66.7]) assert_eq(cll.z2pt5, [5.6, 88.9]) assert_eq(cll.mesh.lons, [10, -1.2]) assert_eq(cll.mesh.lats, [20, -3.4]) assert_eq(cll.mesh.depths, [30, -5.6]) for arr in (cll.vs30, cll.z1pt0, cll.z2pt5): self.assertIsInstance(arr, numpy.ndarray) self.assertEqual(arr.flags.writeable, False) self.assertEqual(arr.dtype, float) for arr in (cll.vs30measured, ): self.assertIsInstance(arr, numpy.ndarray) self.assertEqual(arr.flags.writeable, False) self.assertEqual(arr.dtype, bool) self.assertEqual(len(cll), 2) # test serialization to hdf5 fd, fpath = tempfile.mkstemp(suffix='.hdf5') os.close(fd) with hdf5.File(fpath, 'w') as f: f['folder'] = dict(sitecol=cll, b=[2, 3]) newcll = f['folder/sitecol'] self.assertEqual(newcll, cll) self.assertEqual(list(f['folder/b']), [2, 3]) os.remove(fpath)
def test_point_surface(self): sid = 0 name = 'test' trt = TRT.ACTIVE_SHALLOW_CRUST mfd = ArbitraryMFD([7.0], [1.]) rms = 2.5 msr = WC1994() rar = 1.0 tom = PoissonTOM(1.) usd = 0.0 lsd = 20.0 loc = Point(0.0, 0.0) npd = PMF([(1.0, NodalPlane(90., 90., 90.))]) hyd = PMF([(1.0, 10.)]) src = PointSource(sid, name, trt, mfd, rms, msr, rar, tom, usd, lsd, loc, npd, hyd) rups = [r for r in src.iter_ruptures()] # Compute distances param = 'closest_point' sites = SiteCollection( [Site(Point(0.0, 0.0, 0.0)), Site(Point(-0.2, 0.0, 0.0))]) dsts = get_distances(rups[0], sites, param) # Check first point msg = 'The longitude of the first point is wrong' self.assertTrue(abs(dsts[0, 0] - 0.0) < 1e-2, msg) msg = 'The latitude of the first point is wrong' self.assertTrue(abs(dsts[0, 1] - 0.0) < 1e-2, msg) # Check second point msg = 'The longitude of the second point is wrong' self.assertTrue(abs(dsts[1, 0] + 0.1666) < 1e-2, msg) msg = 'The latitude of the second point is wrong' self.assertTrue(abs(dsts[1, 1] - 0.0) < 1e-2, msg)
def test_international_date_line(self): maxdist = IntegrationDistance({ 'default': [(3, 30), (4, 40), (5, 100), (6, 200), (7, 300), (8, 400)] }) sitecol = SiteCollection([ Site(location=Point(179, 80), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6, backarc=True), Site(location=Point(-179, 80), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9, backarc=False) ]) srcfilter = SourceFilter(sitecol, maxdist) bb1, bb2 = srcfilter.get_bounding_boxes(mag=4.5) # bounding boxes in the form min_lon, min_lat, max_lon, max_lat aae(bb1, (173.8210225, 79.10068, 184.1789775, 80.89932)) aae(bb2, (-184.1789775, 79.10068, -173.8210225, 80.89932))
def test_get_bounding_boxes(self): maxdist = IntegrationDistance({ 'default': [(3, 30), (4, 40), (5, 100), (6, 200), (7, 300), (8, 400)] }) sitecol = SiteCollection([ Site(location=Point(10, 20, 30), vs30=1.2, vs30measured=True, z1pt0=3.4, z2pt5=5.6, backarc=True), Site(location=Point(-1.2, -3.4, -5.6), vs30=55.4, vs30measured=False, z1pt0=66.7, z2pt5=88.9, backarc=False) ]) srcfilter = SourceFilter(sitecol, maxdist) bb1, bb2 = srcfilter.get_bounding_boxes(mag=4.5) # bounding boxes in the form min_lon, min_lat, max_lon, max_lat aae(bb1, (9.0429636, 19.10068, 10.9570364, 20.89932)) aae(bb2, (-2.1009057, -4.29932, -0.2990943, -2.50068))
def test(self): # mutually exclusive ruptures d = os.path.dirname(os.path.dirname(__file__)) tmps = 'nonparametric-source-mutex-ruptures.xml' source_model = os.path.join(d, 'source_model', tmps) groups = nrml.to_python(source_model, SourceConverter( investigation_time=50., rupture_mesh_spacing=2.)) site = Site(Point(143.5, 39.5), 800, z1pt0=100., z2pt5=1.) sitecol = SiteCollection([site]) imtls = DictArray({'PGA': [0.01, 0.1, 0.2, 0.5]}) gsim_by_trt = {'Some TRT': Campbell2003()} hcurves = calc_hazard_curves(groups, sitecol, imtls, gsim_by_trt) # expected results obtained with an ipython notebook expected = [4.3998728e-01, 1.1011728e-01, 7.5495312e-03, 8.5812844e-06] npt.assert_almost_equal(hcurves['PGA'][0], expected)
def test_correlation_with_total_stddev(self): mean1 = 10 mean2 = 14 inter = 1e-300 intra1 = 0.2 intra2 = 1.6 p1 = Point(0, 0) p2 = Point(0, 0.3) sites = [ Site(p1, mean1, False, inter, intra1), Site(p2, mean2, False, inter, intra2) ] self.sites = SiteCollection(sites) numpy.random.seed(41) cormo = JB2009CorrelationModel(vs30_clustering=False) gsim = FakeGSIMTotalStdDev(self) with self.assertRaises(CorrelationButNoInterIntraStdDevs): ground_motion_fields(self.rupture, self.sites, [self.imt1], gsim, truncation_level=None, realizations=6000, correlation_model=cormo)
def setUp(self): self.truncation_level = 3.4 self.imts = {imt.PGA(): [1, 2, 3], imt.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], time_span=self.time_span) self.source2 = self.FakeSource(2, [rup21], time_span=self.time_span) self.sources = iter([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}
def test(self): site = Site(Point(0, 0), vs30=760., z1pt0=48.0, z2pt5=0.607, vs30measured=True) sitecol = SiteCollection([site]) imtls = {"PGA": valid.logscale(.1, 1, 10)} gsim = BooreAtkinson2008() [hcurve] = calc_hazard_curves([asource], sitecol, imtls, {"Stable Continental Crust": gsim}) exp = [ 0.879914, 0.747273, 0.566655, 0.376226, 0.217617, 0.110198, 0.049159, 0.019335, 0.006663, 0.001989 ] numpy.testing.assert_allclose(hcurve['PGA'], exp, atol=1E-5)
def setUp(self): self.imt = "SA(0.15)" points = [Point(0, 0), Point(10, 10), Point(20, 20)] sites = [Site(point, 10, False, 2, 3, id=i) for i, point in enumerate(points)] self.sites = models.SiteCollection(sites) assets = [mock.Mock] * 5 self.sites_assets = ((0, assets[0:1]), (1, assets[1:]), (2, assets[2:])) self.gsims = mock.Mock() self.gsims.__getitem__ = mock.Mock(return_value=mock.Mock()) self.cormo = JB2009CorrelationModel(vs30_clustering=False)
def point_at_distance(self, model, distance, vs30, line_azimuth=90., origin_point=(0.5, 0.), vs30measured=True, z1pt0=None, z2pt5=None, backarc=False): """ Generates a point at a given epicentral distance """ azimuth, origin_point, z1pt0, z2pt5 = _setup_site_peripherals( line_azimuth, origin_point, vs30, z1pt0, z2pt5, model.strike, model.surface) return SiteCollection([Site( model.hypocentre.point_at(distance, 0., line_azimuth), vs30, vs30measured, z1pt0, z2pt5, backarc=backarc)])
def get_site_collection(cls, nelements, **kwargs): """ Returns a site collection. :param int nelements: Number of sites included in the site collection """ sites = [] for n in range(nelements): s = Site(Point(0, 0)) for key in kwargs: if np.size(kwargs[key]) > 1: setattr(s, key, kwargs[key][n]) else: setattr(s, key, kwargs[key]) sites.append(s) return SiteCollection(sites)
def setUp(self): self.ruptures_and_poes1 = [ ([0, 0, 0], self.FakeRupture(5, 0.1, 3, 22, 44)), ([0.1, 0.2, 0.1], self.FakeRupture(5, 0.2, 11, 22, 44)), ([0, 0, 0.3], self.FakeRupture(5, 0.01, 12, 22, 45)), ([0, 0.05, 0.001], self.FakeRupture(5, 0.33, 13, 22, 45)), ([0, 0, 0], self.FakeRupture(9, 0.4, 14, 21, 44)), ([0, 0, 0.02], self.FakeRupture(5, 0.05, 11, 21, 44)), ([0.04, 0.1, 0.04], self.FakeRupture(5, 0.53, 11, 21, 45)), ([0.2, 0.3, 0.2], self.FakeRupture(5, 0.066, 10, 21, 45)), ([0.3, 0.4, 0.3], self.FakeRupture(6, 0.1, 12, 22, 44)), ([0, 0, 0.1], self.FakeRupture(6, 0.1, 12, 21, 44)), ([0, 0, 0], self.FakeRupture(6, 0.1, 11, 22, 45)), ] self.ruptures_and_poes2 = [ ([0, 0.1, 0.04], self.FakeRupture(8, 0.04, 5, 11, 45)), ([0.1, 0.5, 0.1], self.FakeRupture(7, 0.03, 5, 11, 46)) ] self.time_span = 10 self.tom = PoissonTOM(time_span=10) self.source1 = self.FakeSource( 1, [rupture for poes, rupture in self.ruptures_and_poes1], self.tom, 'trt1') self.source2 = self.FakeSource( 2, [rupture for poes, rupture in self.ruptures_and_poes2], self.tom, 'trt2') self.disagreggated_poes = dict( (rupture, poes) for (poes, rupture) in self.ruptures_and_poes1 + self.ruptures_and_poes2) self.site = Site(Point(0, 0), 2, False, 4, 5) self.iml, self.imt, self.truncation_level = (object(), object(), object()) gsim = self.FakeGSIM(self.iml, self.imt, self.truncation_level, n_epsilons=3, disaggregated_poes=self.disagreggated_poes) self.gsim = gsim self.gsims = {'trt1': gsim, 'trt2': gsim} self.sources = [self.source1, self.source2] self.orig_make_contexts = ContextMaker.make_contexts ContextMaker.make_contexts = lambda self, sites, rupture: ( sites, rupture, None)
def test(self): sitecol = SiteCollection([ Site(Point(-65.13490, 0.0), vs30=760., z1pt0=48.0, z2pt5=0.607, vs30measured=True) ]) mfd = ArbitraryMFD([6.0], [0.01604252]) trace = Line([Point(-65.0000, -0.11240), Point(-65.000, 0.11240)]) # 1.0 km Mesh Spacing mesh_spacing = 1.0 msr = PeerMSR() sources = [ SimpleFaultSource("001", "PEER Fault Set 2.5", "Active Shallow Crust", mfd, mesh_spacing, msr, 2.0, PoissonTOM(1.0), 0.0, 12., trace, 90., 0.) ] imtls = { "PGA": [ 0.001, 0.01, 0.05, 0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.0 ] } gmpe = ChiouYoungs2014PEER(mixture_model={ "factors": [0.8, 1.2], "weights": [0.5, 0.5] }) hcm = calc_hazard_curves(sources, sitecol, imtls, {"Active Shallow Crust": gmpe}) # Match against the benchmark is not exact - but differences in the # log space should be on the order of less than 0.04 % in log space expected = numpy.array([ -4.140470001, -4.140913368, -4.259457496, -4.724733842, -5.900747959, -7.734816415, -9.019329629, -10.03864778, -10.90333404, -11.83885783, -12.65826442, -14.05429951, -15.22535996, -16.23988897, -17.94685518, -19.36079032, -20.57460101, -21.64201335 ]) expected = numpy.around(expected, 5) hcm_lnpga = numpy.around(numpy.log(hcm["PGA"].flatten()), 5) perc_diff = 100.0 * ((hcm_lnpga / expected) - 1.0) numpy.testing.assert_allclose(perc_diff, numpy.zeros(len(perc_diff)), atol=0.04)
def test(self): d = os.path.dirname(os.path.dirname(__file__)) source_model = os.path.join(d, 'source_model/multi-point-source.xml') groups = nrml.to_python(source_model, SourceConverter( investigation_time=50., rupture_mesh_spacing=2.)) site = Site(Point(0.1, 0.1), 800, True, z1pt0=100., z2pt5=1.) sitecol = SiteCollection([site]) imtls = DictArray({'PGA': [0.01, 0.02, 0.04, 0.08, 0.16]}) gsim_by_trt = {'Stable Continental Crust': Campbell2003()} hcurves = calc_hazard_curves(groups, sitecol, imtls, gsim_by_trt) expected = [0.99999778, 0.9084039, 0.148975348, 0.0036909656, 2.76326e-05] npt.assert_almost_equal(hcurves['PGA'][0], expected) # splitting in point sources [[mps1, mps2]] = groups psources = list(mps1) + list(mps2) hcurves = calc_hazard_curves(psources, sitecol, imtls, gsim_by_trt) npt.assert_almost_equal(hcurves['PGA'][0], expected)