def downsample_mesh(mesh, tol=1.0): """ Returns a mesh sampled at a lower resolution - if the difference in azimuth is larger than the specified tolerance a turn is assumed :returns: Downsampled mesh as instance of :class: openquake.hazardlib.geo.mesh.RectangularMesh """ idx = _find_turning_points(mesh, tol) if mesh.depths is not None: return RectangularMesh(lons=mesh.lons[:, idx], lats=mesh.lats[:, idx], depths=mesh.depths[:, idx]) else: return RectangularMesh(lons=mesh.lons[:, idx], lats=mesh.lats[:, idx])
def _get_finite_top_rupture(mesh): ok = numpy.isfinite(mesh.lons.flat) if numpy.all(ok): return mesh[0:1] ok = numpy.isfinite(mesh.lons[0, :]) return RectangularMesh(mesh.lons[0, ok], mesh.lats[0, ok], mesh.depths[0, ok])
def test_non_parametric_source(self): # non-parametric source equivalent to case 2 simple fault source data = test_data.SET1_CASE2_SOURCE_DATA ruptures = [] for i in range(data['num_rups_dip']): for j in range(data['num_rups_strike']): lons = data['lons'] lats = data['lats'][j] depths = data['depths'][i] mesh = RectangularMesh(lons, lats, depths) surf = SimpleFaultSurface(mesh) hypo = Point( data['hypo_lons'][i, j], data['hypo_lats'][i, j], data['hypo_depths'][i, j] ) rup = BaseRupture(data['mag'], data['rake'], data['tectonic_region_type'], hypo, surf, data['source_typology']) ruptures.append((rup, data['pmf'])) npss = NonParametricSeismicSource( 'id', 'name', data['tectonic_region_type'], ruptures ) sites = SiteCollection([ test_data.SET1_CASE1TO9_SITE1, test_data.SET1_CASE1TO9_SITE2, test_data.SET1_CASE1TO9_SITE3, test_data.SET1_CASE1TO9_SITE4, test_data.SET1_CASE1TO9_SITE5, test_data.SET1_CASE1TO9_SITE6, test_data.SET1_CASE1TO9_SITE7 ]) gsims = {const.TRT.ACTIVE_SHALLOW_CRUST: SadighEtAl1997()} truncation_level = 0 imts = {str(test_data.IMT): test_data.SET1_CASE2_IMLS} curves = calc_hazard_curves( [npss], sites, imts, gsims, truncation_level) s1hc, s2hc, s3hc, s4hc, s5hc, s6hc, s7hc = curves[str(test_data.IMT)] assert_hazard_curve_is(self, s1hc, test_data.SET1_CASE2_SITE1_POES, atol=3e-3, rtol=1e-5) assert_hazard_curve_is(self, s2hc, test_data.SET1_CASE2_SITE2_POES, atol=2e-5, rtol=1e-5) assert_hazard_curve_is(self, s3hc, test_data.SET1_CASE2_SITE3_POES, atol=2e-5, rtol=1e-5) assert_hazard_curve_is(self, s4hc, test_data.SET1_CASE2_SITE4_POES, atol=1e-3, rtol=1e-5) assert_hazard_curve_is(self, s5hc, test_data.SET1_CASE2_SITE5_POES, atol=1e-3, rtol=1e-5) assert_hazard_curve_is(self, s6hc, test_data.SET1_CASE2_SITE6_POES, atol=1e-3, rtol=1e-5) assert_hazard_curve_is(self, s7hc, test_data.SET1_CASE2_SITE7_POES, atol=2e-5, rtol=1e-5)
def test(self): surface_mesh = RectangularMesh(self.POLYGON.lons.reshape((2, 2)), self.POLYGON.lats.reshape((2, 2)), depths=None) class rupture(object): class surface(object): @classmethod def get_joyner_boore_distance(cls, mesh): return surface_mesh.get_joyner_boore_distance(mesh) filtered = filters.filter_sites_by_distance_to_rupture( rupture=rupture, integration_distance=1.01, sites=self.sitecol) numpy.testing.assert_array_equal(filtered.indices, [0, 1, 2, 3, 4, 5, 6, 7, 8])
def _construct_surface(lons, lats, upper_depth, lower_depth): """ Utility method that constructs and return a simple fault surface with top edge specified by `lons` and `lats` and extending vertically from `upper_depth` to `lower_depth`. The underlying mesh is built by repeating the same coordinates (`lons` and `lats`) at the two specified depth levels. """ depths = np.array( [np.zeros_like(lons) + upper_depth, np.zeros_like(lats) + lower_depth]) mesh = RectangularMesh(np.tile(lons, (2, 1)), np.tile(lats, (2, 1)), depths) return SimpleFaultSurface(mesh)