Document unweighted spatial mean, add mean vs average tests#944
Open
ecomodeller wants to merge 2 commits into
Open
Document unweighted spatial mean, add mean vs average tests#944ecomodeller wants to merge 2 commits into
ecomodeller wants to merge 2 commits into
Conversation
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.
ecomodeller
commented
May 27, 2026
|
|
||
| def mean(self, axis: int | str | None = 0, **kwargs: Any) -> DataArray: | ||
| """Mean value along an axis. | ||
| """Unweighted mean value along an axis. |
Member
Author
There was a problem hiding this comment.
@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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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