Commit b6432dce authored by David's avatar David
Browse files

fix(CreateInputsModel): bad handle of Diversion nodes in BasinsAreas calculation

Refs #124
Showing with 12 additions and 8 deletions
+12 -8
...@@ -481,9 +481,10 @@ hasUngaugedNodes <- function(id, griwrm) { ...@@ -481,9 +481,10 @@ hasUngaugedNodes <- function(id, griwrm) {
getNodeBasinArea <- function(i, griwrm) { getNodeBasinArea <- function(i, griwrm) {
area <- griwrm$area[i] area <- griwrm$area[i]
if (!is.na(area)) return(area) if (!is.na(area)) return(area)
Diversions <- !is.na(griwrm$model) & griwrm$model == "Diversion"
griwrm <- griwrm[getDiversionRows(griwrm, inverse = TRUE), ] if (i %in% which(Diversions)) return(NA)
UpstreamNodeRows <- which(griwrm$down == griwrm$id[i] & !is.na(griwrm$down)) UpstreamNodeRows <-
which(griwrm$down == griwrm$id[i] & !is.na(griwrm$down) & !Diversions)
if(length(UpstreamNodeRows) > 0) { if(length(UpstreamNodeRows) > 0) {
upstreamAreas <- sapply(UpstreamNodeRows, getNodeBasinArea, griwrm = griwrm) upstreamAreas <- sapply(UpstreamNodeRows, getNodeBasinArea, griwrm = griwrm)
return(sum(upstreamAreas, na.rm = TRUE)) return(sum(upstreamAreas, na.rm = TRUE))
......
...@@ -202,11 +202,14 @@ test_that("Ungauged node should inherits its FUN_MOD from the downstream gauged ...@@ -202,11 +202,14 @@ test_that("Ungauged node should inherits its FUN_MOD from the downstream gauged
}) })
test_that("Network with Diversion works", { test_that("Network with Diversion works", {
n_div <- rbind(nodes, data.frame(id = "54029", n_div <- rbind(
down = "54002", data.frame(id = "54029",
length = 20, down = "54002",
model = "Diversion", length = 20,
area = NA)) model = "Diversion",
area = NA),
nodes
)
g <- CreateGRiwrm(n_div) g <- CreateGRiwrm(n_div)
Qobs = matrix(-1, nrow = length(DatesR), ncol = 1) Qobs = matrix(-1, nrow = length(DatesR), ncol = 1)
colnames(Qobs) = "54029" colnames(Qobs) = "54029"
......
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