def test(self): # relies on mesh.get_convex_hull() and polygon.dilate source = self._make_source() poly = source.get_rupture_enclosing_polygon(dilation=5.0) mesh = Mesh(numpy.array([[-1., 1.], [-1., 1.]]), numpy.array([[0., 0.], [0., 0.]]), numpy.array([[0., 0.], [10., 10.]])) numpy.testing.assert_equal(poly.lons, mesh.get_convex_hull().dilate(5.0).lons) numpy.testing.assert_equal(poly.lats, mesh.get_convex_hull().dilate(5.0).lats)
def test(self): # relies on mesh.get_convex_hull() and polygon.dilate source = self._make_source() poly = source.get_rupture_enclosing_polygon(dilation=5.0) mesh = Mesh(numpy.array([[-1., 1.], [-1., 1.]]), numpy.array([[0., 0.], [0., 0.]]), numpy.array([[0., 0.], [10., 10.]])) numpy.testing.assert_equal( poly.lons, mesh.get_convex_hull().dilate(5.0).lons ) numpy.testing.assert_equal( poly.lats, mesh.get_convex_hull().dilate(5.0).lats )
def get_target_sites_line(self, maximum_distance, spacing, vs30, line_azimuth=90., origin_point=(0.5, 0.5), as_log=False, vs30measured=True, z1pt0=None, z2pt5=None, backarc=False): """ Defines the target sites along a line with respect to the rupture """ #input_origin_point = deepcopy(origin_point) azimuth, origin_location, z1pt0, z2pt5 = _setup_site_peripherals( line_azimuth, origin_point, vs30, z1pt0, z2pt5, self.strike, self.surface) self.target_sites = [ Site(origin_location, vs30, vs30measured, z1pt0, z2pt5, backarc=backarc) ] spacings = self._define_line_spacing(maximum_distance, spacing, as_log) for offset in spacings: target_loc = origin_location.point_at(offset, 0., azimuth) # Get Rupture distance temp_mesh = Mesh(np.array(target_loc.longitude), np.array(target_loc.latitude), np.array(target_loc.depth)) distance = self.surface.get_min_distance(temp_mesh) self.target_sites.append( Site(target_loc, vs30, vs30measured, z1pt0, z2pt5, backarc=backarc)) self.target_sites_config = { "TYPE": "Line", "RMAX": maximum_distance, "SPACING": spacing, "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.surfaces_mesh2D = [ self.FakeSurface(numpy.array([[-1., 2., 3.], [4., 5., 6.]]), numpy.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]), numpy.array([[1.1, 1.2, 1.3], [1.4, 1.5, 1.6]]), numpy.array([[1.1, 1.2, 1.3], [1.4, 1.5, 1.6]]), 2.0, 45.0, 60.0, 10.0, 10.0), self.FakeSurface(numpy.array([[-0.5, 3., 2.], [5., 4., 5.]]), numpy.array([[2.1, 2.2, 2.3], [2.4, 2.5, 2.6]]), numpy.array([[3.1, 3.2, 3.3], [3.4, 3.5, 3.6]]), numpy.array([[2.1, 2.2, 2.3], [2.4, 2.5, 2.6]]), 6, 70.0, 90.0, 8, 20.0), self.FakeSurface(numpy.array([[5., 4., 4.], [6., 6., 7.]]), numpy.array([[4.1, 4.2, 4.3], [4.4, 4.5, 4.6]]), numpy.array([[5.1, 5.2, 5.3], [5.4, 5.5, 5.6]]), numpy.array([[6.1, 6.2, 6.3], [6.4, 6.5, 6.6]]), 10, 100.0, 40.0, 15, 60.0) ] self.mesh2D = Mesh(numpy.array([[1., 2., 3.], [4., 5., 6.]]), numpy.array([[1., 2., 3.], [4., 5., 6.]]), numpy.array([[1., 2., 3.], [4., 5., 6.]])) self.surfaces_mesh1D = [ self.FakeSurface(numpy.array([-1., 2., 3.]), numpy.array([0.1, 0.2, 0.3]), numpy.array([1.1, 1.2, 1.3]), numpy.array([1.1, 1.2, 1.3]), 2.0, 45.0, 60.0, 10.0, 10.0), self.FakeSurface(numpy.array([-0.5, 3., 2.]), numpy.array([2.1, 2.2, 2.3]), numpy.array([3.1, 3.2, 3.3]), numpy.array([2.1, 2.2, 2.3]), 6, 70.0, 90.0, 8, 20.0), self.FakeSurface(numpy.array([5., 4., 4.]), numpy.array([4.1, 4.2, 4.3]), numpy.array([5.1, 5.2, 5.3]), numpy.array([6.1, 6.2, 6.3]), 10, 100.0, 40.0, 15, 60.0) ] self.mesh1D = Mesh(numpy.array([1., 2., 3.]), numpy.array([1., 2., 3.]), numpy.array([1., 2., 3.]))
def _rup_to_point(distance, surface, origin, azimuth, distance_type='rjb', iter_stop=1E-3, maxiter=1000): """ Place a point at a given distance from a rupture along a specified azimuth """ pt0 = origin pt1 = origin.point_at(distance, 0., azimuth) #print pt0, pt1 r_diff = np.inf dip = surface.dip sin_dip = np.sin(np.radians(dip)) dist_sin_dip = distance / sin_dip #max_surf_dist = surface.width / np.cos(np.radians(dip)) iterval = 0 while (np.fabs(r_diff) >= iter_stop) and (iterval <= maxiter): pt1mesh = Mesh(np.array([pt1.longitude]), np.array([pt1.latitude]), None) if distance_type == 'rjb' or np.fabs(dip - 90.0) < 1.0E-3: r_diff = (distance - surface.get_joyner_boore_distance(pt1mesh)).flatten() pt0 = Point(pt1.longitude, pt1.latitude) if r_diff > 0.: pt1 = pt0.point_at(r_diff, 0., azimuth) else: pt1 = pt0.point_at(np.fabs(r_diff), 0., (azimuth + 180.) % 360.) elif distance_type == 'rrup': rrup = surface.get_min_distance(pt1mesh).flatten() if azimuth >= 0.0 and azimuth <= 180.0: # On hanging wall r_diff = dist_sin_dip - (rrup / sin_dip) else: # On foot wall r_diff = distance - rrup pt0 = Point(pt1.longitude, pt1.latitude) #print azimuth, (azimuth + 180.0) % 360, rrup, r_diff, np.fabs(r_diff) if r_diff > 0.: pt1 = pt0.point_at(r_diff, 0., azimuth) else: pt1 = pt0.point_at(np.fabs(r_diff), 0., (azimuth + 180.) % 360.) else: raise ValueError('Distance type must be rrup or rjb!') iterval += 1 return pt1
def get_distances(self, centroid, ruptures, lons, lats): """ Calculates the source to site distances """ nsites = len(lons) mesh = Mesh(lons, lats) distances = np.zeros([len(ruptures), nsites, 4]) for i, rup in enumerate(ruptures): distances[i, :, 0] = rup.get_joyner_boore_distance(mesh) distances[i, :, 1] = rup.get_min_distance(mesh) distances[i, :, 2] = rup.get_rx_distance(mesh) distances[i, :, 3] = rup.get_ry0_distance(mesh) rhypo = centroid.distance_to_mesh(mesh) return distances, rhypo
def _get_min_distance_to_volcanic_front(lons, lats): """ Compute and return minimum distance between volcanic front and points specified by 'lon' and 'lat'. Distance is negative if point is located east of the volcanic front, positive otherwise. The method uses the same approach as :meth:`_get_min_distance_to_sub_trench` but final distance is returned without taking the absolute value. """ vf = _construct_surface(VOLCANIC_FRONT_LONS, VOLCANIC_FRONT_LATS, 0., 10.) sites = Mesh(lons, lats, None) return vf.get_rx_distance(sites)
def get_distances_from_surface(catalogue, surface): """ This computes distances """ nel = len(catalogue.data['longitude']) dsts = np.empty((nel)) delta = 4000 if nel < delta: mesh = Mesh(catalogue.data['longitude'][0:nel], catalogue.data['latitude'][0:nel], catalogue.data['depth'][0:nel]) dsts = surface.get_min_distance(mesh) else: i = 0 upp = 0 while upp < nel - 1: upp = min([i + delta, nel - 1]) mesh = Mesh(catalogue.data['longitude'][i:upp], catalogue.data['latitude'][i:upp], catalogue.data['depth'][i:upp]) tmp = surface.get_min_distance(mesh) dsts[i:upp] = tmp i = upp + 1 return dsts
def _site_collection_to_mesh(self): """ Returns a collection of sites as an instance of the :class: `openquake.hazardlib.geo.Mesh` """ if isinstance(self.target_sites, SiteCollection): locations = np.array([len(self.target_sites.sites), 3], dtype=float) for iloc, site in enumerate(self.target_sites.sites): locations[iloc, 0] = site.location.longitude locations[iloc, 1] = site.location.latitude locations[iloc, 2] = site.location.depth return Mesh(locations[:, 0], locations[:, 1], locations[:, 2]) else: raise ValueError('Target sites must be an instance of ' 'openquake.hazardlib.site.SiteCollection')
def _get_min_distance_to_sub_trench(lons, lats): """ Compute and return minimum distance between subduction trench and points specified by 'lon' and 'lat' The method creates an instance of :class:`openquake.hazardlib.geo.SimpleFaultSurface` to model the subduction trench. The surface is assumed vertical and extending from 0 to 10 km depth. The 10 km depth value is arbitrary given that distance calculation depend only on top edge depth. The method calls then :meth:`openquake.hazardlib.geo.base.BaseSurface.get_rx_distance` and return its absolute value. """ trench = _construct_surface(SUB_TRENCH_LONS, SUB_TRENCH_LATS, 0., 10.) sites = Mesh(lons, lats, None) return np.abs(trench.get_rx_distance(sites))
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 build_sites_distances_contexts(self, event, sites, vs30measured=False, backarc=False): """ Builds the contexts from the event and sites """ # Get distances mesh = Mesh(sites["lon"], sites["lat"]) mshape = mesh.lons.shape dctx = DistancesContext() for param in self.context.REQUIRES_DISTANCES: setattr(dctx, param, get_distances(event.get_rupture(), mesh, param)) # Get sites context sctx = SitesContext() for key in self.site_attribs: if key.startswith("z1pt0") and not "z1pt0" in sites: setattr(sctx, "z1pt0", vs30_to_z1pt0_cy14(sites["vs30"], japan=False)) elif key.startswith("z2pt5") and not "z5pt5" in sites: setattr(sctx, "z2pt5", vs30_to_z2pt5_cb14(sites["vs30"], japan=False)) elif key.startswith( "vs30measured") and not "vs30measured" in sites: if vs30measured: setattr(sctx, "vs30measured", np.ones(mshape, dtype=bool)) else: setattr(sctx, "vs30measured", np.zeros(mshape, dtype=bool)) elif key.startswith( "vs30measured") and not "vs30measured" in sites: if vs30measured: setattr(sctx, "vs30measured", np.ones(mshape, dtype=bool)) else: setattr(sctx, "vs30measured", np.zeros(mshape, dtype=bool)) elif key.startswith("backarc") and not "backarc" in sites: if vs30measured: setattr(sctx, "backarc", np.ones(mshape, dtype=bool)) else: setattr(sctx, "backarc", np.zeros(mshape, dtype=bool)) else: setattr(sctx, key, sites[key]) return sctx, dctx
def gdfs(catalogue, surface): """ :parameter catalogue: :parameter surface: """ nel = len(catalogue.data['longitude']) # MN: 'dsts' assigned but never used dsts = np.empty((nel)) delta = 4000 # # preparing the sub meshes, each containing a subset of earthquakes inputs = [] for i in np.arange(0, nel, delta): upp = min([i + delta, nel - 1]) mesh = Mesh(catalogue.data['longitude'][i:upp], catalogue.data['latitude'][i:upp], catalogue.data['depth'][i:upp]) inputs.append([mesh, surface]) # # multiprocessing pool = mp.Pool(processes=6) # MN: 'results' assigned but never used results = pool.map(aaa, inputs)
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) # Get Rupture distance temp_mesh = Mesh(np.array(target_loc.longitude), np.array(target_loc.latitude), np.array(target_loc.depth)) distance = self.surface.get_min_distance(temp_mesh) self.target_sites.append(Site(target_loc, vs30, vs30measured, z1pt0, z2pt5, 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 get_closest_points(self, sites): assert len(sites) == 1 return Mesh(numpy.array([self.lon], float), numpy.array([self.lat], float), depths=None)
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 get_closest_points(self, mesh): assert mesh.shape == self.lons.shape return Mesh(self.lons, self.lats, self.depths)