Example #1
0
 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))
Example #2
0
 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))
Example #3
0
 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)
     )
Example #4
0
 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)
     )
Example #5
0
 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)
     )
Example #6
0
 def _get_top_edge_centroid(self):
     """
     Overrides :meth:`superclass' method
     <nhlib.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])
Example #7
0
 def _get_top_edge_centroid(self):
     """
     Overrides :meth:`superclass' method
     <nhlib.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])
Example #8
0
File: mesh.py Project: angri/nhlib
    def get_middle_point(self):
        """
        Return the middle point of the mesh.

        :returns:
            An instance of :class:`~nhlib.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)
Example #9
0
File: mesh.py Project: angri/nhlib
    def get_middle_point(self):
        """
        Return the middle point of the mesh.

        :returns:
            An instance of :class:`~nhlib.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)
Example #10
0
 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))