コード例 #1
0
def test_boundary_to_n():
    r = np.array([
        [1, 2],
        [4, 5],
        [1, 5],
        [6, 2],
        [4, -1],
        [4, -1],
        [5, 7],
        [4, 5],
        [6, 7],
        [7, 8],
    ])
    p = np.array([
        [0.6, 0.4],
        [0.85, 0.15],
        [0.65, 0.35],
        [0.9, 0.1],
        [1.0, 0.0],
        [1.0, 0.0],
        [0.75, 0.25],
        [0.55, 0.45],
        [0.8, 0.2],
        [0.95, 0.05],
    ])
    s = np.array([4, 5, 1, 7, 2, 6, 0, 8, 3, 9])

    a, q = find_drainage_area_and_discharge_to_n(s, r, p, boundary_nodes=[0])
    true_a = np.array(
        [0.0, 1.715, 1.1, 1.0, 9.0, 4.9775, 2.74, 2.845, 1.05, 1.0])
    assert np.allclose(a, true_a)
コード例 #2
0
ファイル: test_flow_accums.py プロジェクト: cmshobe/landlab
def test_boundary_to_n():
    r = np.array(
        [
            [1, 2],
            [4, 5],
            [1, 5],
            [6, 2],
            [4, -1],
            [4, -1],
            [5, 7],
            [4, 5],
            [6, 7],
            [7, 8],
        ]
    )
    p = np.array(
        [
            [0.6, 0.4],
            [0.85, 0.15],
            [0.65, 0.35],
            [0.9, 0.1],
            [1., 0.],
            [1., 0.],
            [0.75, 0.25],
            [0.55, 0.45],
            [0.8, 0.2],
            [0.95, 0.05],
        ]
    )
    s = np.array([4, 5, 1, 7, 2, 6, 0, 8, 3, 9])

    a, q = find_drainage_area_and_discharge_to_n(s, r, p, boundary_nodes=[0])
    true_a = np.array([0., 1.715, 1.1, 1., 9., 4.9775, 2.74, 2.845, 1.05, 1.])
    assert np.allclose(a, true_a)
コード例 #3
0
 def _accumulate_A_Q_to_n(self, s, r, p):
     """
     Accumulate area and discharge for a route-to-many scheme. Note this
     can be overridden in inherited components.
     """
     a, q = flow_accum_to_n.find_drainage_area_and_discharge_to_n(
         s, r, p, self.node_cell_area,
         self._grid.at_node["water__unit_flux_in"])
     return (a, q)
コード例 #4
0
ファイル: flow_accumulator.py プロジェクト: landlab/landlab
    def _accumulate_A_Q_to_n(self, s, r, p):
        """Accumulate area and discharge for a route-to-many scheme.

        Note this can be overridden in inherited components.
        """
        a, q = flow_accum_to_n.find_drainage_area_and_discharge_to_n(
            s, r, p, self.node_cell_area, self._grid.at_node["water__unit_flux_in"]
        )
        return (a, q)
コード例 #5
0
ファイル: flow_accumulator.py プロジェクト: awickert/landlab
    def accumulate_flow(self, update_flow_director=True):
        """
        Function to make FlowAccumulator calculate drainage area and discharge.

        Running run_one_step() results in the following to occur:
            1. Flow directions are updated (unless update_flow_director is set
            as False).
            2. Intermediate steps that analyse the drainage network topology
            and create datastructures for efficient drainage area and discharge
            calculations.
            3. Calculation of drainage area and discharge.
            4. Depression finding and mapping, which updates drainage area and
            discharge.
        """
        # step 1. Find flow directions by specified method
        if update_flow_director == True:
            self.flow_director.run_one_step()

        # further steps vary depending on how many recievers are present
        # one set of steps is for route to one (D8, Steepest/D4)
        if self.flow_director.to_n_receivers == 'one':

            # step 3. Run depression finder if passed
            # Depression finder reaccumulates flow at the end of its routine.
            if self.depression_finder_provided is not None:

                self.depression_finder.map_depressions()

                a = self._grid['node']['drainage_area']
                q = self._grid['node']['surface_water__discharge']

            else:
                # step 2. Get r
                r = self._grid['node']['flow__receiver_node']

                # step 2. Stack, D, delta construction
                nd = flow_accum_bw._make_number_of_donors_array(r)
                delta = flow_accum_bw._make_delta_array(nd)
                D = flow_accum_bw._make_array_of_donors(r, delta)
                s = flow_accum_bw.make_ordered_node_array(r)

                # put theese in grid so that depression finder can use it.
                # store the generated data in the grid
                self._grid['node']['flow__data_structure_delta'][:] = delta[1:]
                self._grid['link']['flow__data_structure_D'][:len(D)] = D
                self._grid['node']['flow__upstream_node_order'][:] = s

                # step 4. Accumulate (to one or to N depending on direction method. )
                a, q = flow_accum_bw.find_drainage_area_and_discharge(s,
                                                                      r,
                                                                      self.node_cell_area,
                                                                      self._grid.at_node['water__unit_flux_in'])
                self._grid['node']['drainage_area'][:] = a
                self._grid['node']['surface_water__discharge'][:] = q

        else:
            # step 2. Get r and p
            r = self._grid['node']['flow__receiver_nodes']
            p = self._grid['node']['flow__receiver_proportions']

            # step 2. Stack, D, delta construction
            nd = flow_accum_to_n._make_number_of_donors_array_to_n(r, p)
            delta = flow_accum_to_n._make_delta_array_to_n(nd)
            D = flow_accum_to_n._make_array_of_donors_to_n(r, p, delta)
            s = flow_accum_to_n.make_ordered_node_array_to_n(r, p)

            # put theese in grid so that depression finder can use it.
            # store the generated data in the grid
            self._grid['node']['flow__data_structure_delta'][:] = delta[1:]

            if self._is_raster:
                tempD = BAD_INDEX_VALUE * np.ones((self._grid.number_of_links*2))
                tempD[:len(D)] = D
                self._grid['link']['flow__data_structure_D'][:] = tempD.reshape((self._grid.number_of_links, 2))
            else:
                self._grid['link']['flow__data_structure_D'][:len(D)] = D
            self._grid['node']['flow__upstream_node_order'][:] = s

            # step 3. Run depression finder if passed
            # at present this must go at the end.

            # step 4. Accumulate (to one or to N depending on direction method. )
            a, q = flow_accum_to_n.find_drainage_area_and_discharge_to_n(s,
                                                                         r,
                                                                         p,
                                                                         self.node_cell_area,
                                                                         self._grid.at_node['water__unit_flux_in'])
            # store drainage area and discharge.
            self._grid['node']['drainage_area'][:] = a
            self._grid['node']['surface_water__discharge'][:] = q

            # at the moment, this is where the depression finder needs to live.
            if self.depression_finder_provided is not None:
                self.depression_finder.map_depressions()

        return (a, q)
コード例 #6
0
ファイル: flow_accumulator.py プロジェクト: eladante/landlab
    def accumulate_flow(self, update_flow_director=True):
        """
        Function to make FlowAccumulator calculate drainage area and discharge.

        Running run_one_step() results in the following to occur:
            1. Flow directions are updated (unless update_flow_director is set
            as False).
            2. Intermediate steps that analyse the drainage network topology
            and create datastructures for efficient drainage area and discharge
            calculations.
            3. Calculation of drainage area and discharge.
            4. Depression finding and mapping, which updates drainage area and
            discharge.
        """
        # step 1. Find flow directions by specified method
        if update_flow_director == True:
            self.flow_director.run_one_step()

        # further steps vary depending on how many recievers are present
        # one set of steps is for route to one (D8, Steepest/D4)
        if self.flow_director.to_n_receivers == "one":

            # step 3. Run depression finder if passed
            # Depression finder reaccumulates flow at the end of its routine.
            if self.depression_finder_provided is not None:

                self.depression_finder.map_depressions()

                a = self._grid["node"]["drainage_area"]
                q = self._grid["node"]["surface_water__discharge"]

            else:
                # step 2. Get r
                r = self._grid["node"]["flow__receiver_node"]

                # step 2. Stack, D, delta construction
                nd = flow_accum_bw._make_number_of_donors_array(r)
                delta = flow_accum_bw._make_delta_array(nd)
                D = flow_accum_bw._make_array_of_donors(r, delta)
                s = flow_accum_bw.make_ordered_node_array(r)

                # put theese in grid so that depression finder can use it.
                # store the generated data in the grid
                self._grid["node"]["flow__data_structure_delta"][:] = delta[1:]
                self._grid["link"]["flow__data_structure_D"][:len(D)] = D
                self._grid["node"]["flow__upstream_node_order"][:] = s

                # step 4. Accumulate (to one or to N depending on direction method. )
                a, q = flow_accum_bw.find_drainage_area_and_discharge(
                    s, r, self.node_cell_area,
                    self._grid.at_node["water__unit_flux_in"])
                self._grid["node"]["drainage_area"][:] = a
                self._grid["node"]["surface_water__discharge"][:] = q

        else:
            # step 2. Get r and p
            r = self._grid["node"]["flow__receiver_node"]
            p = self._grid["node"]["flow__receiver_proportions"]

            # step 2. Stack, D, delta construction
            nd = flow_accum_to_n._make_number_of_donors_array_to_n(r, p)
            delta = flow_accum_to_n._make_delta_array_to_n(nd)
            D = flow_accum_to_n._make_array_of_donors_to_n(r, p, delta)
            s = flow_accum_to_n.make_ordered_node_array_to_n(r, p)

            # put theese in grid so that depression finder can use it.
            # store the generated data in the grid
            self._grid["node"]["flow__data_structure_delta"][:] = delta[1:]

            if self._is_raster:
                tempD = BAD_INDEX_VALUE * np.ones(
                    (self._grid.number_of_links * 2))
                tempD[:len(D)] = D
                self._grid["link"][
                    "flow__data_structure_D"][:] = tempD.reshape(
                        (self._grid.number_of_links, 2))
            else:
                self._grid["link"]["flow__data_structure_D"][:len(D)] = D
            self._grid["node"]["flow__upstream_node_order"][:] = s

            # step 3. Run depression finder if passed
            # at present this must go at the end.

            # step 4. Accumulate (to one or to N depending on direction method. )
            a, q = flow_accum_to_n.find_drainage_area_and_discharge_to_n(
                s, r, p, self.node_cell_area,
                self._grid.at_node["water__unit_flux_in"])
            # store drainage area and discharge.
            self._grid["node"]["drainage_area"][:] = a
            self._grid["node"]["surface_water__discharge"][:] = q

            # at the moment, this is where the depression finder needs to live.
            # at the moment, no depression finders work with to-many
            # if self.depression_finder_provided is not None:
            #     self.depression_finder.map_depressions()

        return (a, q)