def _get_limits_maximum_rjb(self, maximum_distance): """ Returns the bounding box of a polyon representing the locations of maximum distance from the rupture """ top_left = deepcopy(self.surface.top_left) top_left.depth = 0. top_right = deepcopy(self.surface.top_right) top_right.depth = 0. bottom_left = deepcopy(self.surface.bottom_left) bottom_left.depth = 0. bottom_right = deepcopy(self.surface.bottom_right) bottom_right.depth = 0. surface_projection = Polygon([top_left, top_right, bottom_right, bottom_left]) dilated_projection = surface_projection.dilate(maximum_distance) return (np.min(dilated_projection.lons), np.max(dilated_projection.lons), np.min(dilated_projection.lats), np.max(dilated_projection.lats))
def to_polygon(self, radius): """ Create a circular polygon with specified radius centered in the point. :param radius: Required radius of a new polygon, in km. :returns: Instance of :class:`~openquake.hazardlib.geo.polygon.Polygon` that approximates a circle around the point with specified radius. """ assert radius > 0 # avoid circular imports from openquake.hazardlib.geo.polygon import Polygon # get a projection that is centered in the point proj = geo_utils.OrthographicProjection( self.longitude, self.longitude, self.latitude, self.latitude) # create a shapely object from a projected point coordinates, # which are supposedly (0, 0) point = shapely.geometry.Point(*proj(self.longitude, self.latitude)) # extend the point to a shapely polygon using buffer() # and create openquake.hazardlib.geo.polygon.Polygon object from it return Polygon._from_2d(point.buffer(radius), proj)
def test_fault_source_outside_mag_range(self): """ Tests the rates when the whole fault is inside the polygon """ self.limits = { "polygon": Polygon([ Point(14.9, 14.9), Point(14.9, 15.1), Point(15.1, 15.1), Point(15.1, 14.9) ]), "upper_depth": 0.0, "lower_depth": 20.0 } model1 = RatePolygon(self.limits, [SIMPLE_FAULT], area_discretisation=4.0) model1.get_rates(6.5, 6.8) self.assertAlmostEqual(model1.rates, 0.0)
def test_point_source_outside_mag_limit(self): """ Tests the case of a single point source outside the polygon """ self.limits = { "polygon": Polygon([ Point(14.9, 14.9), Point(14.9, 15.1), Point(15.1, 15.1), Point(15.1, 14.9) ]), "upper_depth": 0.0, "lower_depth": 3.0 } model1 = RatePolygon(self.limits, [POINT_SOURCE], area_discretisation=4.0) model1.get_rates(5.5, 6.0) self.assertAlmostEqual(model1.rates, 0.0)
def node_to_area_geometry(node): """ Reads an area geometry node and returns the polygon, upper depth and lower depth """ assert "areaGeometry" in node.tag for subnode in node.nodes: if "Polygon" in subnode.tag: crds = [float(x) for x in subnode.nodes[0].nodes[0].nodes[0].text.split()] polygon = Polygon([Point(crds[iloc], crds[iloc + 1]) for iloc in range(0, len(crds), 2)]) elif "upperSeismoDepth" in subnode.tag: upper_depth = float_(subnode.text) elif "lowerSeismoDepth" in subnode.tag: lower_depth = float_(subnode.text) else: # Redundent pass assert lower_depth > upper_depth return polygon, upper_depth, lower_depth
def test_instantiation(self): """ Tests simple instantiation of the class """ self.limits = { "polygon": Polygon([ Point(14.9, 14.9), Point(14.9, 15.1), Point(15.1, 15.1), Point(15.1, 14.9) ]), "upper_depth": 0.0, "lower_depth": 10.0 } model1 = RatePolygon(self.limits, [POINT_SOURCE], area_discretisation=4.0) self.assertAlmostEqual(model1.upper_depth, 0.0) self.assertAlmostEqual(model1.lower_depth, 10.0) self.assertAlmostEqual(model1.rates, 0.0)
def to_polygon(self, radius): """ Create a circular polygon with specified radius centered in the point. :param radius: Required radius of a new polygon, in km. :returns: Instance of :class:`~openquake.hazardlib.geo.polygon.Polygon` that approximates a circle around the point with specified radius. """ assert radius > 0 # avoid circular imports from openquake.hazardlib.geo.polygon import Polygon # get a projection that is centered in the point proj = geo_utils.get_orthographic_projection( self.longitude, self.longitude, self.latitude, self.latitude ) # create a shapely object from a projected point coordinates, # which are supposedly (0, 0) point = shapely.geometry.Point(*proj(self.longitude, self.latitude)) # extend the point to a shapely polygon using buffer() # and create openquake.hazardlib.geo.polygon.Polygon object from it return Polygon._from_2d(point.buffer(radius), proj)
def get_convex_hull(self): """ Get a convex polygon object that contains projections of all the points of the mesh. :returns: Instance of :class:`openquake.hazardlib.geo.polygon.Polygon` that is a convex hull around all the points in this mesh. If the original mesh had only one point, the resulting polygon has a square shape with a side length of 10 meters. If there were only two points, resulting polygon is a stripe 10 meters wide. """ proj, polygon2d = self._get_proj_convex_hull() # if mesh had only one point, the convex hull is a point. if there # were two, it is a line string. we need to return a convex polygon # object, so extend that area-less geometries by some arbitrarily # small distance. if isinstance(polygon2d, (shapely.geometry.LineString, shapely.geometry.Point)): polygon2d = polygon2d.buffer(self.DIST_TOLERANCE, 1) # avoid circular imports from openquake.hazardlib.geo.polygon import Polygon return Polygon._from_2d(polygon2d, proj)
OUTSIDE_POINT_SOURCE = PointSource( "PNT000", "Point 000", "Active Shallow Crust", EvenlyDiscretizedMFD(5.0, 0.1, [1.0]), 1.0, PointMSR(), 1.0, PoissonTOM(1.0), 0.0, 20.0, Point(15.0, 15.2), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 5.0)])) AREA_POLY = Polygon([Point(14.95, 15.05), Point(15.05, 15.05), Point(15.05, 14.95), Point(14.95, 14.95)]) AREA_SOURCE = AreaSource("AREA000", "Area 000", "Active Shallow Crust", EvenlyDiscretizedMFD(5.0, 0.1, [1.0]), 1.0, PointMSR(), 1.0, PoissonTOM(1.0), 0., 40., PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(0.5, 5.0), (0.5, 15.0)]), AREA_POLY, 4.0)
def as_polygon(self): return Polygon([ Point(self['xmin'], self['ymax']), Point(self['xmax'], self['ymax']), Point(self['xmax'], self['ymin']), Point(self['xmin'], self['ymin'])])