def setup_method(self, method):
     self.bs1 = RasterBoundaryStatus([
         NodeStatus.CORE, NodeStatus.FIXED_VALUE_BOUNDARY, NodeStatus.CORE,
         NodeStatus.FIXED_VALUE_BOUNDARY
     ])
     self.bs2 = RasterBoundaryStatus(NodeStatus.CORE)
     self.bs3 = RasterBoundaryStatus(NodeStatus.LOOPED_BOUNDARY)
Beispiel #2
0
    def setup_class(cls):
        profile_grid = ProfileGrid(8, 2.2, [NodeStatus.FIXED_VALUE_BOUNDARY] * 2, [])
        cls.profile_flow_graph = FlowGraph(profile_grid, SingleFlowRouter())
        cls.profile_elevation = np.r_[0.82, 0.16, 0.14, 0.20, 0.71, 0.97, 0.41, 0.09]
        cls.result_profile_elevation = cls.profile_flow_graph.update_routes(
            cls.profile_elevation
        )

        raster_grid = RasterGrid(
            [4, 4],
            [1.1, 1.2],
            RasterBoundaryStatus(NodeStatus.FIXED_VALUE_BOUNDARY),
            [],
        )
        cls.raster_flow_graph = FlowGraph(raster_grid, SingleFlowRouter())
        cls.raster_elevation = np.array(
            [
                [0.82, 0.16, 0.14, 0.20],
                [0.71, 0.97, 0.41, 0.09],
                [0.49, 0.01, 0.19, 0.38],
                [0.29, 0.82, 0.09, 0.88],
            ]
        )
        cls.result_raster_elevation = cls.raster_flow_graph.update_routes(
            cls.raster_elevation
        )
    def test_raster_grid(self, func, k):
        # Test on a tiny (2x2) 2-d square grid with a planar surface
        # tilted in y (rows) and with all outlets on the 1st row.
        spacing = 300.
        grid = RasterGrid([2, 2], [spacing, spacing],
                          RasterBoundaryStatus(
                              NodeStatus.FIXED_VALUE_BOUNDARY), [])
        flow_graph = FlowGraph(grid, SingleFlowRouter())

        h = 1.
        elevation = np.array([[0., 0.], [h, h]], dtype='d')
        graph_elevation = flow_graph.update_routes(elevation)

        drainage_area = flow_graph.accumulate(1.)
        erosion = np.zeros_like(elevation)
        m_exp = 0.5
        n_exp = 1.

        dt = 1  # use small time step (compare with explicit scheme)
        tolerance = 1e-3

        n_corr = func(erosion, elevation, drainage_area, flow_graph, k, m_exp,
                      n_exp, dt, tolerance)

        slope = h / spacing
        a = spacing**2
        k_coef = 1e-3
        err = dt * k_coef * a**m_exp * slope**n_exp
        expected_erosion = np.array([[0., 0.], [err, err]], dtype='d')

        np.testing.assert_allclose(erosion, expected_erosion, atol=1e-5)
        assert n_corr == 0
Beispiel #4
0
def grid(grid_type):
    if grid_type == "profile":
        bs = ProfileBoundaryStatus(NodeStatus.FIXED_VALUE_BOUNDARY)
        return ProfileGrid(4, 1.0, bs, [])

    elif grid_type == "raster":
        bs = RasterBoundaryStatus(NodeStatus.FIXED_VALUE_BOUNDARY)
        return RasterGrid([3, 3], np.array([1.0, 1.0]), bs, [])
    def test___init__(self):
        profile_grid = ProfileGrid(8, 2.2,
                                   [NodeStatus.FIXED_VALUE_BOUNDARY] * 2, [])
        raster_grid = RasterGrid([5, 10], [2.2, 2.4],
                                 RasterBoundaryStatus(
                                     NodeStatus.FIXED_VALUE_BOUNDARY), [])

        FlowGraph(profile_grid, DummyFlowRouter())
        FlowGraph(profile_grid, MultipleFlowRouter(1., 1.1))
        FlowGraph(profile_grid, SingleFlowRouter())
    def test_accumulate(self):
        grid = ProfileGrid(8, 2.2, [NodeStatus.FIXED_VALUE_BOUNDARY] * 2, [])
        flow_graph = FlowGraph(grid, SingleFlowRouter())
        elevation = np.r_[0.82, 0.16, 0.14, 0.20, 0.71, 0.97, 0.41, 0.09]

        graph_elevation = flow_graph.update_routes(elevation)

        npt.assert_almost_equal(
            flow_graph.accumulate(np.ones(elevation.shape)),
            np.r_[2.2, 4.4, 11.0, 4.4, 2.2, 2.2, 4.4, 6.6],
        )

        grid = RasterGrid(
            [4, 4],
            [1.1, 1.2],
            RasterBoundaryStatus(NodeStatus.FIXED_VALUE_BOUNDARY),
            [],
        )
        flow_graph = FlowGraph(grid, SingleFlowRouter())
        elevation = np.array([
            [0.82, 0.16, 0.14, 0.20],
            [0.71, 0.97, 0.41, 0.09],
            [0.49, 0.01, 0.19, 0.38],
            [0.29, 0.82, 0.09, 0.88],
        ])

        graph_elevation = flow_graph.update_routes(elevation)

        expected = np.array([
            [1.32, 2.64, 3.96, 1.32],
            [1.32, 1.32, 1.32, 9.24],
            [1.32, 11.88, 1.32, 1.32],
            [1.32, 1.32, 2.64, 1.32],
        ])
        npt.assert_almost_equal(
            flow_graph.accumulate(np.ones(elevation.shape)), expected)

        npt.assert_almost_equal(flow_graph.accumulate(1.0), expected)

        npt.assert_almost_equal(flow_graph.accumulate(5.0), 5 * expected)

        data = np.array([
            [1.1, 1.0, 1.1, 1.0],
            [1.1, 1.0, 1.1, 1.0],
            [1.1, 1.0, 1.1, 1.0],
            [1.1, 1.0, 1.1, 1.0],
        ])
        expected = np.array([
            [1.452, 2.772, 4.224, 1.32],
            [1.452, 1.32, 1.452, 9.636],
            [1.452, 12.54, 1.452, 1.32],
            [1.452, 1.32, 2.772, 1.32],
        ])
        npt.assert_almost_equal(flow_graph.accumulate(data), expected)
 def setup_method(self, method):
     self.bs = bs = RasterBoundaryStatus(NodeStatus.FIXED_VALUE_BOUNDARY)
     self.g = RasterGrid(
         [5, 10], [2.2, 2.4], bs,
         [RasterNode(0, 5, NodeStatus.FIXED_VALUE_BOUNDARY)])