Skip to content

Commit

Permalink
bugfix for patricia g: resetting by DOY
Browse files Browse the repository at this point in the history
  • Loading branch information
stineb committed Aug 7, 2024
1 parent 9984aee commit 3567ebb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/cwd.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ cwd <- function(df, varname_wbal, varname_date, thresh_terminate = 0.0, thresh_d
# continue accumulating deficit as long as the deficit has not fallen below (thresh_terminate) times the maximum deficit attained in this event
# optionally
while (iidx <= (nrow(df)-1) && # avoid going over row length
(deficit - df[[ varname_wbal ]][iidx] > thresh_terminate * max_deficit) &&
df$doy[iidx] < doy_reset
(deficit - df[[ varname_wbal ]][iidx] > thresh_terminate * max_deficit)
){

dday <- dday + 1
Expand All @@ -88,6 +87,13 @@ cwd <- function(df, varname_wbal, varname_date, thresh_terminate = 0.0, thresh_d
done_finding_dropday <- TRUE
}

# stop accumulating on re-set day
if (df$doy[iidx] == doy_reset){
iidx_drop <- iidx
max_deficit <- deficit
break
}

# once, deficit has fallen below threshold, all subsequent dates are dropped (dday set to NA)
if (done_finding_dropday){
df$iinst[iidx] <- NA
Expand Down

0 comments on commit 3567ebb

Please sign in to comment.