def test_differnet_point(self): self.assertEqual( geo.Point(*utils.get_middle_point(0, 0, 0.2, -0.2)), geo.Point(0.1, -0.1), ) self.assertEqual(geo.Point(*utils.get_middle_point(20, 40, 20.02, 40)), geo.Point(20.01, 40))
def test_same_points(self): self.assertEqual( geo.Point(*utils.get_middle_point(1.2, -1.4, 1.2, -1.4)), geo.Point(1.2, -1.4)) self.assertEqual( geo.Point(*utils.get_middle_point(-150.33, 22.1, -150.33, 22.1)), geo.Point(-150.33, 22.1))
def test_international_date_line(self): self.assertEqual( geo.Point(*utils.get_middle_point(-178, 10, 178, -10)), geo.Point(180, 0) ) self.assertEqual( geo.Point(*utils.get_middle_point(-179, 43, 179, 43)), geo.Point(180, 43.004353) )
def test_differnet_point(self): self.assertEqual( geo.Point(*utils.get_middle_point(0, 0, 0.2, -0.2)), geo.Point(0.1, -0.1), ) self.assertEqual( geo.Point(*utils.get_middle_point(20, 40, 20.02, 40)), geo.Point(20.01, 40) )
def test_same_points(self): self.assertEqual( geo.Point(*utils.get_middle_point(1.2, -1.4, 1.2, -1.4)), geo.Point(1.2, -1.4) ) self.assertEqual( geo.Point(*utils.get_middle_point(-150.33, 22.1, -150.33, 22.1)), geo.Point(-150.33, 22.1) )
def get_middle_point(self): """ If :class:`MultiSurface` is defined by a single surface, simply returns surface's middle point, otherwise find surface element closest to the surface's bounding box centroid and return corresponding middle point. Note that the concept of middle point for a multi surface is ambiguous and alternative definitions may be possible. However, this method is mostly used to define the hypocenter location for ruptures described by a multi surface (see :meth:`openquake.hazardlib.source.characteristic.CharacteristicFaultSource.iter_ruptures`). This is needed because when creating fault based sources, the rupture's hypocenter locations are not explicitly defined, and therefore an automated way to define them is required. """ if len(self.surfaces) == 1: return self.surfaces[0].get_middle_point() west, east, north, south = self.get_bounding_box() longitude, latitude = utils.get_middle_point(west, north, east, south) dists = [] for surf in self.surfaces: dists.append( surf.get_min_distance(Mesh(numpy.array([longitude]), numpy.array([latitude]), None))) dists = numpy.array(dists).flatten() idx = dists == numpy.min(dists) return numpy.array(self.surfaces)[idx][0].get_middle_point()
def get_middle_point(self): """ If :class:`MultiSurface` is defined by a single surface, simply returns surface's middle point, otherwise find surface element closest to the surface's bounding box centroid and return corresponding middle point. Note that the concept of middle point for a multi surface is ambiguous and alternative definitions may be possible. However, this method is mostly used to define the hypocenter location for ruptures described by a multi surface (see :meth:`openquake.hazardlib.source.characteristic.CharacteristicFaultSource.iter_ruptures`). This is needed because when creating fault based sources, the rupture's hypocenter locations are not explicitly defined, and therefore an automated way to define them is required. """ if len(self.surfaces) == 1: return self.surfaces[0].get_middle_point() west, east, north, south = self.get_bounding_box() longitude, latitude = utils.get_middle_point(west, north, east, south) dists = [] for surf in self.surfaces: dists.append( surf.get_min_distance(Mesh(numpy.array([longitude]), numpy.array([latitude]), None)) ) dists = numpy.array(dists).flatten() idx = dists == numpy.min(dists) return numpy.array(self.surfaces)[idx][0].get_middle_point()
def _get_top_edge_centroid(self): """ Overrides :meth:`superclass' method <openquake.hazardlib.geo.surface.base.BaseQuadrilateralSurface._get_top_edge_centroid>` in order to avoid creating a mesh. """ lon, lat = geo_utils.get_middle_point( self.corner_lons[0], self.corner_lats[0], self.corner_lons[1], self.corner_lats[1] ) return Point(lon, lat, self.corner_depths[0])
def _get_top_edge_centroid(self): """ Overrides :meth:`superclass' method <openquake.hazardlib.geo.surface.base.BaseSurface._get_top_edge_centroid>` in order to avoid creating a mesh. """ lon, lat = geo_utils.get_middle_point(self.corner_lons[0], self.corner_lats[0], self.corner_lons[1], self.corner_lats[1]) return Point(lon, lat, self.corner_depths[0])
def get_middle_point(self): """ Compute middle point from surface's corners coordinates. Calls :meth:`openquake.hazardlib.geo.utils.get_middle_point` """ # compute middle point between upper left and bottom right corners lon, lat = geo_utils.get_middle_point( self.corner_lons[0], self.corner_lats[0], self.corner_lons[3], self.corner_lats[3] ) depth = (self.corner_depths[0] + self.corner_depths[3]) / 2.0 return Point(lon, lat, depth)
def get_middle_point(self): """ Compute middle point from surface's corners coordinates. Calls :meth:`openquake.hazardlib.geo.utils.get_middle_point` """ # compute middle point between upper left and bottom right corners lon, lat = geo_utils.get_middle_point(self.corner_lons[0], self.corner_lats[0], self.corner_lons[3], self.corner_lats[3]) depth = (self.corner_depths[0] + self.corner_depths[3]) / 2. return Point(lon, lat, depth)
def get_middle_point(self): """ Return the middle point of the mesh. :returns: An instance of :class:`~openquake.hazardlib.geo.point.Point`. The middle point is taken from the middle row and a middle column of the mesh if there are odd number of both. Otherwise the geometric mean point of two or four middle points. """ num_rows, num_cols = self.lons.shape mid_row = num_rows // 2 depth = 0 if num_rows & 1 == 1: # there are odd number of rows mid_col = num_cols // 2 if num_cols & 1 == 1: # odd number of columns, we can easily take # the middle point if self.depths is not None: depth = self.depths[mid_row][mid_col] return Point(self.lons[mid_row][mid_col], self.lats[mid_row][mid_col], depth) else: # even number of columns, need to take two middle # points on the middle row lon1, lon2 = self.lons[mid_row][mid_col - 1:mid_col + 1] lat1, lat2 = self.lats[mid_row][mid_col - 1:mid_col + 1] if self.depths is not None: depth1 = self.depths[mid_row][mid_col - 1] depth2 = self.depths[mid_row][mid_col] else: # there are even number of rows. take the row just above # and the one just below the middle and find middle point # of each submesh1 = self[mid_row - 1:mid_row] submesh2 = self[mid_row:mid_row + 1] p1, p2 = submesh1.get_middle_point(), submesh2.get_middle_point() lon1, lat1, depth1 = p1.longitude, p1.latitude, p1.depth lon2, lat2, depth2 = p2.longitude, p2.latitude, p2.depth # we need to find the middle between two points if self.depths is not None: depth = (depth1 + depth2) / 2.0 lon, lat = geo_utils.get_middle_point(lon1, lat1, lon2, lat2) return Point(lon, lat, depth)
def get_middle_point(self): """ Return the middle point of the mesh. :returns: An instance of :class:`~openquake.hazardlib.geo.point.Point`. The middle point is taken from the middle row and a middle column of the mesh if there are odd number of both. Otherwise the geometric mean point of two or four middle points. """ num_rows, num_cols = self.lons.shape mid_row = num_rows // 2 depth = 0 if num_rows & 1 == 1: # there are odd number of rows mid_col = num_cols // 2 if num_cols & 1 == 1: # odd number of columns, we can easily take # the middle point if self.depths is not None: depth = self.depths[mid_row][mid_col] return Point(self.lons[mid_row][mid_col], self.lats[mid_row][mid_col], depth) else: # even number of columns, need to take two middle # points on the middle row lon1, lon2 = self.lons[mid_row][mid_col - 1 : mid_col + 1] lat1, lat2 = self.lats[mid_row][mid_col - 1 : mid_col + 1] if self.depths is not None: depth1 = self.depths[mid_row][mid_col - 1] depth2 = self.depths[mid_row][mid_col] else: # there are even number of rows. take the row just above # and the one just below the middle and find middle point # of each submesh1 = self[mid_row - 1 : mid_row] submesh2 = self[mid_row : mid_row + 1] p1, p2 = submesh1.get_middle_point(), submesh2.get_middle_point() lon1, lat1, depth1 = p1.longitude, p1.latitude, p1.depth lon2, lat2, depth2 = p2.longitude, p2.latitude, p2.depth # we need to find the middle between two points if self.depths is not None: depth = (depth1 + depth2) / 2.0 lon, lat = geo_utils.get_middle_point(lon1, lat1, lon2, lat2) return Point(lon, lat, depth)