Skip to content

Commit b363826

Browse files
committed
fixup! Add Convention.select_indexes() and related functions
1 parent 081c313 commit b363826

File tree

1 file changed

+68
-8
lines changed

1 file changed

+68
-8
lines changed

src/emsarray/conventions/_base.py

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,15 +1483,25 @@ def selector_for_index(self, index: Index) -> xarray.Dataset:
14831483
14841484
Returns
14851485
-------
1486-
selector
1487-
A dict suitable for passing to :meth:`xarray.Dataset.isel`
1486+
selector : xarray.Dataset
1487+
A selector suitable for passing to :meth:`xarray.Dataset.isel`
14881488
that will select values at this index.
14891489
14901490
See Also
14911491
--------
14921492
:meth:`.select_index`
14931493
:meth:`.select_point`
1494+
:meth:`.selector_for_indexes`
14941495
:ref:`indexing`
1496+
1497+
Notes
1498+
-----
1499+
1500+
The returned selector is an :class:`xarray.Dataset`,
1501+
but the contents of the dataset are dependent on the specific convention
1502+
and may change between versions of emsarray.
1503+
The selector should be treated as an opaque value
1504+
that is only useful when passed to :meth:`xarray.Dataset.isel()`.
14951505
"""
14961506
index_dimension = utils.find_unused_dimension(self.dataset, 'index')
14971507
dataset = self.selector_for_indexes([index], index_dimension=index_dimension)
@@ -1505,6 +1515,37 @@ def selector_for_indexes(
15051515
*,
15061516
index_dimension: Hashable | None = None,
15071517
) -> xarray.Dataset:
1518+
"""
1519+
Convert a list of convention native indexes into a selector
1520+
that can be passed to :meth:`Dataset.isel <xarray.Dataset.isel>`.
1521+
1522+
Parameters
1523+
----------
1524+
indexes : list of :data:`Index`
1525+
A list of convention native indexes
1526+
1527+
Returns
1528+
-------
1529+
selector : xarray.Dataset
1530+
A selector suitable for passing to :meth:`xarray.Dataset.isel`
1531+
that will select values at this index.
1532+
1533+
See Also
1534+
--------
1535+
:meth:`.select_indexes`
1536+
:meth:`.select_points`
1537+
:meth:`.selector_for_index`
1538+
:ref:`indexing`
1539+
1540+
Notes
1541+
-----
1542+
1543+
The returned selector is an :class:`xarray.Dataset`,
1544+
but the contents of the dataset are dependent on the specific convention
1545+
and may change between versions of emsarray.
1546+
The selector should be treated as an opaque value
1547+
that is only useful when passed to :meth:`xarray.Dataset.isel()`.
1548+
"""
15081549
pass
15091550

15101551
def select_index(
@@ -1527,7 +1568,6 @@ def select_index(
15271568
----------
15281569
index : :data:`Index`
15291570
The index to select.
1530-
The index must be for the default grid kind for this dataset.
15311571
drop_geometry : bool, default True
15321572
Whether to drop geometry variables from the returned point dataset.
15331573
If the geometry data is kept
@@ -1540,6 +1580,11 @@ def select_index(
15401580
:class:`xarray.Dataset`
15411581
A new dataset that is subset to the one index.
15421582
1583+
See also
1584+
--------
1585+
:meth:`.select_point`
1586+
:meth:`.select_indexes`
1587+
15431588
Notes
15441589
-----
15451590
@@ -1566,15 +1611,15 @@ def select_indexes(
15661611
15671612
An index is associated with a grid kind.
15681613
The returned dataset will only contain variables that were defined on this grid,
1569-
with the single indexed point selected.
1614+
with the indexed points selected.
15701615
For example, if the index of a face is passed in,
15711616
the returned dataset will not contain any variables defined on an edge.
15721617
15731618
Parameters
15741619
----------
1575-
index : :data:`Index`
1576-
The index to select.
1577-
The index must be for the default grid kind for this dataset.
1620+
indexes : list of :data:`Index`
1621+
The indexes to select.
1622+
The indexes must all be for the same grid kind.
15781623
index_dimension : str, optional
15791624
The name of the new dimension added for each index to select.
15801625
Defaults to the :func:`first unused dimension <.utils.find_unused_dimension>` with prefix `index`.
@@ -1588,7 +1633,12 @@ def select_indexes(
15881633
Returns
15891634
-------
15901635
:class:`xarray.Dataset`
1591-
A new dataset that is subset to the one index.
1636+
A new dataset that is subset to the indexes.
1637+
1638+
See also
1639+
--------
1640+
:meth:`.select_points`
1641+
:meth:`.select_index`
15921642
15931643
Notes
15941644
-----
@@ -1632,6 +1682,11 @@ def select_point(self, point: Point) -> xarray.Dataset:
16321682
-------
16331683
xarray.Dataset
16341684
A dataset of values at the point
1685+
1686+
See also
1687+
--------
1688+
:meth:`.select_index`
1689+
:meth:`.select_points`
16351690
"""
16361691
index = self.get_index_for_point(point)
16371692
if index is None:
@@ -1664,6 +1719,11 @@ def select_points(
16641719
xarray.Dataset
16651720
A dataset with values extracted from the points.
16661721
No variables not defined on the default grid and no geometry variables will be present.
1722+
1723+
See also
1724+
--------
1725+
:meth:`.select_indexes`
1726+
:meth:`.select_point`
16671727
"""
16681728
if point_dimension is None:
16691729
point_dimension = utils.find_unused_dimension(self.dataset, 'point')

0 commit comments

Comments
 (0)