Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e496054
boilerplate
philipc2 Jul 2, 2024
23c7a7b
update boilerplate
philipc2 Jul 2, 2024
3094cfc
fix boilerplate
philipc2 Jul 3, 2024
af8b865
Merge branch 'main' into weighted-mean
philipc2 Jul 3, 2024
23a6422
add quad hexagon to tests
philipc2 Jul 5, 2024
bd3248c
Merge branch 'weighted-mean' of https://github.com/UXARRAY/uxarray in…
philipc2 Jul 5, 2024
98c1c90
Merge branch 'main' into weighted-mean
philipc2 Jul 5, 2024
1ecb633
Merge branch 'main' into weighted-mean
philipc2 Jul 5, 2024
ae4a13e
Merge branch 'main' into weighted-mean
philipc2 Jul 8, 2024
e8e01a5
Merge branch 'main' into weighted-mean
philipc2 Jul 15, 2024
5dbaf5d
write tests, work on api design
philipc2 Jul 16, 2024
4c3290b
asv benchmark
philipc2 Jul 17, 2024
7e5ceca
Merge branch 'main' into weighted-mean
philipc2 Jul 17, 2024
6553163
update asv benchmark
philipc2 Jul 17, 2024
659cfe9
Merge branch 'weighted-mean' of https://github.com/UXARRAY/uxarray in…
philipc2 Jul 17, 2024
70bf239
Merge branch 'main' into weighted-mean
philipc2 Jul 26, 2024
0032870
Committing weighted mean modifications from rtam/weighted mean to uxa…
rytam2 Jul 26, 2024
8a2ecb3
Merge branch 'main' into weighted-mean
philipc2 Aug 12, 2024
02dc504
merge main
philipc2 Oct 10, 2024
f9a4d19
some cleanup
philipc2 Oct 10, 2024
efce996
fix tests
philipc2 Oct 10, 2024
87e6543
Merge branch 'main' into weighted-mean
philipc2 Oct 22, 2024
7999c43
Merge branch 'main' into weighted-mean
philipc2 Nov 13, 2024
7722698
Merge branch 'main' into weighted-mean
philipc2 Nov 19, 2024
8c36fa0
add initial dask test cases
philipc2 Nov 19, 2024
a3c87b8
use parametrize
philipc2 Nov 19, 2024
7056451
add boilerplate for example in docstring
philipc2 Nov 19, 2024
944b42b
update docstring
philipc2 Nov 19, 2024
9a1d746
Merge branch 'weighted-mean' of https://github.com/UXARRAY/uxarray in…
rytam2 Nov 22, 2024
48273fb
added examples to weighted mean API, userguide and test case
rytam2 Nov 22, 2024
c16f192
Merge branch 'main' into weighted-mean
philipc2 Dec 3, 2024
a5f0d3c
cleaned userguide output
rytam2 Dec 3, 2024
97cdf92
restarted kernel
rytam2 Dec 3, 2024
70a2b3f
removed duplicate notebook
rytam2 Dec 5, 2024
d7a6d18
run pre-commit
philipc2 Dec 5, 2024
1613a2d
re-run notebook
philipc2 Dec 5, 2024
b5ae01a
Merge branch 'main' into weighted-mean
aaronzedwick Dec 11, 2024
463fe89
Update uxarray/core/dataarray.py
rytam2 Dec 27, 2024
6093487
Update uxarray/core/dataarray.py
rytam2 Dec 27, 2024
3f395cc
merge main
philipc2 Jan 15, 2025
3edf3b6
Merge branch 'weighted-mean' of https://github.com/UXARRAY/uxarray in…
philipc2 Jan 15, 2025
fda2f77
update docstring, api
philipc2 Jan 15, 2025
633ea1b
update toc
philipc2 Jan 15, 2025
7ef3904
update notebook
philipc2 Jan 15, 2025
121a41d
update docstring
philipc2 Jan 15, 2025
fc3ae23
clean and restart notebook
philipc2 Jan 15, 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 5 additions & 7 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ Dual Mesh Construction
Aggregations
------------


Topological
~~~~~~~~~~~

Expand All @@ -413,16 +414,13 @@ on each face.
UxDataArray.topological_all
UxDataArray.topological_any



Intersections
~~~~~~~~~~~~~

Weighted
~~~~~~~~
.. autosummary::
:toctree: generated/

grid.intersections.gca_gca_intersection
grid.intersections.gca_const_lat_intersection
UxDataArray.weighted_mean



Spherical Geometry
Expand Down
208 changes: 208 additions & 0 deletions docs/user-guide/weighted_mean.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "23f93b0f-62ac-4efd-975c-368477c9ebbe",
"metadata": {},
"source": [
"# Weighted Mean\n",
"\n",
"UXarray supports computing weighted means based on geometric properties such as face areas or edge lengths. In this section of the user guide, we explain how to calculate variable means using unstructured grid geometries as weights. The examples below demonstrate the application of weighted means using grid face areas and grid edge lengths as weights.\n"
]
},
{
"cell_type": "code",
"id": "ed637e46-672c-45ba-a5f1-ed3c3248c8a1",
"metadata": {},
"source": [
"import uxarray as ux\n",
"import xarray as xr\n",
"import cartopy.crs as ccrs\n",
"\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"id": "8518335d-2f75-4699-bc3d-862ab25830d1",
"metadata": {},
"source": [
"## Data\n",
"\n",
"Data used in this section is a 3-random-variable dataset on a quad hexagon mesh mapped to the edges and faces."
]
},
{
"cell_type": "code",
"id": "a2f58f07d7881d4f",
"metadata": {},
"source": [
"grid_path = \"../../test/meshfiles/ugrid/quad-hexagon/grid.nc\"\n",
"quad_hex_data_path_edge_centered = (\n",
" \"../../test/meshfiles/ugrid/quad-hexagon/random-edge-data.nc\"\n",
")\n",
"quad_hex_data_path_face_centered = (\n",
" \"../../test/meshfiles/ugrid/quad-hexagon/random-face-data.nc\"\n",
")\n",
"\n",
"uxds_face = ux.open_mfdataset(grid_path, quad_hex_data_path_face_centered)\n",
"uxds_edge = ux.open_mfdataset(grid_path, quad_hex_data_path_edge_centered)"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"id": "6fac99462efcccdc",
"metadata": {},
"source": [
"(\n",
" uxds_face.uxgrid.plot(line_color=\"black\")\n",
" * uxds_edge[\"random_data_edge\"]\n",
" .plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"square\", clabel=None, tools=[\"hover\"]\n",
" )\n",
" .relabel(\"Edge Data\")\n",
" * uxds_face[\"random_data_face\"]\n",
" .plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"triangle\", clabel=None, tools=[\"hover\"]\n",
" )\n",
" .relabel(\"Face Data\")\n",
").opts(legend_position=\"top_right\")"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"id": "bb77e5067497a0f5",
"metadata": {},
"source": [
"## Weighted Mean based on Face Areas\n",
"\n",
"Here we first look at the data values on each face and the faces' respective areas. "
]
},
{
"cell_type": "code",
"id": "c87fb018ca75ba5e",
"metadata": {},
"source": [
"uxds_face[\"random_data_face\"].values"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"id": "def2b952ba7f1740",
"metadata": {},
"source": "We can simply call `UxDataArray.weighted_mean()` on the UXDataArray to compute the weighted mean. The differences between the weighted mean and the regular mean is small since the area differences across the faces are small. "
},
{
"cell_type": "code",
"id": "bd76b23993d9967f",
"metadata": {},
"source": [
"result = uxds_face[\"random_data_face\"].weighted_mean()\n",
"result.values"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"id": "a92f056d6b2a567b",
"metadata": {},
"source": [
"unweighted_result = uxds_face[\"random_data_face\"].mean()\n",
"unweighted_result.values"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"id": "e8ddb288f83486b8",
"metadata": {},
"source": [
"## Weighted Mean Based on Edge Length\n",
"\n",
"Here we show the similar steps but for edge-centered data and the edge lengths. "
]
},
{
"cell_type": "code",
"id": "1b01581da7ebacc",
"metadata": {},
"source": [
"uxds_edge[\"random_data_edge\"].values"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"id": "a50c11e691337cff",
"metadata": {},
"source": [
"uxds_edge.uxgrid.edge_node_distances.data"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"id": "647630d11f001fcf",
"metadata": {},
"source": "The differences between weighted and unweighted mean is more drastic (~0.1 value difference) since the edge lengths have a larger variance. "
},
{
"cell_type": "code",
"id": "6bace8386234b942",
"metadata": {},
"source": [
"result = uxds_edge[\"random_data_edge\"].weighted_mean()\n",
"result.values"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"id": "d81bc60c195be6ec",
"metadata": {},
"source": [
"unweighted_result = uxds_edge[\"random_data_edge\"].mean()\n",
"unweighted_result.values"
],
"outputs": [],
"execution_count": null
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 4 additions & 0 deletions docs/userguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ These user guides provide detailed explanations of the core functionality in UXa
`Topological Aggregations <user-guide/topological-aggregations.ipynb>`_
Aggregate data across grid dimensions

`Weighted Mean <user-guide/weighted_mean.ipynb>`_
Compute the weighted average

`Calculus Operators <user-guide/calculus.ipynb>`_
Apply calculus operators (gradient, integral) on unstructured grid data

Expand Down Expand Up @@ -100,6 +103,7 @@ These user guides provide additional details about specific features in UXarray.
user-guide/cross-sections.ipynb
user-guide/remapping.ipynb
user-guide/topological-aggregations.ipynb
user-guide/weighted_mean.ipynb
user-guide/calculus.ipynb
user-guide/tree_structures.ipynb
user-guide/area_calc.ipynb
Expand Down
Loading
Loading