Skip to content

Commit e180869

Browse files
committed
Assert 1D lon and lat arrays are strictly monotonically increasing
1 parent e0b5b9f commit e180869

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

parcels/xgrid.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ def assert_valid_lat_lon(da_lat, da_lon, axes: _XGCM_AXES):
353353
f"Latitude DataArray {da_lat.name!r} with dims {da_lat.dims} is not associated with the Y axis."
354354
)
355355

356+
if not np.all(np.diff(da_lon.values) > 0):
357+
raise ValueError(
358+
f"Longitude DataArray {da_lon.name!r} with dims {da_lon.dims} must be strictly increasing."
359+
)
360+
if not np.all(np.diff(da_lat.values) > 0):
361+
raise ValueError(f"Latitude DataArray {da_lat.name!r} with dims {da_lat.dims} must be strictly increasing.")
362+
356363
if da_lon.ndim == 2:
357364
if da_lon.dims != da_lat.dims:
358365
raise ValueError(
@@ -373,12 +380,14 @@ def _search_1d_array(
373380
"""
374381
Searches for the particle location in a 1D array and returns barycentric coordinate along dimension.
375382
376-
Assumes particle position x is within the bounds of the array, and array is increasing.
383+
Assumptions:
384+
- particle position x is within the bounds of the array
385+
- array is strictly monotonically increasing.
377386
378387
Parameters
379388
----------
380389
arr : np.array
381-
1D array (assumed to be ascending) to search in.
390+
1D array to search in.
382391
x : float
383392
Position in the 1D array to search for.
384393

0 commit comments

Comments
 (0)