-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UGRID Conformance, Grid Construction from Minimal Grid Variables (#628)
* initial work * work on convetnions * topology reader * work on topo, getitem for grid * work on conventions * run pre-commit * fix from face vertices * add sizes, dims, coordinates, and connectivity properties * reader * work on ugrid reader * use ugrid conventions module in esmf reader * update scrip reader * add test for from topo * update topology reader * update mpas reader * update exodus reader * update ugrid reader * fix tests after refactor * fix tests * update connectivity.py with refactor * update connectivity.py with refactor * investigate failing test * investigate failing test * investigate failing test * fix failing connectivity tests * testing * update grid.py * update user api * update face areas and add grid.to_netcdf * update ValueError * update internall api * add docstring to __getitem__ * add edge dimension to grid topology * docstring for Grid.to_netcdf * remove Grid.to_netcdf in favor of Grid.to_xarray * update repr * fix failing test * update docstrings * update repr * coments * fix failing test * remove leftover method in api * specify Cartesiain in xyz coordinates * add cartesiain coordinate names * update docstrings * update docstrings * update conventions --------- Co-authored-by: Hongyu Chen <hyvchen@ucdavis.edu> Co-authored-by: Orhan Eroglu <32553057+erogluorhan@users.noreply.github.com>
- Loading branch information
1 parent
556cdc7
commit 545a18d
Showing
18 changed files
with
1,073 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import uxarray as ux | ||
|
||
from uxarray.constants import INT_FILL_VALUE | ||
import numpy.testing as nt | ||
import os | ||
|
||
import pytest | ||
|
||
from pathlib import Path | ||
|
||
current_path = Path(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
GRID_PATHS = [ | ||
current_path / 'meshfiles' / "mpas" / "QU" / 'oQU480.231010.nc', | ||
current_path / "meshfiles" / "ugrid" / "geoflow-small" / "grid.nc", | ||
current_path / "meshfiles" / "ugrid" / "outCSne30" / "outCSne30.ug" | ||
] | ||
|
||
|
||
|
||
|
||
def test_minimal_class_method(): | ||
"""Tests the minimal required variables for constructing a grid using the | ||
from topology class method.""" | ||
|
||
for grid_path in GRID_PATHS: | ||
uxgrid = ux.open_grid(grid_path) | ||
|
||
uxgrid_ft = ux.Grid.from_topology(node_lon=uxgrid.node_lon.values, | ||
node_lat=uxgrid.node_lat.values, | ||
face_node_connectivity=uxgrid.face_node_connectivity.values, | ||
fill_value=INT_FILL_VALUE, | ||
start_index=0) | ||
|
||
nt.assert_array_equal(uxgrid.node_lon.values, uxgrid_ft.node_lon.values) | ||
nt.assert_array_equal(uxgrid.node_lat.values, uxgrid_ft.node_lat.values) | ||
nt.assert_array_equal(uxgrid.face_node_connectivity.values, uxgrid_ft.face_node_connectivity.values) | ||
|
||
|
||
def test_minimal_api(): | ||
"""Tests the minimal required variables for constructing a grid using the | ||
``ux.open_dataset`` method.""" | ||
|
||
for grid_path in GRID_PATHS: | ||
uxgrid = ux.open_grid(grid_path) | ||
|
||
uxgrid_ft = ux.Grid.from_topology(node_lon=uxgrid.node_lon.values, | ||
node_lat=uxgrid.node_lat.values, | ||
face_node_connectivity=uxgrid.face_node_connectivity.values, | ||
fill_value=INT_FILL_VALUE, | ||
start_index=0) | ||
|
||
grid_topology = {'node_lon': uxgrid.node_lon.values, | ||
'node_lat': uxgrid.node_lat.values, | ||
'face_node_connectivity': uxgrid.face_node_connectivity.values, | ||
'fill_value': INT_FILL_VALUE, | ||
'start_index': 0} | ||
|
||
uxgrid_ft = ux.open_grid(grid_topology) | ||
|
||
nt.assert_array_equal(uxgrid.node_lon.values, uxgrid_ft.node_lon.values) | ||
nt.assert_array_equal(uxgrid.node_lat.values, uxgrid_ft.node_lat.values) | ||
nt.assert_array_equal(uxgrid.face_node_connectivity.values, uxgrid_ft.face_node_connectivity.values) | ||
|
||
|
||
def test_dataset(): | ||
uxds = ux.open_dataset(GRID_PATHS[0], GRID_PATHS[0]) | ||
|
||
grid_topology = {'node_lon': uxds.uxgrid.node_lon.values, | ||
'node_lat': uxds.uxgrid.node_lat.values, | ||
'face_node_connectivity': uxds.uxgrid.face_node_connectivity.values, | ||
'fill_value': INT_FILL_VALUE, | ||
'start_index': 0, | ||
"dims_dict" : {"nVertices": "n_node"}} | ||
|
||
|
||
uxds_ft = ux.open_grid(grid_topology, GRID_PATHS[1]) | ||
|
||
uxgrid = uxds.uxgrid | ||
uxgrid_ft = uxds_ft | ||
|
||
|
||
nt.assert_array_equal(uxgrid.node_lon.values, uxgrid_ft.node_lon.values) | ||
nt.assert_array_equal(uxgrid.node_lat.values, uxgrid_ft.node_lat.values) | ||
nt.assert_array_equal(uxgrid.face_node_connectivity.values, uxgrid_ft.face_node_connectivity.values) | ||
|
||
assert uxds_ft.dims == {'n_face', 'n_node', 'n_max_face_nodes'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
DESCRIPTOR_NAMES = ["face_areas", "edge_face_distances", "edge_node_distances"] | ||
|
||
|
||
FACE_AREAS_DIMS = ["n_face"] | ||
|
||
FACE_AREAS_ATTRS = {"cf_role": "face_areas"} | ||
|
||
EDGE_FACE_DISTANCES_DIMS = ["n_edge"] | ||
EDGE_FACE_DISTANCES_ATTRS = { | ||
"cf_role": "edge_face_distances", | ||
"long_name": "Distances between the face centers that " "saddle each edge", | ||
} | ||
|
||
EDGE_NODE_DISTANCES_DIMS = ["n_edge"] | ||
EDGE_NODE_DISTANCES_ATTRS = { | ||
"cf_role": "edge_node_distances", | ||
"long_name": "Distances between the nodes that make up " "each edge.", | ||
} |
Oops, something went wrong.