def test_rx(self): mesh = Mesh(numpy.array([-118.]), numpy.array([33])) # 1 point surf18 = MultiSurface.from_csv(cd / 'msurface18.csv') # 2 planes surf19 = MultiSurface.from_csv(cd / 'msurface19.csv') # 2 planes surf20 = MultiSurface.from_csv(cd / 'msurface20.csv') # 1 plane rx18 = surf18.get_rx_distance(mesh)[0] rx19 = surf19.get_rx_distance(mesh)[0] rx20 = surf20.get_rx_distance(mesh)[0] aac([rx18, rx19, rx20], [51.610675, 54.441119, -60.205692]) surfa = MultiSurface(surf18.surfaces + surf19.surfaces) surfb = MultiSurface(surf19.surfaces + surf20.surfaces) rxa = surfa.get_rx_distance(mesh)[0] rxb = surfb.get_rx_distance(mesh)[0] aac([rxa, rxb], [53.034889, -56.064366])
def test_rjb(self): mesh = Mesh(numpy.array([-118.]), numpy.array([33])) # 1 point surf18 = MultiSurface.from_csv(cd / 'msurface18.csv') # 2 planes surf19 = MultiSurface.from_csv(cd / 'msurface19.csv') # 2 planes surf20 = MultiSurface.from_csv(cd / 'msurface20.csv') # 1 plane rjb18 = surf18.get_joyner_boore_distance(mesh)[0] rjb19 = surf19.get_joyner_boore_distance(mesh)[0] rjb20 = surf20.get_joyner_boore_distance(mesh)[0] aac([rjb18, rjb19, rjb20], [85.676294, 89.225542, 92.937021]) surfa = MultiSurface(surf18.surfaces + surf19.surfaces) surfb = MultiSurface(surf19.surfaces + surf20.surfaces) rjba = surfa.get_joyner_boore_distance(mesh)[0] rjbb = surfb.get_joyner_boore_distance(mesh)[0] aac([rjba, rjbb], [85.676294, 89.225542])
def test_bounding_box(self): surf = MultiSurface(self.surfaces_mesh2D) west, east, north, south = surf.get_bounding_box() self.assertEqual(0.1, west) self.assertEqual(4.6, east) self.assertEqual(5.6, north) self.assertEqual(1.1, south)
def get_rupture_enclosing_polygon(self, dilation=0): """ Create instance of :class:`openquake.hazardlib.geo.surface.multi.MultiSurface` from all ruptures' surfaces and compute its bounding box. Calculate convex hull of bounding box, and return it dilated by ``dilation``. :param dilation: A buffer distance in km to extend the polygon borders to. :returns: Instance of :class:`openquake.hazardlib.geo.polygon.Polygon`. """ surfaces = [] for rup, _ in self.data: if isinstance(rup.surface, MultiSurface): for s in rup.surface.surfaces: surfaces.append(s) else: surfaces.append(rup.surface) multi_surf = MultiSurface(surfaces) west, east, north, south = multi_surf.get_bounding_box() mesh = RectangularMesh(numpy.array([[west, east], [west, east]]), numpy.array([[north, north], [south, south]]), None) poly = mesh.get_convex_hull() return poly if dilation == 0 else poly.dilate(dilation)
def setUp(self): # First surface - Almost vertical dipping to south prf1 = Line([Point(0, 0, 0), Point(0, -0.00001, 20.)]) prf2 = Line([Point(0.15, 0, 0), Point(0.15, -0.00001, 20.)]) prf3 = Line([Point(0.3, 0, 0), Point(0.3, -0.00001, 20.)]) sfca = KiteSurface.from_profiles([prf1, prf2, prf3], 1., 1.) self.msrf = MultiSurface([sfca])
def iter_ruptures(self, fromidx=0, untilidx=None, **kwargs): """ An iterator for the ruptures. :param fromidx: start :param untilidx: stop """ # check if 'sections' not in self.__dict__: raise RuntimeError('You forgot to call set_sections in %s!' % self) # iter on the ruptures untilidx = len(self.mags) if untilidx is None else untilidx s = self.sections for i in range(fromidx, untilidx): idxs = self.rupture_idxs[i] if len(idxs) == 1: sfc = self.sections[idxs[0]].surface else: sfc = MultiSurface([s[idx].surface for idx in idxs]) rake = self.rakes[i] hypo = self.sections[idxs[0]].surface.get_middle_point() yield NonParametricProbabilisticRupture(self.mags[i], rake, self.tectonic_region_type, hypo, sfc, self.pmfs[i])
def test_get_closest_points_mesh1D(self): surf = MultiSurface(self.surfaces_mesh1D) closest_points = surf.get_closest_points(self.mesh1D) numpy.testing.assert_equal(closest_points.lons, numpy.array([0.1, 0.2, 2.3])) numpy.testing.assert_equal(closest_points.lats, numpy.array([1.1, 1.2, 3.3])) numpy.testing.assert_equal(closest_points.depths, numpy.array([1.1, 1.2, 2.3]))
def test_middle_point_multi_surfaces(self): surf = MultiSurface([ PlanarSurface(1.0, 0.0, 90.0, Point(0.0, -1.0, 0.0), Point(0.0, 1.0, 0.0), Point(0.0, 1.0, 10.0), Point(0.0, -1.0, 10.0)), PlanarSurface(1.0, 135.0, 90.0, Point(0.0, -1.0, 0.0), Point(1.0, 1.0, 0.0), Point(1.0, 1.0, 10.0), Point(0.0, -1.0, 10.0)) ]) middle_point = surf.get_middle_point() self.assertTrue(Point(0.5, 0.0, 5.0) == middle_point)
def get_ucerf_rupture(self, hdf5, iloc, src_filter): """ :param hdf5: Source Model hdf5 object as instance of :class: h5py.File :param int iloc: Location of the rupture plane in the hdf5 file :param src_filter: Sites for consideration and maximum distance """ ctl = self.control mesh_spacing = ctl.mesh_spacing trt = ctl.tectonic_region_type ridx = hdf5[self.idx_set["geol_idx"] + "/RuptureIndex"][iloc] mag = hdf5[self.idx_set["mag_idx"]][iloc] surface_set = [] r_sites = self.get_rupture_sites(hdf5, ridx, src_filter, mag) if r_sites is None: return None, None for idx in ridx: # Build simple fault surface trace_idx = "{:s}/{:s}".format(self.idx_set["sec_idx"], str(idx)) rup_plane = hdf5[trace_idx + "/RupturePlanes"][:].astype("float64") for jloc in range(0, rup_plane.shape[2]): top_left = Point(rup_plane[0, 0, jloc], rup_plane[0, 1, jloc], rup_plane[0, 2, jloc]) top_right = Point(rup_plane[1, 0, jloc], rup_plane[1, 1, jloc], rup_plane[1, 2, jloc]) bottom_right = Point(rup_plane[2, 0, jloc], rup_plane[2, 1, jloc], rup_plane[2, 2, jloc]) bottom_left = Point(rup_plane[3, 0, jloc], rup_plane[3, 1, jloc], rup_plane[3, 2, jloc]) try: surface_set.append( ImperfectPlanarSurface.from_corner_points( mesh_spacing, top_left, top_right, bottom_right, bottom_left)) except ValueError as evl: raise ValueError(evl, trace_idx, top_left, top_right, bottom_right, bottom_left) rupture = ParametricProbabilisticRupture( mag, hdf5[self.idx_set["rake_idx"]][iloc], trt, surface_set[len(surface_set) // 2].get_middle_point(), MultiSurface(surface_set), CharacteristicFaultSource, hdf5[self.idx_set["rate_idx"]][iloc], ctl.tom) # Get rupture index code string ridx_string = "-".join(str(val) for val in ridx) return rupture, ridx_string
def get_bounding_box(self, maxdist): """ Bounding box containing all surfaces, enlarged by the maximum distance """ surfaces = [] for rup, _ in self.data: if isinstance(rup.surface, MultiSurface): for s in rup.surface.surfaces: surfaces.append(s) else: surfaces.append(rup.surface) multi_surf = MultiSurface(surfaces) west, east, north, south = multi_surf.get_bounding_box() a1 = maxdist * KM_TO_DEGREES a2 = angular_distance(maxdist, north, south) return west - a2, south - a1, east + a2, north + a1
def few_ruptures(self): """ Fast version of iter_ruptures used in estimate_weight """ s = self.sections for i in range(0, len(self.mags), BLOCKSIZE // 5): idxs = self.rupture_idxs[i] if len(idxs) == 1: sfc = self.sections[idxs[0]].surface else: sfc = MultiSurface([s[idx].surface for idx in idxs]) rake = self.rakes[i] hypo = self.sections[idxs[0]].surface.get_middle_point() yield NonParametricProbabilisticRupture( self.mags[i], rake, self.tectonic_region_type, hypo, sfc, self.pmfs[i])
def setUp(self): path = os.path.join(BASE_DATA_PATH, 'profiles08') hsmpl = 2 vsmpl = 2 idl = False alg = False # Read the profiles with prefix cs_50. These profiles dip toward # north prf, _ = _read_profiles(path, 'cs_50') srfc50 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg) # Read the profiles with prefix cs_52. These profiles dip toward # north. This section is west to the section defined by cs_50 prf, _ = _read_profiles(path, 'cs_51') srfc51 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg) clo = [] cla = [] step = 0.01 for lo in np.arange(-71.8, -69, step): tlo = [] tla = [] for la in np.arange(19.25, 20.25, step): tlo.append(lo) tla.append(la) clo.append(tlo) cla.append(tla) self.clo = np.array(clo) self.cla = np.array(cla) mesh = Mesh(lons=self.clo.flatten(), lats=self.cla.flatten()) # Define multisurface and mesh of sites self.srfc50 = srfc50 self.srfc51 = srfc51 self.msrf = MultiSurface([srfc50, srfc51]) self.mesh = mesh self.los = [ self.msrf.surfaces[0].mesh.lons, self.msrf.surfaces[1].mesh.lons ] self.las = [ self.msrf.surfaces[0].mesh.lats, self.msrf.surfaces[1].mesh.lats ]
def setUp(self): # First surface prf1 = Line([Point(0, 0, 0), Point(0, -0.001, 20.)]) prf2 = Line([Point(0.15, 0, 0), Point(0.15, -0.001, 20.)]) prf3 = Line([Point(0.3, 0, 0), Point(0.3, -0.001, 20.)]) sfcA = KiteSurface.from_profiles([prf1, prf2, prf3], 5., 5.) # Second surface prf3 = Line([Point(0.32, 0, 0), Point(0.32, 0.001, 20.)]) prf4 = Line([Point(0.45, 0.15, 0), Point(0.45, 0.1501, 20.)]) sfcB = KiteSurface.from_profiles([prf3, prf4], 5., 5.) self.msrf = MultiSurface([sfcA, sfcB]) coo = np.array([[-0.1, 0.0], [0.0, 0.1]]) self.mesh = Mesh(coo[:, 0], coo[:, 1])
def test_rx_kite(self): spc = 2.0 pro1 = Line([Point(0.2, 0.0, 0.0), Point(0.2, 0.05, 15.0)]) pro2 = Line([Point(0.0, 0.0, 0.0), Point(0.0, 0.05, 15.0)]) sfc1 = KiteSurface.from_profiles([pro1, pro2], spc, spc) msurf = MultiSurface([sfc1]) pcoo = numpy.array([[0.2, 0.1], [0.0, -0.1]]) mesh = Mesh(pcoo[:, 0], pcoo[:, 1]) # Compute expected distances lo = pro1.points[0].longitude la = pro1.points[0].longitude tmp0 = geodetic_distance(lo, la, pcoo[0, 0], pcoo[0, 1]) lo = pro2.points[0].longitude la = pro2.points[0].longitude tmp1 = geodetic_distance(lo, la, pcoo[1, 0], pcoo[1, 1]) # Checking rx = msurf.get_rx_distance(mesh) expected = numpy.array([tmp0, -tmp1]) numpy.testing.assert_almost_equal(expected, rx, decimal=5)
def get_ucerf_rupture(self, iloc): """ :param iloc: Location of the rupture plane in the hdf5 file """ trt = self.tectonic_region_type if hasattr(self, 'all_ridx'): # already computed by the UcerfFilter ridx = self.all_ridx[iloc - self.start] else: ridx = self.get_ridx(iloc) mag = self.mags[iloc - self.start] if mag < self.min_mag: return surface_set = [] indices = self.src_filter.get_indices(self, ridx, mag) if len(indices) == 0: return for trace, plane in self.gen_trace_planes(ridx): # build simple fault surface for jloc in range(0, plane.shape[2]): top_left = Point( plane[0, 0, jloc], plane[0, 1, jloc], plane[0, 2, jloc]) top_right = Point( plane[1, 0, jloc], plane[1, 1, jloc], plane[1, 2, jloc]) bottom_right = Point( plane[2, 0, jloc], plane[2, 1, jloc], plane[2, 2, jloc]) bottom_left = Point( plane[3, 0, jloc], plane[3, 1, jloc], plane[3, 2, jloc]) try: surface_set.append( ImperfectPlanarSurface.from_corner_points( top_left, top_right, bottom_right, bottom_left)) except ValueError as err: raise ValueError(err, trace, top_left, top_right, bottom_right, bottom_left) rupture = ParametricProbabilisticRupture( mag, self.rake[iloc - self.start], trt, surface_set[len(surface_set) // 2].get_middle_point(), MultiSurface(surface_set), self.rate[iloc - self.start], self.tom) return rupture
def get_ucerf_rupture(self, iloc, src_filter): """ :param iloc: Location of the rupture plane in the hdf5 file :param src_filter: Sites for consideration and maximum distance """ mesh_spacing = self.mesh_spacing trt = self.tectonic_region_type ridx = self.get_ridx(iloc) mag = self.mags[iloc] surface_set = [] r_sites = self.get_rupture_sites(ridx, src_filter, mag) if r_sites is None: return None for trace, plane in self.gen_trace_planes(ridx): # build simple fault surface for jloc in range(0, plane.shape[2]): top_left = Point(plane[0, 0, jloc], plane[0, 1, jloc], plane[0, 2, jloc]) top_right = Point(plane[1, 0, jloc], plane[1, 1, jloc], plane[1, 2, jloc]) bottom_right = Point(plane[2, 0, jloc], plane[2, 1, jloc], plane[2, 2, jloc]) bottom_left = Point(plane[3, 0, jloc], plane[3, 1, jloc], plane[3, 2, jloc]) try: surface_set.append( ImperfectPlanarSurface.from_corner_points( mesh_spacing, top_left, top_right, bottom_right, bottom_left)) except ValueError as err: raise ValueError(err, trace, top_left, top_right, bottom_right, bottom_left) rupture = ParametricProbabilisticRupture( mag, self.rake[iloc], trt, surface_set[len(surface_set) // 2].get_middle_point(), MultiSurface(surface_set), CharacteristicFaultSource, self.rate[iloc], self.tom) return rupture
def setUp(self): # First surface - Almost vertical dipping to south prf1 = Line([Point(0, 0, 0), Point(0, -0.00001, 20.)]) prf2 = Line([Point(0.15, 0, 0), Point(0.15, -0.00001, 20.)]) prf3 = Line([Point(0.3, 0, 0), Point(0.3, -0.00001, 20.)]) sfca = KiteSurface.from_profiles([prf1, prf2, prf3], 1., 1.) # Second surface - Strike to NE and dip to SE pntsa = npoints_towards(lon=0.32, lat=0.0, depth=0.0, azimuth=45, hdist=10.0, vdist=0.0, npoints=2) pntsb = npoints_towards(lon=pntsa[0][1], lat=pntsa[1][1], depth=pntsa[2][1], azimuth=45 + 90, hdist=10.0, vdist=10.0, npoints=2) pntsc = npoints_towards(lon=0.32, lat=0.0, depth=0.0, azimuth=45 + 90, hdist=10.0, vdist=10.0, npoints=2) tmp = Point(pntsc[0][1], pntsc[1][1], pntsc[2][1]) prf3 = Line([Point(0.32, 0, 0), tmp]) tmp1 = Point(pntsa[0][1], pntsa[1][1], pntsa[2][1]) tmp2 = Point(pntsb[0][1], pntsb[1][1], pntsb[2][1]) prf4 = Line([tmp1, tmp2]) sfcb = KiteSurface.from_profiles([prf3, prf4], 0.2, 0.2) # Create surface and mesh needed for the test self.msrf = MultiSurface([sfca, sfcb]) self.coo = np.array([[-0.1, 0.0], [0.0, 0.1]]) self.mesh = Mesh(self.coo[:, 0], self.coo[:, 1])
def get_ucerf_rupture(self, ridx): """ :param ridx: rupture index """ sections = self.sections[ridx] mag = self.mags[ridx] if mag < self.min_mag: return surface_set = [] for sec in sections: plane = self.planes[sec] for p in range(plane.shape[2]): surface_set.append(PlanarSurface.from_ucerf(plane[:, :, p])) rupture = ParametricProbabilisticRupture( mag, self.rake[ridx], self.tectonic_region_type, surface_set[len(surface_set) // 2].get_middle_point(), MultiSurface(surface_set), self.rate[ridx], self.tom) rupture.rup_id = self.start + ridx return rupture
def setUp(self): path = os.path.join(BASE_DATA_PATH, 'profiles08') hsmpl = 5 vsmpl = 5 idl = False alg = False prf, _ = _read_profiles(path, 'cs_50') srfc50 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg) prf, _ = _read_profiles(path, 'cs_51') srfc51 = KiteSurface.from_profiles(prf, vsmpl, hsmpl, idl, alg) coo = [] step = 0.5 for lo in np.arange(-74, -68, step): for la in np.arange(17, 20, step): coo.append([lo, la]) coo = np.array(coo) mesh = Mesh(coo[:, 0], coo[:, 1]) # Define multisurface and mesh of sites self.msrf = MultiSurface([srfc50, srfc51]) self.mesh = mesh
def test_get_dip(self): surf = MultiSurface(self.surfaces_mesh2D) self.assertAlmostEqual(53.33333333, surf.get_dip())
def _setup_peer_test_bending_fault_config(): """ The GC2 tests will be based on variations of the PEER bending fault test case: (Fault is dipping east north east Point 5 (-65.0, 0.0, 0.0) o | | | o Point 4 (-65.0, -0.16188, 0) \ \ \ \ \ o Point 3 (-64.90498, -0.36564, 0.0) \__ \__ \__ \__ \__Point 2 (-64.80164, -0.45236, 0.0) \o---o Point 1 (-64.78365, -0.45236, 0.0) """ # Build separate faults # Get down-dip points - dipping east-noth-east strike1 = PNT1.azimuth(PNT2) dipdir1 = (strike1 + 90.) % 360.0 strike2 = PNT2.azimuth(PNT3) dipdir2 = (strike2 + 90.) % 360.0 strike3 = PNT3.azimuth(PNT4) dipdir3 = (strike3 + 90.) % 360.0 strike4 = PNT4.azimuth(PNT5) dipdir4 = (strike4 + 90.) % 360.0 global_strike = PNT1.azimuth(PNT5) global_dipdir = (global_strike + 90.) % 360.0 # Get lower trace usd = 0.0 lsd = 12.0 dip = 60.0 as_length = lsd / numpy.tan(numpy.radians(dip)) PNT1b = PNT1.point_at(as_length, lsd, global_dipdir) PNT2b = PNT2.point_at(as_length, lsd, global_dipdir) PNT3b = PNT3.point_at(as_length, lsd, global_dipdir) PNT4b = PNT4.point_at(as_length, lsd, global_dipdir) PNT5b = PNT5.point_at(as_length, lsd, global_dipdir) # As simple fault dipping east mesh_spacing = 0.5 simple_fault1 = SimpleFaultSurface.from_fault_data( Line([PNT1, PNT2, PNT3, PNT4, PNT5]), usd, lsd, dip, mesh_spacing) # As a set of planes describing a concordant "Stirling fault" stirling_planes = [ PlanarSurface.from_corner_points(PNT1, PNT2, PNT2b, PNT1b), PlanarSurface.from_corner_points(PNT2, PNT3, PNT3b, PNT2b), PlanarSurface.from_corner_points(PNT3, PNT4, PNT4b, PNT3b), PlanarSurface.from_corner_points(PNT4, PNT5, PNT5b, PNT4b) ] stirling_fault1 = MultiSurface(stirling_planes) # As a set of planes describing a concordant "Frankel Fault" # In the Frankel fault each segment is projected to the local dip direction dipdir2b = (dipdir2 + 180.) % 360.0 frankel_planes = [ PlanarSurface.from_corner_points( PNT1, PNT2, PNT2.point_at(as_length, lsd, dipdir1), PNT1.point_at(as_length, lsd, dipdir1)), PlanarSurface.from_corner_points( PNT2, PNT3, PNT3.point_at(as_length, lsd, dipdir2), PNT2.point_at(as_length, lsd, dipdir2)), PlanarSurface.from_corner_points( PNT3, PNT4, PNT4.point_at(as_length, lsd, dipdir3), PNT3.point_at(as_length, lsd, dipdir3)), PlanarSurface.from_corner_points( PNT4, PNT5, PNT5.point_at(as_length, lsd, dipdir4), PNT4.point_at(as_length, lsd, dipdir4)) ] frankel_fault1 = MultiSurface(frankel_planes) # Test the case of a discordant Frankel plane # Swapping the strike of the second segment to change the dip direction # Also increasing the dip from 60 degrees to 75 degrees as_length_alt = lsd / numpy.tan(numpy.radians(75.0)) frankel_discordant = [ PlanarSurface.from_corner_points( PNT1, PNT2, PNT2.point_at(as_length, lsd, dipdir1), PNT1.point_at(as_length, lsd, dipdir1)), PlanarSurface.from_corner_points( PNT3, PNT2, PNT2.point_at(as_length_alt, lsd, dipdir2b), PNT3.point_at(as_length_alt, lsd, dipdir2b)), PlanarSurface.from_corner_points( PNT3, PNT4, PNT4.point_at(as_length, lsd, dipdir3), PNT3.point_at(as_length, lsd, dipdir3)), PlanarSurface.from_corner_points( PNT4, PNT5, PNT5.point_at(as_length, lsd, dipdir4), PNT4.point_at(as_length, lsd, dipdir4)) ] frankel_fault2 = MultiSurface(frankel_discordant) return simple_fault1, stirling_fault1, frankel_fault1, frankel_fault2
def test_joyner_boore_distance_mesh2D(self): surf = MultiSurface(self.surfaces_mesh2D) numpy.testing.assert_equal(surf.get_joyner_boore_distance(self.mesh2D), numpy.array([[-1., 2., 2.], [4., 4., 5.]]))
def setUp(self): self.data = numpy.genfromtxt(DISCORDANT_FILE, delimiter=",") self.mesh = Mesh(self.data[:, 0], self.data[:, 1], self.data[:, 2]) self.model = MultiSurface(FRANK2.surfaces)
def test_ry0_distance_mesh1D(self): surf = MultiSurface(self.surfaces_mesh1D) self.assertRaises(NotImplementedError, surf.get_ry0_distance, self.mesh1D)
def test_rx_distance_mesh1D(self): surf = MultiSurface(self.surfaces_mesh1D) numpy.testing.assert_equal(surf.get_rx_distance(self.mesh1D), numpy.array([-1., 2., 2.]))
def test_top_edge_depth(self): surf = MultiSurface(self.surfaces_mesh2D) self.assertAlmostEqual(8.22222222, surf.get_top_edge_depth())
def test_middle_point_single_surface(self): surf = MultiSurface([self.surfaces_mesh2D[0]]) middle_point = surf.get_middle_point() self.assertTrue(Point(0.1, 1.1, 1.1) == middle_point)
def test_get_strike(self): surf = MultiSurface(self.surfaces_mesh2D) self.assertAlmostEqual(87.64579754, surf.get_strike())
def test_area(self): surf = MultiSurface(self.surfaces_mesh2D) self.assertAlmostEqual(90.0, surf.get_area())
def test_get_width(self): surf = MultiSurface(self.surfaces_mesh2D) self.assertAlmostEqual(12.88888888, surf.get_width())