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

DRAFT: Reductions #1075

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2,999 changes: 2,999 additions & 0 deletions docs/user-guide/.ipynb_checkpoints/topological-aggregations-checkpoint.ipynb

Large diffs are not rendered by default.

145 changes: 133 additions & 12 deletions docs/user-guide/topological-aggregations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,7 @@
"source": [
"## Edge Aggregations\n",
"\n",
"The follow aggregations are for edge-centered data. \n",
"\n",
"```{warning}\n",
"Aggregation of edge-centered data is not yet supported in UXarray. \n",
"```\n",
"\n"
"The follow aggregations are for edge-centered data. "
]
},
{
Expand All @@ -402,6 +397,36 @@
"<img src=\"../_static/examples/agg/edge_node.png\" width=\"600\" alt=\"Optional Alt Text\">"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8c462c1c-cf55-4bb5-a78a-5ac28366cc9b",
"metadata": {},
"outputs": [],
"source": [
"uxda_edge_face_agg = uxds[\"random_data_edge\"].topological_mean(destination=\"node\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c809274-1b47-42da-8f21-227cd7206fac",
"metadata": {},
"outputs": [],
"source": [
"(\n",
" uxds.uxgrid.plot(line_color=\"black\")\n",
" * uxds[\"random_data_edge\"]\n",
" .plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"circle\", clabel=None, tools=[\"hover\"]\n",
" )\n",
" .relabel(\"Edge Data\")\n",
" * uxda_node_edge_agg.plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"square\", clabel=None, tools=[\"hover\"]\n",
" ).relabel(\"Edge to Node Mean\")\n",
").opts(title=\"Edge to Node Aggregation (Mean)\", legend_position=\"top_right\")"
]
},
{
"cell_type": "markdown",
"id": "86846522863860f5",
Expand All @@ -419,6 +444,38 @@
"<img src=\"../_static/examples/agg/edge_face.png\" width=\"600\" alt=\"Optional Alt Text\">"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b9769693-62a8-4566-95cc-6a8078358bf5",
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"uxda_edge_face_agg = uxds[\"random_data_edge\"].topological_mean(destination=\"face\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f2bc4883-ea2c-47c6-8305-b5b06224a56e",
"metadata": {},
"outputs": [],
"source": [
"(\n",
" uxds.uxgrid.plot(line_color=\"black\")\n",
" * uxds[\"random_data_edge\"]\n",
" .plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"circle\", clabel=None, tools=[\"hover\"]\n",
" )\n",
" .relabel(\"Edge Data\")\n",
" * uxda_edge_face_agg.plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"square\", clabel=None, tools=[\"hover\"]\n",
" ).relabel(\"Edge to Face Mean\")\n",
").opts(title=\"Edge to Face Aggregation (Mean)\", legend_position=\"top_right\")"
]
},
{
"cell_type": "markdown",
"id": "7dd482e719e7d775",
Expand All @@ -431,11 +488,7 @@
"source": [
"## Face Aggregations\n",
"\n",
"The following aggregations are for face-centered data.\n",
"\n",
"```{warning}\n",
"Aggregation of face-centered data is not yet supported in UXarray. \n",
"```\n"
"The following aggregations are for face-centered data."
]
},
{
Expand All @@ -455,6 +508,36 @@
"<img src=\"../_static/examples/agg/face_node.png\" width=\"600\" alt=\"Optional Alt Text\">"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4fb30cee-69b9-4136-8a65-40cbd0d4f708",
"metadata": {},
"outputs": [],
"source": [
"uxda_face_node_agg = uxds[\"random_data_face\"].topological_mean(destination=\"node\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e68c204f-ae92-4d2a-aada-696239b73f62",
"metadata": {},
"outputs": [],
"source": [
"(\n",
" uxds.uxgrid.plot(line_color=\"black\")\n",
" * uxds[\"random_data_face\"]\n",
" .plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"circle\", clabel=None, tools=[\"hover\"]\n",
" )\n",
" .relabel(\"Face Data\")\n",
" * uxda_face_node_agg.plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"square\", clabel=None, tools=[\"hover\"]\n",
" ).relabel(\"Face to Node Mean\")\n",
").opts(title=\"Face to Node Aggregation (Mean)\", legend_position=\"top_right\")"
]
},
{
"cell_type": "markdown",
"id": "1609e8bef449a334",
Expand All @@ -471,6 +554,44 @@
"\n",
"<img src=\"../_static/examples/agg/face_edge.png\" width=\"600\" alt=\"Optional Alt Text\">"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f1104d1e-97fc-4403-8daa-f2dc33a37900",
"metadata": {},
"outputs": [],
"source": [
"uxda_face_edge_agg = uxds[\"random_data_face\"].topological_mean(destination=\"edge\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ff32897f-e555-474a-978a-723929261b38",
"metadata": {},
"outputs": [],
"source": [
"(\n",
" uxds.uxgrid.plot(line_color=\"black\")\n",
" * uxds[\"random_data_face\"]\n",
" .plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"circle\", clabel=None, tools=[\"hover\"]\n",
" )\n",
" .relabel(\"Face Data\")\n",
" * uxda_face_edge_agg.plot.points(\n",
" cmap=\"inferno\", size=150, marker=\"square\", clabel=None, tools=[\"hover\"]\n",
" ).relabel(\"Face to Edge Mean\")\n",
").opts(title=\"Face to Edge Aggregation (Mean)\", legend_position=\"top_right\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b55ecc0e-2015-4248-b5a6-c5a997faa6d5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -489,7 +610,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
14 changes: 12 additions & 2 deletions test/test_topological_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

current_path = Path(os.path.dirname(os.path.realpath(__file__)))


ds_path = current_path / 'meshfiles' / "mpas" / "QU" / 'oQU480.231010.nc'

AGGS = ["topological_mean",
Expand All @@ -32,11 +31,22 @@ def test_node_to_face_aggs():
assert 'n_face' in grid_reduction.dims



def test_node_to_edge_aggs():
uxds = ux.open_dataset(ds_path, ds_path)

for agg_func in AGGS:
grid_reduction = getattr(uxds['areaTriangle'], agg_func)(destination='edge')

assert 'n_edge' in grid_reduction.dims


def test_edge_to_face_aggs():
grid_path = '/Users/aaronzedwick/uxarray/test/meshfiles/mpas/QU/mesh.QU.1920km.151026.nc'

uxds = ux.open_dataset(grid_path, grid_path)

uxds = uxds['latCell'].subset.nearest_neighbor(k=3, center_coord=[0, 0])

uxda_edge_face_agg = uxds.topological_mean(destination="node")

print(uxda_edge_face_agg)
27 changes: 27 additions & 0 deletions uxarray/conventions/ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,33 @@

N_NODES_PER_FACE_DIMS = ["n_face"]

N_FACES_PER_NODE_ATTRS = {
"cf_role": "n_faces_per_node",
"long name": "Number of faces per node",
}

N_FACES_PER_NODE_DIMS = ["n_node"]

N_FACES_PER_EDGE_ATTRS = {
"cf_role": "n_faces_per_edge",
"long name": "Number of faces per edge",
}

N_FACES_PER_EDGE_DIMS = ["n_edge"]

N_EDGES_PER_FACE_ATTRS = {
"cf_role": "n_edges_per_face",
"long name": "Number of edges per face",
}

N_EDGES_PER_FACE_DIMS = ["n_face"]

N_EDGES_PER_NODE_ATTRS = {
"cf_role": "n_edges_per_node",
"long name": "Number of edges per node",
}

N_EDGES_PER_NODE_DIMS = ["n_node"]

CONNECTIVITY_NAMES = [
"face_node_connectivity",
Expand Down
Loading
Loading