Skip to content

Add drainagebasins #50

@ktlenz

Description

@ktlenz

Implementation should wait for the GRIDobj
drainagebasins.R distinguishes two cases

Case 1: No outlets provided

libtopotoolbox's drainagebasins function employed which requires the following arguments:

  • [output] basins (ptrdiff_t, size: dims[0] x dims[1])
  • [input] source (ptrdiff_t, size: edge_count)
  • [input] target (ptrdiff_t, size: edge_count)
  • [input] edge_count (ptrdiff_t, size: 1)
  • [input] dims (ptrdiff_t, size: 2)

Comments

  • source and target arrays are outputs of flow_routing_d8_edgelist and a property of the FLOWobj (FLOWobj$source, FLOWobj$target)
  • edge_count can be computed in drainagebasins.R from the length of the other arguments

Case 2: Outlets provided

libtopotoolbox's travers_up_u32_or_and function employed which requires the following arguments:

  • [output] output (uint32_t, size: edge_count)
  • [input] weights (uint32_t, size: edge_count)
  • [input] source (ptrdiff_t, size: edge_count)
  • [input] target (ptrdiff_t, size: edge_count)
  • [input] edge_count (ptrdiff_t, size: 1)

Comments

  • outlet indices need to be unravelled (unravel_index.FLOWobj)
  • mimic the following python lines in R:
    basins[indices] = np.arange(1, len(outlets) + 1, dtype=np.uint32)
    weights = np.full(self.source.size, 0xffffffff, dtype=np.uint32)
  • source and target arrays are outputs of flow_routing_d8_edgelist and a property of the FLOWobj (FLOWobj$source, FLOWobj$target)

Further information

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions