-
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.
Support GEOS Cube-Sphere Grids (#802)
* start geos reader * add geos parser * update user guide * update geos reader * update docs and add docstrings * update testsS * add comment about geos dimensions --------- Co-authored-by: Aaron Zedwick <[email protected]>
- Loading branch information
1 parent
e626119
commit 13462bd
Showing
7 changed files
with
153 additions
and
19 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
Binary file not shown.
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,31 @@ | ||
import uxarray as ux | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
current_path = Path(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
gridfile_geos_cs = current_path / "meshfiles" / "geos-cs" / "c12" / "test-c12.native.nc4" | ||
|
||
|
||
|
||
def test_read_geos_cs_grid(): | ||
"""Tests the conversion of a CS12 GEOS-CS Grid to the UGRID conventions. | ||
A CS12 grid has 6 faces, each with 12x12 faces and 13x13 nodes each. | ||
""" | ||
|
||
uxgrid = ux.open_grid(gridfile_geos_cs) | ||
|
||
n_face = 6 * 12 * 12 | ||
n_node = 6 * 13 * 13 | ||
|
||
assert uxgrid.n_face == n_face | ||
assert uxgrid.n_node == n_node | ||
|
||
|
||
def test_read_geos_cs_uxds(): | ||
"""Tests the creating of a UxDataset from a CS12 GEOS-CS Grid.""" | ||
uxds = ux.open_dataset(gridfile_geos_cs, gridfile_geos_cs) | ||
|
||
assert uxds['T'].shape[-1] == uxds.uxgrid.n_face |
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,59 @@ | ||
import xarray as xr | ||
import numpy as np | ||
|
||
from uxarray.constants import INT_DTYPE | ||
from uxarray.conventions import ugrid | ||
|
||
|
||
def _read_geos_cs(in_ds: xr.Dataset): | ||
"""Reads and encodes a GEOS Cube-Sphere grid into the UGRID conventions. | ||
https://gmao.gsfc.nasa.gov/gmaoftp/ops/GEOSIT_sample/doc/CS_Description_c180_v1.pdf | ||
""" | ||
out_ds = xr.Dataset() | ||
|
||
node_lon = in_ds["corner_lons"].values.ravel() | ||
node_lat = in_ds["corner_lats"].values.ravel() | ||
|
||
out_ds["node_lon"] = xr.DataArray( | ||
data=node_lon, dims=ugrid.NODE_DIM, attrs=ugrid.NODE_LON_ATTRS | ||
) | ||
|
||
out_ds["node_lat"] = xr.DataArray( | ||
data=node_lat, dims=ugrid.NODE_DIM, attrs=ugrid.NODE_LAT_ATTRS | ||
) | ||
|
||
if "lons" in in_ds: | ||
face_lon = in_ds["lons"].values.ravel() | ||
face_lat = in_ds["lats"].values.ravel() | ||
|
||
out_ds["face_lon"] = xr.DataArray( | ||
data=face_lon, dims=ugrid.FACE_DIM, attrs=ugrid.FACE_LON_ATTRS | ||
) | ||
|
||
out_ds["face_lat"] = xr.DataArray( | ||
data=face_lat, dims=ugrid.FACE_DIM, attrs=ugrid.FACE_LAT_ATTRS | ||
) | ||
|
||
nf, nx, ny = in_ds["corner_lons"].shape | ||
|
||
# generate indices for all corner nodes | ||
idx = np.arange(nx * ny * nf, dtype=INT_DTYPE).reshape(nf, nx, ny) | ||
|
||
# calculate indices of corner nodes for each face | ||
tl = idx[:, :-1, :-1].reshape(-1) | ||
tr = idx[:, :-1, 1:].reshape(-1) | ||
bl = idx[:, 1:, :-1].reshape(-1) | ||
br = idx[:, 1:, 1:].reshape(-1) | ||
|
||
# Concatenate corner node indices for all faces | ||
face_node_connectivity = np.column_stack((br, bl, tl, tr)) | ||
|
||
out_ds["face_node_connectivity"] = xr.DataArray( | ||
data=face_node_connectivity, | ||
dims=ugrid.FACE_NODE_CONNECTIVITY_DIMS, | ||
attrs=ugrid.FACE_NODE_CONNECTIVITY_ATTRS, | ||
) | ||
|
||
# GEOS-CS does not return a source_dims_dict | ||
return out_ds, None |
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