Skip to content

Commit 7936b3f

Browse files
authored
Constrain MAC-filled values to the variable's range (#450)
1 parent c05aa9b commit 7936b3f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

pipeline/L2.qmd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ for(i in seq_len(nrow(site_rn_table))) {
289289
# Transfer good values into gap-fill column
290290
nagf <- is.na(dat_gf$Value_MAC)
291291
dat_gf$Value_MAC[nagf] <- dat_gf$Value[nagf]
292+
293+
# MAC values are not allowed to drift outside of
294+
# the limits defined in variables_metadata.csv
295+
rni <- which(rn == vmd_combined$research_name)
296+
if(length(rni) == 1) { # i.e., if research name exists in table
297+
lb <- vmd_combined$low_bound[rni]
298+
if(!is.na(lb)) { # if a low bound is defined, truncate to it
299+
dat_gf$Value_MAC[dat_gf$Value_MAC < lb] <- lb
300+
}
301+
hb <- vmd_combined$high_bound[rni]
302+
if(!is.na(hb)) { # if a high bound is defined, truncate to it
303+
dat_gf$Value_MAC[dat_gf$Value_MAC > hb] <- hb
304+
}
305+
}
306+
292307
message("\tGap filled ",
293308
sum(is.na(dat_gf$Value)) - sum(is.na(dat_gf$Value_MAC)),
294309
" values in ", these_files$filename[j])

0 commit comments

Comments
 (0)