Commit 485be9f0 authored by David's avatar David
Browse files

fix(getNodeRanking): wrong sorting between sibling and upstream ungauged with same donor

- fix & test

Refs #155
2 merge requests!93Draft: Version 0.7.0,!87Resolve "Wrong sorting for calibration of ungauged nodes"
Pipeline #55518 passed with stage
in 7 minutes and 43 seconds
Showing with 15 additions and 1 deletion
+15 -1
......@@ -40,7 +40,10 @@ getNodeRanking <- function(griwrm) {
# Check if upstream nodes have already been processed
immediate_upstream_nodes <- g$id[!is.na(g$down) & g$down %in% g2$id]
immediate_upstream_nodes <- immediate_upstream_nodes[!immediate_upstream_nodes %in% g2$id]
if (all(immediate_upstream_nodes %in% r)) {
if (all(immediate_upstream_nodes %in% r) &&
(upDonor %in% r || isNodeDownstream(g2, upId, upDonor))) {
areNodesUpstreamDonor <- sapply(g2$id, function(id) isNodeDownstream(g2, id, upDonor))
g2 <- g2[upDonor %in% r | g2$id == upDonor | areNodesUpstreamDonor, ]
g2$donor <- g2$id
ungaugedIds <- getNodeRanking(g2)
r <- c(r, ungaugedIds)
......
......@@ -55,3 +55,14 @@ test_that("Impossible case detected: ungauged node with diversion to an upstream
area = NA))
expect_error(CreateGRiwrm(nodes_div))
})
test_that("donor of ungauged cluster is processed before sibling ungauged nodes (#155)", {
n155 <- data.frame(id = c("UngSib", "UngUp", "Donor", "Down"),
down = c("Down", "Donor", "Down", NA),
length = c(rep(1, 3), NA),
model = c("Ungauged", "Ungauged", "RunModel_GR4J", "RunModel_GR4J"),
area = rep(1,4),
donor = c("Donor", NA, NA, NA))
g155 <- CreateGRiwrm(n155)
expect_equal(getNodeRanking(g155), c("UngUp", "Donor", "UngSib", "Down"))
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment