diff --git a/docs/api.rst b/docs/api.rst index 91030e7d4..acf518a5e 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -68,6 +68,10 @@ UgridDataArray or UgridDataset. UgridDatasetAccessor.assign_edge_coords UgridDatasetAccessor.assign_face_coords UgridDatasetAccessor.set_node_coords + UgridDatasetAccessor.grid + UgridDatasetAccessor.name + UgridDatasetAccessor.names + UgridDatasetAccessor.topology UgridDatasetAccessor.bounds UgridDatasetAccessor.total_bounds UgridDatasetAccessor.crs @@ -84,9 +88,13 @@ UgridDataArray or UgridDataset. UgridDataArrayAccessor UgridDataArrayAccessor.assign_node_coords - UgridDatasetAccessor.assign_edge_coords - UgridDatasetAccessor.assign_face_coords + UgridDataArrayAccessor.assign_edge_coords + UgridDataArrayAccessor.assign_face_coords UgridDataArrayAccessor.set_node_coords + UgridDataArrayAccessor.grids + UgridDataArrayAccessor.name + UgridDataArrayAccessor.names + UgridDataArrayAccessor.topology UgridDataArrayAccessor.bounds UgridDataArrayAccessor.total_bounds UgridDataArrayAccessor.crs diff --git a/docs/changelog.rst b/docs/changelog.rst index bdf50586c..81d77bfe4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -22,6 +22,13 @@ Added The result can be used to define a valid subselection. - :meth:`xugrid.Ugrid2d.from_structured_bounds` can be used to generate a Ugrid2d topology from x and y bounds arrays. +- :attr:`xugrid.UgridDatasetAccessor.name`, + :attr:`xugrid.UgridDatasetAccessor.names`, + :attr:`xugrid.UgridDatasetAccessor.topology`; and + :attr:`xugrid.UgridDataArrayAccessor.name`, + :attr:`xugrid.UgridDataArrayAccessor.names`, + :attr:`xugrid.UgridDataArrayAccessor.topology` have been added to provide + easier access to the names of the UGRID topologies. Fixed ~~~~~ diff --git a/xugrid/core/dataarray_accessor.py b/xugrid/core/dataarray_accessor.py index 6454ea03a..a53489a33 100644 --- a/xugrid/core/dataarray_accessor.py +++ b/xugrid/core/dataarray_accessor.py @@ -26,18 +26,28 @@ def __init__(self, obj: xr.DataArray, grid: UgridType): @property def grids(self) -> List[UgridType]: + """ + The UGRID topology of this DataArry, as a list. Included for + consistency with UgridDataset. + """ return [self.grid] @property def name(self) -> str: + """Name of the UGRID topology of this DataArray.""" return self.grid.name @property def names(self) -> List[str]: + """ + Name of the UGRID topology, as a list. Included for consistency with + UgridDataset. + """ return [self.grid.name] @property def topology(self) -> Dict[str, UgridType]: + """Mapping from name to UGRID topology.""" return {self.name: self.grid} @property diff --git a/xugrid/core/dataset_accessor.py b/xugrid/core/dataset_accessor.py index 5a704b274..0ee208ad4 100644 --- a/xugrid/core/dataset_accessor.py +++ b/xugrid/core/dataset_accessor.py @@ -17,6 +17,10 @@ def __init__(self, obj: xr.Dataset, grids: Sequence[UgridType]): @property def grid(self) -> UgridType: + """ + Returns the single UGRID topology in this dataset. Raises a TypeError if + the dataset contains more than one topology. + """ ngrid = len(self.grids) if ngrid == 1: return self.grids[0] @@ -29,6 +33,10 @@ def grid(self) -> UgridType: @property def name(self) -> str: + """ + Returns name of the single UGRID topology in this dataset. Raises a + TypeError if the dataset contains more than one topology. + """ ngrid = len(self.grids) if ngrid == 1: return self.grid.name @@ -41,10 +49,12 @@ def name(self) -> str: @property def names(self) -> List[str]: + """Names of all the UGRID topologies in the dataset.""" return [grid.name for grid in self.grids] @property def topology(self) -> Dict[str, UgridType]: + """Mapping from names to UGRID topologies.""" return {grid.name: grid for grid in self.grids} @property