Skip to content

Commit b7eaf60

Browse files
Renaming field_sampling_error to grid_searching_error
1 parent ba14fa5 commit b7eaf60

3 files changed

Lines changed: 53 additions & 18 deletions

File tree

parcels/_index_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
FieldOutOfBoundSurfaceError,
1616
_raise_field_out_of_bound_error,
1717
_raise_field_out_of_bound_surface_error,
18-
_raise_field_sampling_error,
18+
_raise_grid_searching_error,
1919
_raise_time_extrapolation_error,
2020
)
2121

@@ -243,7 +243,7 @@ def _search_indices_rectilinear(
243243
zi, zeta = -1, 0
244244

245245
if not ((0 <= xsi <= 1) and (0 <= eta <= 1) and (0 <= zeta <= 1)):
246-
_raise_field_sampling_error(z, y, x)
246+
_raise_grid_searching_error(z, y, x)
247247

248248
_ei = field.ravel_index(zi, yi, xi)
249249

@@ -314,7 +314,7 @@ def _search_indices_curvilinear_2d(
314314
eta = np.where(eta < 0.0, 0.0, np.where(eta > 1.0, 1.0, eta))
315315

316316
if np.any((xsi < 0) | (xsi > 1) | (eta < 0) | (eta > 1)):
317-
_raise_field_sampling_error(y, x)
317+
_raise_grid_searching_error(y, x)
318318
return (yi, eta, xi, xsi)
319319

320320

@@ -400,7 +400,7 @@ def _search_indices_curvilinear(field, time, z, y, x, ti, particle=None, search2
400400
zeta = 0
401401

402402
if not ((0 <= xsi <= 1) and (0 <= eta <= 1) and (0 <= zeta <= 1)):
403-
_raise_field_sampling_error(z, y, x)
403+
_raise_grid_searching_error(z, y, x)
404404

405405
if particle:
406406
particle.ei[field.igrid] = field.ravel_index(zi, yi, xi)

parcels/kernel.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
from parcels.basegrid import GridType
1616
from parcels.tools.statuscodes import (
1717
StatusCode,
18+
_raise_field_interpolation_error,
1819
_raise_field_out_of_bound_error,
1920
_raise_field_out_of_bound_surface_error,
20-
_raise_field_sampling_error,
21+
_raise_general_error,
22+
_raise_grid_searching_error,
2123
_raise_time_extrapolation_error,
2224
)
2325
from parcels.tools.warnings import KernelWarning
@@ -274,7 +276,9 @@ def execute(self, pset, endtime, dt):
274276
StatusCode.ErrorTimeExtrapolation: _raise_time_extrapolation_error,
275277
StatusCode.ErrorOutOfBounds: _raise_field_out_of_bound_error,
276278
StatusCode.ErrorThroughSurface: _raise_field_out_of_bound_surface_error,
277-
StatusCode.Error: _raise_field_sampling_error,
279+
StatusCode.ErrorInterpolation: _raise_field_interpolation_error,
280+
StatusCode.ErrorGridSearching: _raise_grid_searching_error,
281+
StatusCode.Error: _raise_general_error,
278282
}
279283

280284
for error_code, error_func in errors_to_throw.items():

parcels/tools/statuscodes.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"KernelError",
88
"StatusCode",
99
"TimeExtrapolationError",
10+
"_raise_field_interpolation_error",
1011
"_raise_field_out_of_bound_error",
1112
"_raise_field_out_of_bound_surface_error",
12-
"_raise_field_sampling_error",
13+
"_raise_general_error",
14+
"_raise_grid_searching_error",
1315
"_raise_time_extrapolation_error",
1416
]
1517

@@ -25,37 +27,38 @@ class StatusCode:
2527
StopAllExecution = 41
2628
Error = 50
2729
ErrorInterpolation = 51
30+
ErrorGridSearching = 52
2831
ErrorOutOfBounds = 60
2932
ErrorThroughSurface = 61
3033
ErrorTimeExtrapolation = 70
3134

3235

33-
class FieldSamplingError(RuntimeError):
34-
"""Utility error class to propagate erroneous field sampling."""
36+
class FieldInterpolationError(RuntimeError):
37+
"""Utility error class to propagate NaN field interpolation."""
3538

3639
pass
3740

3841

42+
def _raise_field_interpolation_error(z, y, x):
43+
raise FieldInterpolationError(f"Field interpolation returned NaN at (depth={z}, lat={y}, lon={x})")
44+
45+
3946
class FieldOutOfBoundError(RuntimeError):
4047
"""Utility error class to propagate out-of-bound field sampling."""
4148

4249
pass
4350

4451

52+
def _raise_field_out_of_bound_error(z, y, x):
53+
raise FieldOutOfBoundError(f"Field sampled out-of-bound, at (depth={z}, lat={y}, lon={x})")
54+
55+
4556
class FieldOutOfBoundSurfaceError(RuntimeError):
4657
"""Utility error class to propagate out-of-bound field sampling at the surface."""
4758

4859
pass
4960

5061

51-
def _raise_field_sampling_error(z, y, x):
52-
raise FieldSamplingError(f"Field sampled at (depth={z}, lat={y}, lon={x})")
53-
54-
55-
def _raise_field_out_of_bound_error(z, y, x):
56-
raise FieldOutOfBoundError(f"Field sampled out-of-bound, at (depth={z}, lat={y}, lon={x})")
57-
58-
5962
def _raise_field_out_of_bound_surface_error(z: float | None, y: float | None, x: float | None) -> None:
6063
def format_out(val):
6164
return "unknown" if val is None else val
@@ -65,6 +68,32 @@ def format_out(val):
6568
)
6669

6770

71+
class FieldSamplingError(RuntimeError):
72+
"""Utility error class to propagate field sampling errors."""
73+
74+
pass
75+
76+
77+
class GridSearchingError(RuntimeError):
78+
"""Utility error class to propagate grid searching errors."""
79+
80+
pass
81+
82+
83+
def _raise_grid_searching_error(z, y, x):
84+
raise GridSearchingError(f"Grid searching failed at (depth={z}, lat={y}, lon={x})")
85+
86+
87+
class GeneralError(RuntimeError):
88+
"""Utility error class to propagate general errors."""
89+
90+
pass
91+
92+
93+
def _raise_general_error(z, y, x):
94+
raise GeneralError(f"General error occurred at (depth={z}, lat={y}, lon={x})")
95+
96+
6897
class TimeExtrapolationError(RuntimeError):
6998
"""Utility error class to propagate erroneous time extrapolation sampling."""
7099

@@ -91,9 +120,11 @@ def __init__(self, particle, fieldset=None, msg=None):
91120

92121

93122
AllParcelsErrorCodes = {
94-
FieldSamplingError: StatusCode.Error,
123+
FieldInterpolationError: StatusCode.ErrorInterpolation,
95124
FieldOutOfBoundError: StatusCode.ErrorOutOfBounds,
96125
FieldOutOfBoundSurfaceError: StatusCode.ErrorThroughSurface,
126+
GridSearchingError: StatusCode.ErrorGridSearching,
97127
TimeExtrapolationError: StatusCode.ErrorTimeExtrapolation,
98128
KernelError: StatusCode.Error,
129+
GeneralError: StatusCode.Error,
99130
}

0 commit comments

Comments
 (0)