diff --git a/uxarray/grid/grid.py b/uxarray/grid/grid.py index a09522cc9..179138831 100644 --- a/uxarray/grid/grid.py +++ b/uxarray/grid/grid.py @@ -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.""" diff --git a/uxarray/io/_exodus.py b/uxarray/io/_exodus.py index 5b83e4dd6..3e07ccc1c 100644 --- a/uxarray/io/_exodus.py +++ b/uxarray/io/_exodus.py @@ -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 diff --git a/uxarray/io/utils.py b/uxarray/io/utils.py index ce5317486..cfd05173f 100644 --- a/uxarray/io/utils.py +++ b/uxarray/io/utils.py @@ -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