Skip to content

Document unweighted spatial mean, add mean vs average tests#944

Open
ecomodeller wants to merge 2 commits into
mainfrom
test/mean-vs-average-spatial
Open

Document unweighted spatial mean, add mean vs average tests#944
ecomodeller wants to merge 2 commits into
mainfrom
test/mean-vs-average-spatial

Conversation

@ecomodeller

Copy link
Copy Markdown
Member

Why

mean(axis="space") on unstructured meshes is unweighted — all elements contribute equally regardless of area. On HD2D.dfsu, where the largest element is 15x the smallest, this gives biased results. Users must use average(weights=area) for correct area-weighted means, but nothing in the API or docstrings warns about this.

What this adds

  • 4 tests demonstrating the difference on variable meshes, agreement on uniform grids, and a synthetic known-weights case
  • Updates mean() and nanmean() docstrings to note they are unweighted and reference average()

Tests demonstrate that mean(axis='space') is unweighted and differs
from area-weighted average() on variable meshes. Updates mean() and
nanmean() docstrings to warn users and reference average().
Quartodoc doesn't support sphinx cross-reference syntax.

def mean(self, axis: int | str | None = 0, **kwargs: Any) -> DataArray:
"""Mean value along an axis.
"""Unweighted mean value along an axis.

@ecomodeller ecomodeller May 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@otzi5300 I was about to add this clarification. Based on the discussion related to vertical mean, maybe the semantics of mean should change and take area/volume into account, instead of doing the naive mean?

But thinking about this for 10 sec, it seems safer to add a new method or argument to do weighted aggregations. #979

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.

1 participant