Skip to content

Commit

Permalink
Docstring, changelog, api
Browse files Browse the repository at this point in the history
  • Loading branch information
Huite committed Aug 7, 2023
1 parent d9c0545 commit c972df3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~
Expand Down
10 changes: 10 additions & 0 deletions xugrid/core/dataarray_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions xugrid/core/dataset_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c972df3

Please sign in to comment.