From 5f6285d4322581e004058e8b62528cb2d266d597 Mon Sep 17 00:00:00 2001 From: Aaron Zedwick Date: Fri, 3 Jan 2025 09:30:07 -0600 Subject: [PATCH] Addressed review comments --- uxarray/grid/grid.py | 22 ++++++++++++---------- uxarray/grid/slice.py | 4 +--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/uxarray/grid/grid.py b/uxarray/grid/grid.py index 7bedb343e..8e2a64775 100644 --- a/uxarray/grid/grid.py +++ b/uxarray/grid/grid.py @@ -160,6 +160,7 @@ def __init__( grid_ds: xr.Dataset, source_grid_spec: Optional[str] = None, source_dims_dict: Optional[dict] = {}, + is_subset=False, ): # check if inputted dataset is a minimum representable 2D UGRID unstructured grid if not _validate_minimum_ugrid(grid_ds): @@ -191,6 +192,7 @@ def __init__( # initialize attributes self._antimeridian_face_indices = None self._ds.assign_attrs({"source_grid_spec": self.source_grid_spec}) + self.is_subset = is_subset # cached parameters for GeoDataFrame conversions self._gdf_cached_parameters = { @@ -242,7 +244,9 @@ def __init__( cross_section = UncachedAccessor(GridCrossSectionAccessor) @classmethod - def from_dataset(cls, dataset, use_dual: Optional[bool] = False, **kwargs): + def from_dataset( + cls, dataset, use_dual: Optional[bool] = False, is_subset=False, **kwargs + ): """Constructs a ``Grid`` object from a dataset. Parameters @@ -301,7 +305,7 @@ def from_dataset(cls, dataset, use_dual: Optional[bool] = False, **kwargs): except TypeError: raise ValueError("Unsupported Grid Format") - return cls(grid_ds, source_grid_spec, source_dims_dict) + return cls(grid_ds, source_grid_spec, source_dims_dict, is_subset=is_subset) @classmethod def from_file( @@ -1508,15 +1512,13 @@ def global_sphere_coverage(self): @property def inverse_face_indices(self): - if self._is_subset: + """Indices for a subset that map each face in the subset back to the original grid""" + if self.is_subset: return self._ds["inverse_face_indices"] - - @property - def _is_subset(self): - """Boolean indicator for whether the Grid is from a subset or not.""" - if "_is_subset" not in self._ds: - self._ds["_is_subset"] = False - return self._ds["_is_subset"] + else: + raise Exception( + "Grid is not a subset, therefore no inverse face indices exist" + ) def chunk(self, n_node="auto", n_edge="auto", n_face="auto"): """Converts all arrays to dask arrays with given chunks across grid diff --git a/uxarray/grid/slice.py b/uxarray/grid/slice.py index 430389ba8..c748ce588 100644 --- a/uxarray/grid/slice.py +++ b/uxarray/grid/slice.py @@ -134,6 +134,4 @@ def _slice_face_indices(grid, indices, inclusive=True, inverse_indices=False): if inverse_indices: ds["inverse_face_indices"] = indices - ds["_is_subset"] = True - - return Grid.from_dataset(ds, source_grid_spec=grid.source_grid_spec) + return Grid.from_dataset(ds, source_grid_spec=grid.source_grid_spec, is_subset=True)