Skip to content

Commit c66286b

Browse files
authored
Merge pull request #953 from UXARRAY/philipc2/mpas-face-area
Parse Face Areas from MPAS Grids
2 parents a626596 + b1949d0 commit c66286b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

test/test_mpas.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ def test_set_attrs(self):
132132
for mpas_attr in expected_attrs:
133133
assert mpas_attr in uxgrid._ds.attrs
134134

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

139-
pass
138+
uxgrid_primal = ux.open_grid(self.mpas_grid_path, use_dual=False)
139+
uxgrid_dual = ux.open_grid(self.mpas_grid_path, use_dual=True)
140+
141+
assert "face_areas" in uxgrid_primal._ds
142+
assert "face_areas" in uxgrid_dual._ds

uxarray/io/_mpas.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def _primal_to_ugrid(in_ds, out_ds):
5959
if "cellsOnCell" in in_ds:
6060
_parse_face_faces(in_ds, out_ds)
6161

62+
if "areaCell" in in_ds:
63+
_parse_face_areas(in_ds, out_ds, mesh_type="primal")
64+
6265
# set global attributes
6366
_parse_global_attrs(in_ds, out_ds)
6467

@@ -121,6 +124,9 @@ def _dual_to_ugrid(in_ds, out_ds):
121124
if "dcEdge" in in_ds:
122125
_parse_edge_face_distances(in_ds, out_ds)
123126

127+
if "areaTriangle" in in_ds:
128+
_parse_face_areas(in_ds, out_ds, mesh_type="dual")
129+
124130
# set global attributes
125131
_parse_global_attrs(in_ds, out_ds)
126132

@@ -489,6 +495,21 @@ def _parse_face_faces(in_ds, out_ds):
489495
)
490496

491497

498+
def _parse_face_areas(in_ds, out_ds, mesh_type):
499+
"""Parses the face area for either a primal or dual grid."""
500+
501+
if mesh_type == "primal":
502+
face_area = in_ds["areaCell"].data
503+
else:
504+
face_area = in_ds["areaTriangle"].data
505+
506+
out_ds["face_areas"] = xr.DataArray(
507+
data=face_area,
508+
dims=descriptors.FACE_AREAS_DIMS,
509+
attrs=descriptors.FACE_AREAS_ATTRS,
510+
)
511+
512+
492513
def _replace_padding(verticesOnCell, nEdgesOnCell):
493514
"""Replaces the padded values in verticesOnCell defined by nEdgesOnCell
494515
with a fill-value.

0 commit comments

Comments
 (0)