Skip to content

Commit

Permalink
Include sapflux tree reassignment and fix valid_entries() sorting bug (
Browse files Browse the repository at this point in the history
…#98)

* Fix two bugs in date-handling and data frame sorting; this ensures that valid_through entries are handled correctly
* Account for C8->C19 reassignment in TEMPEST control ( #86 )
  • Loading branch information
bpbond authored Jan 19, 2024
1 parent d959b49 commit 242e341
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion synoptic/L1_normalize.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ f <- function(fn, out_dir, design_table) {
# (in helpers.R) to figure out which mappings should apply.
message("\tChecking for multiple-match design links...")
dat_retain <- valid_entries(objects = dat$loggernet_variable,
times = ymd_hms(dat$TIMESTAMP, tz = "EST"),
times = substr(dat$TIMESTAMP, 1, 10), # isolate YYYY-MM-DD
valid_through = dat$valid_through)
message("\tDropping ", sum(!dat_retain), " out-of-date design links")
dat <- dat[dat_retain,]
dat$valid_through <- NULL
Expand Down
5 changes: 4 additions & 1 deletion synoptic/data_TEST/design_table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,10 @@ TMP,PNNL_11,sapflow,Format,,,,
TMP,PNNL_11,sapflow,RECORD,,,,
TMP,PNNL_11,sapflow,Statname,,,,
TMP,PNNL_11,sapflow,BattV_Avg,SF_BattV-TMP-C-11,,voltage,
TMP,PNNL_11,sapflow,DiffVolt_Avg({1:6}),"SF-TMP-C-{C7,C19,C10,C11,C16,C18}",,sapflow_2.5cm,
TMP,PNNL_11,sapflow,DiffVolt_Avg(1),SF-TMP-C-C7,,sapflow_2.5cm,
TMP,PNNL_11,sapflow,DiffVolt_Avg(2),SF-TMP-C-C8,2022-06-03,sapflow_2.5cm,C8 (Tree 1436) died; reassigned to C19
TMP,PNNL_11,sapflow,DiffVolt_Avg(2),SF-TMP-C-C19,,sapflow_2.5cm,C8 (Tree 1436) died; reassigned to C19
TMP,PNNL_11,sapflow,DiffVolt_Avg({3:6}),"SF-TMP-C-{C10,C11,C16,C18}",,sapflow_2.5cm,
TMP,PNNL_11,sapflow,DiffVolt_Avg(7),SF-TMP-C-C10D,,sapflow_5cm,
TMP,PNNL_11,sapflow,DiffVolt_Avg({8:14}),,,,
TMP,PNNL_11,sapflow,DiffVolt({1:14}),,,,
Expand Down
3 changes: 2 additions & 1 deletion synoptic/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,15 @@ valid_entries <- function(objects, times, valid_through) {
past_valid_time <- times > valid_through

# Create a data frame to aggregate and then merge, below
x <- data.frame(obj = objects, time = times, vu = valid_through)
x <- data.frame(num = seq_along(objects), obj = objects, time = times, vu = valid_through)
# Compute the minimum valid_through entry for each object and time that is
# not past the valid_through point; this is the 'controlling' value
y <- aggregate(vu ~ obj + time, data = x[!past_valid_time,], FUN = min)
names(y)[3] <- "controlling"

# Figure out controlling valid_through for each object/time
z <- merge(x, y, all.x = TRUE)
z <- z[order(z$num),] # ensure in correct original order
# An NA controlling entry means there is none
valids <- z$vu == z$controlling
valids[is.na(valids)] <- FALSE
Expand Down

0 comments on commit 242e341

Please sign in to comment.