Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronzedwick committed Jan 3, 2025
1 parent fb173e5 commit 5f6285d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 12 additions & 10 deletions uxarray/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions uxarray/grid/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5f6285d

Please sign in to comment.