Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include sapflux tree reassignment and fix valid_entries() sorting bug #98

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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