Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-Conservative Zonal Mean #1004

Open
wants to merge 77 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
32b7a2d
Zonal mean with fast cross sections
philipc2 Oct 10, 2024
9c06917
docstring
philipc2 Oct 10, 2024
5a6c967
Merge branch 'main' into philipc2/zonal-average
philipc2 Oct 10, 2024
e1e9ef6
work on zonal
philipc2 Oct 12, 2024
9fa0dc3
Merge branch 'main' into philipc2/zonal-average
philipc2 Oct 12, 2024
40101f4
implement get_weights, integrate into calculation
philipc2 Oct 13, 2024
950f8b0
add weights module
philipc2 Oct 13, 2024
1766273
revert benchmark changes
philipc2 Oct 13, 2024
4e1e841
work on handling north and south pole case
philipc2 Oct 14, 2024
630c9b4
Merge branch 'main' into philipc2/zonal-average
philipc2 Oct 21, 2024
84ef18e
Merge branch 'main' into philipc2/zonal-average
philipc2 Oct 23, 2024
8138790
Merge branch 'main' into philipc2/zonal-average
philipc2 Oct 31, 2024
97a2d2b
pole point indices
philipc2 Nov 4, 2024
e19dce3
Merge branch 'main' into philipc2/zonal-average
philipc2 Nov 8, 2024
2e02bbe
run pre-commit
philipc2 Nov 8, 2024
b23fb26
merge main
philipc2 Nov 8, 2024
5943646
remove cached pole indices for now
philipc2 Nov 8, 2024
6334fbc
add user guide notebook
philipc2 Nov 8, 2024
f0f6591
add tests
philipc2 Nov 8, 2024
ad67e1e
docstrings
philipc2 Nov 8, 2024
b960cfe
add image and work on spherical example
philipc2 Nov 8, 2024
ab38557
add case for extreme lat
philipc2 Nov 8, 2024
9c8ea10
Merge branch 'main' into philipc2/zonal-average
philipc2 Nov 20, 2024
f3975ba
merge
philipc2 Nov 20, 2024
d1e0eec
update API and restore files
philipc2 Nov 20, 2024
779dc8f
delete figure that is not needed
philipc2 Nov 20, 2024
ccc1feb
notebook
philipc2 Nov 20, 2024
535407d
update notebook
philipc2 Nov 20, 2024
b01aedb
fix failing test
philipc2 Nov 20, 2024
4a4d66d
remove non-bounds test case
philipc2 Nov 20, 2024
721c9e4
update docstrings
philipc2 Nov 20, 2024
aba6a20
fix parameter
philipc2 Nov 20, 2024
e8e020a
clean up docstrings
philipc2 Nov 20, 2024
329e343
add tests
philipc2 Nov 20, 2024
7d92a79
merge main
philipc2 Nov 22, 2024
4601ee4
clean notebook
philipc2 Nov 22, 2024
782c1fc
Merge branch 'main' into philipc2/zonal-average
philipc2 Nov 26, 2024
f0d6197
clean up test comments
philipc2 Nov 28, 2024
33d27d9
remove edge weights for now and update api ref
philipc2 Nov 28, 2024
ae0726f
update extreme docstring
philipc2 Nov 28, 2024
7a4539a
fix docstring
philipc2 Dec 2, 2024
e47c1fc
fix docstring
philipc2 Dec 2, 2024
218a830
remove unused plot util function
philipc2 Dec 3, 2024
bc90791
clean up accessor.py and include docstrings
philipc2 Dec 3, 2024
b4d0dde
update test
philipc2 Dec 3, 2024
611be54
update test case
philipc2 Dec 3, 2024
c1c7cc6
Merge branch 'main' into philipc2/zonal-average
philipc2 Dec 3, 2024
ecd3aa5
use correct weights
philipc2 Dec 4, 2024
9d1112f
use bounds directly without converting to degrees
philipc2 Dec 5, 2024
ff4a0eb
debugging
philipc2 Dec 6, 2024
f69ed33
debugging
hongyuchen1030 Dec 6, 2024
810a6c9
Merge branch 'philipc2/zonal-average' of https://github.com/UXARRAY/u…
hongyuchen1030 Dec 6, 2024
5ec0586
merge main
philipc2 Dec 17, 2024
80b618b
remove unused code in Grid
philipc2 Dec 17, 2024
3045d57
update tests
philipc2 Dec 17, 2024
afe8f8d
remove debug print and copy
philipc2 Dec 17, 2024
21213f1
clean up grid
philipc2 Dec 17, 2024
93bc29c
use fma to prevent singular matrix
philipc2 Dec 17, 2024
8388788
use numba for jacobian
philipc2 Dec 17, 2024
61e9fba
update jacobian and work on weight optimization
philipc2 Dec 17, 2024
7711e4d
update bench
philipc2 Dec 17, 2024
5819ea3
merge main
philipc2 Jan 13, 2025
47a1e12
revisions
philipc2 Jan 13, 2025
f56da87
update notebook
philipc2 Jan 13, 2025
51822c6
update docstring and notebook
philipc2 Jan 13, 2025
473043b
use polars instead of pandas
philipc2 Jan 13, 2025
5500c5b
remove comments
philipc2 Jan 13, 2025
ae69a40
update weight assertion
philipc2 Jan 13, 2025
f13c89b
remove commented out code
philipc2 Jan 13, 2025
54cd2c8
Merge branch 'main' into philipc2/zonal-average
philipc2 Jan 13, 2025
543c33e
Merge branch 'main' into philipc2/zonal-average
philipc2 Jan 13, 2025
73513d7
merge main, address hongyus review
philipc2 Jan 16, 2025
cc968e5
correct zonal mean at pole test
philipc2 Jan 16, 2025
221f947
initial refacor of weights, need to clean up
philipc2 Jan 17, 2025
ef14dad
merge main
philipc2 Jan 17, 2025
ea145ad
clean up docstrings
philipc2 Jan 17, 2025
f2d69c0
add zonal average alais, update docstrings
philipc2 Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions uxarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from uxarray.remap import UxDataArrayRemapAccessor
from uxarray.cross_sections import UxDataArrayCrossSectionAccessor
from uxarray.core.aggregation import _uxda_grid_aggregate
from uxarray.core.zonal import _compute_zonal_mean

import warnings
from warnings import warn
Expand Down Expand Up @@ -428,6 +429,38 @@ def integrate(

return uxda

def zonal_mean(self, lat=(-90, 90, 5), method="fast"):
if not self._face_centered() and not self._edge_centered():
raise NotImplementedError(
"Zonal mean computations are currently only supported for face-centered or edge-centered data variables."
)

if isinstance(lat, tuple):
# zonal mean over a range of latitudes
latitudes = np.arange(lat[0], lat[1] + lat[2], lat[2])

elif isinstance(lat, (float, int)):
# zonal mean over a single latitude
latitudes = [lat]

# Compute Zonal Mean
res = _compute_zonal_mean(
uxda=self, data_mapping=self.dims[-1], latitudes=latitudes, method=method
)

dims = list(self.dims[:-1]) + ["latitudes"]

# Result is stored and returned as a UxDataArray
uxda = UxDataArray(
res,
uxgrid=self.uxgrid,
dims=dims,
coords={"latitudes": latitudes},
name=self.name + "_zonal_mean" if self.name is not None else "zonal_mean",
)

return uxda

def topological_mean(
self,
destination: Literal["node", "edge", "face"],
Expand Down
25 changes: 25 additions & 0 deletions uxarray/core/zonal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
import dask.array as da


def _compute_zonal_mean(uxda, data_mapping, latitudes, method="fast"):
# Select the appropriate function based on the data_mapping
if data_mapping == "n_face":
get_indices_func = uxda.uxgrid.get_faces_at_constant_latitude
else:
get_indices_func = uxda.uxgrid.get_edges_at_constant_latitude

# Create a result array based on whether Dask is being used
shape = uxda.shape[:-1] + (len(latitudes),)
if isinstance(uxda.data, da.Array):
# Create a Dask array for storing results
averages = da.empty(shape, dtype=uxda.dtype)
else:
# Create a NumPy array for storing results
averages = np.empty(shape, dtype=uxda.dtype)

for i, lat in enumerate(latitudes):
indices = get_indices_func(lat, method)
philipc2 marked this conversation as resolved.
Show resolved Hide resolved
averages[..., i] = uxda[..., indices].data.mean(axis=-1)

return averages
Loading