Skip to content

Bugfix for new plot "ObsFit (Active Observations Only)"#42

Merged
ewhelan merged 5 commits intoHirlam:masterfrom
dschoenach:patch-1
Mar 24, 2026
Merged

Bugfix for new plot "ObsFit (Active Observations Only)"#42
ewhelan merged 5 commits intoHirlam:masterfrom
dschoenach:patch-1

Conversation

@dschoenach
Copy link
Copy Markdown
Contributor

Misbehaviour discovered by Reima and should now work as intended.

Misbehaviour discovered by Reima and should now work as intended.
Copilot AI review requested due to automatic review settings February 17, 2026 13:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the data post-processing for the new timeseries plot “ObsFit (Active Observations Only)” so that RMS metrics are computed correctly from per-observation departures after filtering to active observations.

Changes:

  • Add a local .rms() helper to compute RMS with NA-safe handling (returns NA_real_ when a group has no non-NA values).
  • Simplify the post-processing by removing an intermediate, redundant grouping step and computing group summaries in a single data.table aggregation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 47 to 53
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)
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be neater to do this:

fg_rms_total = sqrt(mean(fg_dep^2, na.rm = TRUE))
an_rms_total = sqrt(mean(an_dep^2 na.rm = TRUE))

Then, you do not need to define .rms.

@ewhelan ewhelan self-assigned this Mar 24, 2026
@ewhelan ewhelan self-requested a review March 24, 2026 10:39
@ewhelan ewhelan added the bug Something isn't working label Mar 24, 2026
Comment thread src/plots/plots_timeseries.R Outdated
oldColAttrs <- lapply(names(data), function(nm) attributes(data[[nm]]))
names(oldColAttrs) <- names(data)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove this whitespace change please.

Comment on lines 47 to 53
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be neater to do this:

fg_rms_total = sqrt(mean(fg_dep^2, na.rm = TRUE))
an_rms_total = sqrt(mean(an_dep^2 na.rm = TRUE))

Then, you do not need to define .rms.

@ewhelan ewhelan merged commit efbf7f3 into Hirlam:master Mar 24, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants