Skip to content

Implements zonal and mean methods in UxDataset; fixes weighted_mean() dims order assumption - #1803

Open
Sevans711 wants to merge 7 commits into
mainfrom
sevans/UxDataset-zonal_mean
Open

Sevans711 wants to merge 7 commits into
mainfrom
sevans/UxDataset-zonal_mean

Conversation

@Sevans711

Copy link
Copy Markdown
Collaborator

Closes #1801 (sub-issue of #1734)
Closes #1800

Overview

Solves #1801 by implementing UxDataset.zonal_mean(), .zonal_average(), .zonal_anomaly(), .azimuthal_mean(), .azimuthal_average(), and .weighted_mean(). These use the new UxDataset._apply_across_data_vars helper function, which should be very useful when addressing other sub-issues of #1734.

Solves #1800 by updating weighted_mean code and docstring accordingly.

Corresponding readthedocs notebooks have been updated to include these new features, with simple examples for zonal_mean and azimuthal_mean, and a more detailed example for weighted_mean. Added relevant tests into test_dataset.py and test_weighted_mean.py.

Expansions of scope:

  • Improved zonal_mean() docstring to be more honest and to clarify the different possible output shapes.
  • (Design decision) used some keyword-only arguments in these new methods (see Utilize keyword-only arguments, at least in public API #1573) even though their UxDataArray counterparts do not require keyword-only arguments. Keyword-only restrictions are easy to lift later if needed (doesn't break backwards compatibility) but hard to introduce later (requires a deprecation cycle).
  • Added support for xr.DataArray inputs to weighted_mean().
  • Added clear DimensionError in weighted_mean() if user-provided weights have the wrong number of dimensions.
  • Added missing link to "7. Zonal Anomalies" section, at top of zonal-average.ipynb.

Sidenote: I didn't make any edits to the bottom of the zonal-average.ipynb (lines 700+) myself, those are all from automatic ruff formatting.

Expected Usage

import uxarray as ux
uxds = ux.tutorial.open_dataset("outCSne30-timeseries")
uxds.zonal_mean()
uxds.zonal_anomaly()
uxds.azimuthal_mean(center_coord=(45, 0), outer_radius=50, radius_step=10)
uxds.weighted_mean()

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)
  • [N/A] If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)
  • If touched any notebook files, cleared the output of all cells before committing
  • [N/A] If added new notebook files, put into appropriate directories and referenced in appropriate files

AI Disclosure

AI Usage: Claude mostly just to settle on design for the new helper function; GitHub Copilot's inline code suggestions.

  • I have tested and take responsibility for all AI-generated content in my PR.

adds UxDataset.zonal_mean, zonal_average, zonal_anomaly, azimuthal_mean, azimuthal_average, weighted_mean (see #1800).

improves UxDataArray.zonal_mean docstring.

fixes UxDataArray.weighted_mean bugs (see #1800) and improves its docstring.

Adds private methods: _grid_dims and _grid_dim, and UxDataset._apply_across_data_vars
(sidenote: some UxDataset.weighted_mean tests are already covered by test_weighted_mean.py)
@Sevans711 Sevans711 added bug Something isn't working new feature New user-facing functionality labels Oct 1, 2026
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working new feature New user-facing functionality

Projects

None yet

1 participant