Skip to content

Commit

Permalink
initial refactoring for class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc2 committed Jul 25, 2023
1 parent cc72660 commit e630214
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
28 changes: 28 additions & 0 deletions uxarray/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,34 @@ def __from_vert__(self, dataset):
"start_index": 0
})

@classmethod
def from_dataset(cls, dataset, latlon=True, use_dual=False):
if not isinstance(dataset, xr.Dataset):
raise ValueError

# determine grid/mesh specification
mesh_spec = _parse_grid_type(dataset)

if mesh_spec == "Exodus":
grid_ds, var_encoding = _read_exodus(dataset)
elif mesh_spec == "Scrip":
grid_ds, var_encoding = _read_scrip(dataset)
elif mesh_spec == "UGRID":
grid_ds, var_encoding = _read_ugrid(dataset)
elif mesh_spec == "MPAS":
grid_ds, var_encoding = _read_mpas(dataset, use_dual=use_dual)
elif mesh_spec == "Shapefile":
# TODO: Not supported, add appropriate exception
raise ValueError
else:
pass

pass

@classmethod
def from_vertices(cls, vertices, latlon=True):
pass

# load mesh from a file
def __from_ds__(self, dataset):
"""Loads a mesh dataset."""
Expand Down
2 changes: 1 addition & 1 deletion uxarray/io/_exodus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


# Exodus Number is one-based.
def _read_exodus(ext_ds, grid_var_names):
def _read_exodus(ext_ds):
"""Exodus file reader.
Parameters: xarray.Dataset, required
Expand Down
10 changes: 5 additions & 5 deletions uxarray/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ def _parse_grid_type(dataset):
"""
# exodus with coord or coordx
if "coord" in dataset:
mesh_type = "exo"
mesh_type = "Exodus"
elif "coordx" in dataset:
mesh_type = "exo"
mesh_type = "Exodus"
# scrip with grid_center_lon
elif "grid_center_lon" in dataset:
mesh_type = "scrip"
mesh_type = "Scrip"
# ugrid topology
elif _is_ugrid(dataset):
mesh_type = "ugrid"
mesh_type = "UGRID"
elif "verticesOnCell" in dataset:
mesh_type = "mpas"
mesh_type = "MPAS"
else:
raise RuntimeError(f"Could not recognize dataset format.")
return mesh_type
Expand Down

0 comments on commit e630214

Please sign in to comment.