Skip to content

Commit

Permalink
Merge pull request #953 from UXARRAY/philipc2/mpas-face-area
Browse files Browse the repository at this point in the history
Parse Face Areas from MPAS Grids
  • Loading branch information
aaronzedwick authored Sep 13, 2024
2 parents a626596 + b1949d0 commit c66286b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions test/test_mpas.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ def test_set_attrs(self):
for mpas_attr in expected_attrs:
assert mpas_attr in uxgrid._ds.attrs

def test_face_mask(self):
primal_uxgrid = ux.open_grid(self.mpas_ocean_mesh, use_dual=False)
dual_uxgrid = ux.open_grid(self.mpas_ocean_mesh, use_dual=True)
def test_face_area(self):
"""Tests the parsing of face areas for MPAS grids."""

pass
uxgrid_primal = ux.open_grid(self.mpas_grid_path, use_dual=False)
uxgrid_dual = ux.open_grid(self.mpas_grid_path, use_dual=True)

assert "face_areas" in uxgrid_primal._ds
assert "face_areas" in uxgrid_dual._ds
21 changes: 21 additions & 0 deletions uxarray/io/_mpas.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def _primal_to_ugrid(in_ds, out_ds):
if "cellsOnCell" in in_ds:
_parse_face_faces(in_ds, out_ds)

if "areaCell" in in_ds:
_parse_face_areas(in_ds, out_ds, mesh_type="primal")

# set global attributes
_parse_global_attrs(in_ds, out_ds)

Expand Down Expand Up @@ -121,6 +124,9 @@ def _dual_to_ugrid(in_ds, out_ds):
if "dcEdge" in in_ds:
_parse_edge_face_distances(in_ds, out_ds)

if "areaTriangle" in in_ds:
_parse_face_areas(in_ds, out_ds, mesh_type="dual")

# set global attributes
_parse_global_attrs(in_ds, out_ds)

Expand Down Expand Up @@ -489,6 +495,21 @@ def _parse_face_faces(in_ds, out_ds):
)


def _parse_face_areas(in_ds, out_ds, mesh_type):
"""Parses the face area for either a primal or dual grid."""

if mesh_type == "primal":
face_area = in_ds["areaCell"].data
else:
face_area = in_ds["areaTriangle"].data

out_ds["face_areas"] = xr.DataArray(
data=face_area,
dims=descriptors.FACE_AREAS_DIMS,
attrs=descriptors.FACE_AREAS_ATTRS,
)


def _replace_padding(verticesOnCell, nEdgesOnCell):
"""Replaces the padded values in verticesOnCell defined by nEdgesOnCell
with a fill-value.
Expand Down

0 comments on commit c66286b

Please sign in to comment.