Skip to content

Change order of operations for ensemble mean of derived parameters - #257

Merged
jonasbhend merged 1 commit into
mainfrom
fix/order-of-operations
Sep 11, 2026
Merged

jonasbhend merged 1 commit into
mainfrom
fix/order-of-operations

Conversation

@jonasbhend

Copy link
Copy Markdown
Contributor

For all derived quantities, the order of operation to compute the ensemble mean needs fixing. First we need to compute the derived parameter per ensemble member, then average (now we're doing it in reverse).

For aggregated parameters, this is a non-issue as long as we only compute the ensemble mean (not median or other ensemble statistics).

Summary of changes

  • change order of operations for derived parameters

sqrt(mean(U)^2 + mean(V)^2) <= mean(sqrt(U^2 + V^2))
the speed of the mean wind vector is not equal to the mean wind speed.
Derive DERIVED_PARAMS (e.g. SP_10M) per member before accumulating into
the ensemble-mean accumulator so the final division gives the correct
mean wind speed.

_disaggregated_and_derived_params already guards with
`if p in DERIVED_PARAMS and p not in ds.data_vars` so it skips
recomputing SP_10M from the now-averaged components.

@cosunae cosunae left a comment

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.

good catch.
I checked that the derived params wont be computed later on, if variables are already in ds.data_vars so this looks good to me

@jonasbhend
jonasbhend merged commit ebfc84a into main Sep 11, 2026
4 checks passed
@jonasbhend
jonasbhend deleted the fix/order-of-operations branch September 11, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants