Skip to content

Commit 02917cf

Browse files
authored
Merge pull request #146 from csiro-coasts/feature/select-indexes
Add `Convention.select_indexes()` method
2 parents 16266c3 + b363826 commit 02917cf

File tree

26 files changed

+612
-285
lines changed

26 files changed

+612
-285
lines changed

docs/api/conventions/ugrid.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ Topology
3636
Masking
3737
=======
3838

39-
.. autofunction:: mask_from_face_indices
39+
.. autofunction:: mask_from_face_indexes
4040
.. autofunction:: buffer_faces

docs/developing/conventions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ and returns a value indicating whether this convention implementation can unders
6969
:pyobject: Grass.check_dataset
7070

7171
:meth:`.DimensionConvention.unpack_index` and :meth:`.DimensionConvention.pack_index`
72-
transform between native index types and a grid kind and indices.
72+
transform between native index types and a grid kind and indexes.
7373
The native representation must be representable as JSON for GeoJSON export support.
74-
The simplest representation is a tuple of (grid_kind, indices):
74+
The simplest representation is a tuple of (grid_kind, indexes):
7575

7676
.. literalinclude:: ./grass.py
7777
:pyobject: Grass.unpack_index

docs/developing/grass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def check_dataset(cls, dataset: xarray.Dataset) -> int | None:
4141
def unpack_index(self, index: GrassIndex) -> tuple[GrassGridKind, Sequence[int]]:
4242
return index[0], list(index[1])
4343

44-
def pack_index(self, grid_kind: GrassGridKind, indices: Sequence[int]) -> GrassIndex:
45-
return (grid_kind, list(indices))
44+
def pack_index(self, grid_kind: GrassGridKind, indexes: Sequence[int]) -> GrassIndex:
45+
return (grid_kind, list(indexes))
4646

4747
@cached_property
4848
def grid_dimensions(self) -> dict[GrassGridKind, Sequence[Hashable]]:

docs/releases/development.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@ Next release (in development)
3535
(:pr:`142`).
3636
* Add :attr:`.Convention.depth_coordinates` and :meth:`.Convention.get_depth_coordinate_for_data_array()`. Deprecate functions :meth:`.Convention.get_depth_name()`, :meth:`.Convention.get_all_depth_names()`, and :meth:`Convention.get_time_name()`. Remove deprecated functions ``Convention.get_depths()`` and ``Convention.get_times()`` (:pr:`143`).
3737
* Swap to using `pyproject.toml` for all project metadata (:pr:`145`).
38+
* Add new methods
39+
:meth:`.Convention.selector_for_indexes()`,
40+
:meth:`.Convention.select_indexes()`, and
41+
:meth:`.Convention.select_points()`.
42+
These allow for more efficient extraction of multiple points at the same time.
43+
The return type of :meth:`.Convention.selector_for_index()` has been changed
44+
from a `dict` to an :class:`xarray.Dataset`,
45+
but this new value is also designed to be passed directly to :meth:`Dataset.isel() <xarray.Dataset.isel>`.
46+
:meth:`.Convention.select_index()` and :meth:`.Convention.select_indexes()`
47+
have a new `drop_geometry` flag which defaults to True.
48+
Previously these methods would act as if `drop_geometry` was False,
49+
but this led to convention-dependent results as to which geometry variables were returned.
50+
The fragmented geometry variables from different conventions often did not contain enough data to be useful.
51+
By dropping geometry the results are more consistent across all conventions
52+
and do not contain potentially fragmented geometry information.
53+
(:issue:`106`, :pr:`146`).

src/emsarray/cli/commands/extract_points.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def handle(self, options: argparse.Namespace) -> None:
7373
point_dimension=options.point_dimension,
7474
missing_points=options.missing_points)
7575
except point_extraction.NonIntersectingPoints as err:
76-
rows = dataframe.iloc[err.indices]
76+
rows = dataframe.iloc[err.indexes]
7777
raise CommandException(
7878
f"Error extracting points: the points in the following rows "
7979
f"did not intersect the dataset geometry:\n"

src/emsarray/compat/shapely.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ def query(
4949
geom: BaseGeometry,
5050
) -> numpy.ndarray:
5151
if shapely_version >= v2:
52-
indices = self.index.query(geom)
52+
indexes = self.index.query(geom)
5353
else:
54-
indices = self.index._query(geom)
55-
return cast(numpy.ndarray, self.items.take(indices))
54+
indexes = self.index._query(geom)
55+
return cast(numpy.ndarray, self.items.take(indexes))
5656

5757
def nearest(
5858
self,
5959
geom: BaseGeometry,
6060
) -> numpy.ndarray:
6161
if shapely_version >= v2:
62-
indices = self.index.nearest(geom)
62+
indexes = self.index.nearest(geom)
6363
else:
64-
indices = self.index._nearest(geom)
65-
return cast(numpy.ndarray, self.items.take(indices))
64+
indexes = self.index._nearest(geom)
65+
return cast(numpy.ndarray, self.items.take(indexes))

0 commit comments

Comments
 (0)