Skip to content

Add Z axis support for spatial averaging  #596

@tomvothecoder

Description

@tomvothecoder

Discussed in #591

Originally posted by tomvothecoder January 29, 2024

Is your feature request related to a problem?

I'm running into a case where I need to average over the Z axis. The CDAT code being used is cdutil.averager(tvar, axis="z"), which I need to replace.

xCDAT's spatial averager, which is based on cdutil.averager(), only supports rectilinear grids ("X" and "Y"). However, we do mention that the get_weights() method can be extended to support other axes:

xcdat/xcdat/spatial.py

Lines 246 to 252 in fbf1db6

Notes
-----
This method was developed for rectilinear grids only. ``get_weights()``
recognizes and operate on latitude and longitude, but could be extended
to work with other standard geophysical dimensions (e.g., time, depth,
and pressure).
"""

Are there are any possible answers you came across?

No response

Describe alternatives you've considered

No response

Additional context

For the short-term, I might be able to use xarray.DataArray.weighted directly. However, I still need to generate the weights xr.DataArray beforehand.

datarray.weighted(weights).mean("height")

Metadata

Metadata

Type

No type

Projects

Status

In Review

Relationships

None yet

Development

No branches or pull requests

Issue actions