Skip to content

Commit 7990ebc

Browse files
committed
adressed review comments on metric coverage.PMU plot label and docs
1 parent 6788ce4 commit 7990ebc

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

modules/benchmark/R/metric_Coverage.R

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ metric_Coverage <- function(dat, ...) {
2525
PEcAn.logger::logger.info("Metric: Prediction Interval Coverage")
2626

2727
valid <- !is.na(dat$obvs) & !is.na(q_low) & !is.na(q_high)
28-
29-
if ("obvs_sd" %in% names(dat)) {
30-
valid <- valid & !is.na(dat$obvs_sd)
31-
covered <- (dat$obvs[valid] - dat$obvs_sd[valid]) <= q_high[valid] &
32-
(dat$obvs[valid] + dat$obvs_sd[valid]) >= q_low[valid]
33-
} else {
34-
covered <- dat$obvs[valid] >= q_low[valid] & dat$obvs[valid] <= q_high[valid]
28+
if (!any(valid)) {
29+
return(NA_real_)
3530
}
36-
31+
32+
covered <- dat$obvs[valid] >= q_low[valid] & dat$obvs[valid] <= q_high[valid]
3733
return(mean(covered))
3834
}

modules/benchmark/R/metric_timeseries_plot.R

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,30 @@ metric_timeseries_plot <- function(metric_dat, var, unit = NULL, filename = NA,
5050
sharpness <- mean(sub_dat$model_q95 - sub_dat$model_q05, na.rm = TRUE)
5151
bias <- mean(sub_dat$model - sub_dat$obvs, na.rm = TRUE)
5252

53+
pmu_val_str <- "N/A"
5354
pass_str <- "N/A"
5455
if ("obs_se" %in% colnames(sub_dat) && "obs_n" %in% colnames(sub_dat)) {
5556
valid_pmu <- !is.na(sub_dat$obs_se) & !is.na(sub_dat$obs_n)
5657
if (any(valid_pmu)) {
5758
se2_n <- (sub_dat$obs_se[valid_pmu]^2) * sub_dat$obs_n[valid_pmu]
5859
pooled_var <- sum(se2_n) / sum(sub_dat$obs_n[valid_pmu])
5960
pmu <- sqrt(pooled_var)
61+
pmu_val_str <- sprintf("%.2f", pmu)
6062

61-
passes_validation <- (coverage_pct >= 90) && (abs(bias) < pmu)
63+
passes_validation <- (!is.na(coverage_pct) && coverage_pct >= 90) && (abs(bias) < pmu)
6264
pass_str <- ifelse(passes_validation, "PASS", "FAIL")
6365
}
6466
}
6567

6668
data.frame(
6769
site = sub_dat$site[1],
6870
variable = sub_dat$variable[1],
69-
label = sprintf("Coverage: %.1f%%\nSharpness: %.2f\nBias: %.2f\nPMU: %s", coverage_pct, sharpness, bias, pass_str)
71+
label = sprintf("Coverage: %.1f%%\nSharpness: %.2f\nBias: %.2f\nPMU: %s\nStatus: %s", coverage_pct, sharpness, bias, pmu_val_str, pass_str)
7072
)
7173
}))
7274

7375
# Determine if model "passes" at each point based on available intervals
74-
if ("obvs_sd" %in% colnames(metric_dat)) {
75-
metric_dat$Pass <- (metric_dat$obvs - metric_dat$obvs_sd) <= metric_dat$model_q95 &
76-
(metric_dat$obvs + metric_dat$obvs_sd) >= metric_dat$model_q05
77-
} else {
78-
metric_dat$Pass <- metric_dat$obvs >= metric_dat$model_q05 & metric_dat$obvs <= metric_dat$model_q95
79-
}
76+
metric_dat$Pass <- metric_dat$obvs >= metric_dat$model_q05 & metric_dat$obvs <= metric_dat$model_q95
8077

8178
if (any(!is.na(metric_dat$Pass))) {
8279
metric_dat$Observation_Status <- ifelse(metric_dat$Pass, "Observed (Pass)", "Observed (Fail)")

modules/benchmark/R/run_benchmark.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ register_metric("COVERAGE", function(dat) {
152152
#'
153153
#' @param aligned data.frame with columns: model, obvs, time
154154
#' @param metrics character vector of metric names
155-
#' @return data.frame with columns: metric, value
155+
#' @return data.frame in wide format with columns `Site` and each requested metric column per site.
156156
compute_metrics <- function(aligned, metrics = c("RMSE", "MAE", "R2")) {
157157
# Treat data as one group if no site column
158158
if (!"site" %in% colnames(aligned)) {

0 commit comments

Comments
 (0)