Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/parcels/_core/index_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from parcels._core.xgrid import XGrid


GRID_SEARCH_ERROR = -3
LEFT_OUT_OF_BOUNDS = -2
RIGHT_OUT_OF_BOUNDS = -1
GRID_SEARCH_ERROR = np.iinfo(np.int32).max - 3
LEFT_OUT_OF_BOUNDS = np.iinfo(np.int32).max - 2
RIGHT_OUT_OF_BOUNDS = np.iinfo(np.int32).max - 1


def _search_1d_array(
Expand Down
16 changes: 16 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from parcels import Field, UxGrid, VectorField, XGrid
from parcels._core.fieldset import FieldSet
from parcels._datasets.structured.generated import simple_UV_dataset
from parcels._datasets.structured.generic import T as T_structured
from parcels._datasets.structured.generic import datasets as datasets_structured
from parcels._datasets.unstructured.generic import datasets as datasets_unstructured
Expand Down Expand Up @@ -270,6 +271,21 @@ def test_field_constant_in_time():
assert np.isclose(P1, P2)


def test_field_eval_out_of_bounds():
"""Test that Field.eval returns IndexError when queried outside the grid boundaries."""
ds = simple_UV_dataset(mesh="flat")
fieldset = FieldSet.from_sgrid_conventions(ds, mesh="flat")

with pytest.raises(IndexError, match=".* is out of bounds.*"):
fieldset.U.eval(0.0, 0.0, 0.0, 5e6)

with pytest.raises(IndexError, match=".* is out of bounds.*"):
fieldset.U.eval(0.0, 0.0, 5e6, 0.0)

with pytest.raises(IndexError, match=".* is out of bounds.*"):
fieldset.U.eval(0.0, 5e6, 0.0, 0.0)


def test_field_unstructured_grid_creation(): ...


Expand Down
Loading