Skip to content
Open
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
22 changes: 9 additions & 13 deletions src/plots/plots_timeseries.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,32 @@
return(data)
}


.obsFitActiveObsDataPostProcessingFunction <- function(data, ...) {
.rms <- function(x) {
n <- sum(!is.na(x))
if(n == 0) return(NA_real_)
sqrt(sum(x^2, na.rm=TRUE) / n)
}

# Preserve attributes
# Store original column-level attributes (e.g. units)
# so we can reattach them later
oldColAttrs <- lapply(names(data), function(nm) attributes(data[[nm]]))
names(oldColAttrs) <- names(data)

# Convert to data.table
dt <- as.data.table(data)
dt <- fillDataWithQualityControlStatus(dt)

# Filter for active
dt <- dt[grepl("active", tolower(status))]

# Summarize by:
# - nobs_total
# - keep fg_dep, an_dep for next group operation
dt <- dt[, .(
nobs_total = .N,
fg_dep = fg_dep,
an_dep = an_dep
), by=.(DTG, level, varname)]

# Now compute rms and bias by groups
dt <- dt[, .(
# total number of obs in this group
nobs_total = .N,
fg_rms_total = sqrt(sum((fg_dep - mean(fg_dep, na.rm=TRUE))^2, na.rm=TRUE) / sum(!is.na(fg_dep))),
an_rms_total = sqrt(sum((an_dep - mean(an_dep, na.rm=TRUE))^2, na.rm=TRUE) / sum(!is.na(an_dep))),
fg_rms_total = .rms(fg_dep),
an_rms_total = .rms(an_dep),
fg_bias_total = mean(fg_dep, na.rm=TRUE),
an_bias_total = mean(an_dep, na.rm=TRUE)
Comment on lines 47 to 53
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated RMS/bias aggregation for the new "ObsFit (Active Observations Only)" plot isn’t covered by tests. Consider adding a testthat case that feeds a small synthetic dataset through .obsFitActiveObsDataPostProcessingFunction and asserts: (1) only rows with an "active" status are included, (2) fg_rms_total/an_rms_total match the intended RMS formula, and (3) all-NA groups return NA_real_ instead of propagating unexpected values.

Copilot uses AI. Check for mistakes.
), by=.(DTG, level, varname)]
Expand Down
Loading