예제 #1
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
        )
예제 #2
0
    def test_update_routes(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_equal(flow_graph.receivers()[:, 0], np.r_[1, 2, 2, 2, 3, 6,
                                                             7, 7])
        npt.assert_equal(flow_graph.receivers_count(), np.ones(elevation.size))
        npt.assert_equal(flow_graph.receivers_weight()[:, 0],
                         np.ones(elevation.size))
        npt.assert_equal(flow_graph.receivers_weight()[:, 1],
                         np.zeros(elevation.size))

        m = np.iinfo(np.uint64).max
        npt.assert_equal(
            flow_graph.donors(),
            np.array([
                [m, m, m],
                [0, m, m],
                [1, 2, 3],
                [4, m, m],
                [m, m, m],
                [m, m, m],
                [5, m, m],
                [6, 7, m],
            ]),
        )
        npt.assert_equal(flow_graph.donors_count(), np.r_[0, 1, 3, 1, 0, 0, 1,
                                                          2])

        npt.assert_equal(graph_elevation, elevation)
예제 #3
0
    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.0, 1.1))
        FlowGraph(profile_grid, SingleFlowRouter())
예제 #4
0
    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.0
        grid = RasterGrid(
            [2, 2],
            [spacing, spacing],
            RasterBoundaryStatus(NodeStatus.FIXED_VALUE_BOUNDARY),
            [],
        )
        flow_graph = FlowGraph(grid, SingleFlowRouter())

        h = 1.0
        elevation = np.array([[0.0, 0.0], [h, h]], dtype="d")
        graph_elevation = flow_graph.update_routes(elevation)

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

        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, 0.0], [err, err]], dtype="d")

        np.testing.assert_allclose(erosion, expected_erosion, atol=1e-5)
        assert n_corr == 0
예제 #5
0
    def test_profile_grid(self, func, k):
        spacing = 300.0
        grid = ProfileGrid(4, 300, [NodeStatus.FIXED_VALUE_BOUNDARY] * 2, [])
        flow_graph = FlowGraph(grid, SingleFlowRouter())

        h = 1.0
        elevation = np.array([0.0, h, h, 0.0], dtype="d")
        graph_elevation = flow_graph.update_routes(elevation)

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

        dt = 1.0  # 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
        k_coef = 1e-3
        err = dt * k_coef * a**m_exp * slope**n_exp
        expected_erosion = np.array([0.0, err, err, 0.0], dtype="d")

        np.testing.assert_allclose(erosion, expected_erosion, atol=1e-5)
        assert n_corr == 0
 def test_receivers(self):
     profile_grid = ProfileGrid(8, 2.2,
                                [NodeStatus.FIXED_VALUE_BOUNDARY] * 2, [])
     flow_graph = FlowGraph(profile_grid, SingleFlowRouter(),
                            NoSinkResolver())
예제 #7
0
    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)