Skip to content

Commit 6fdfc3a

Browse files
committed
Review feedback
#1816 (comment)
1 parent 027ecce commit 6fdfc3a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

parcels/_index_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def search_indices_vertical_z(grid: Grid, gridindexingtype: GridIndexingType, z:
3030
if gridindexingtype == "mom5" and z > 2 * grid.depth[0] - grid.depth[1]:
3131
return (-1, z / grid.depth[0])
3232
else:
33-
_raise_field_out_of_bound_surface_error(z, 0, 0)
33+
_raise_field_out_of_bound_surface_error(z, None, None)
3434
elif z > grid.depth[-1]:
3535
# In case of CROCO, allow particles in last (uppermost) layer using depth[-1]
3636
if gridindexingtype in ["croco"] and z < 0:
@@ -43,7 +43,7 @@ def search_indices_vertical_z(grid: Grid, gridindexingtype: GridIndexingType, z:
4343
zi = depth_indices.argmin() - 1 if z >= grid.depth[0] else 0
4444
else:
4545
if z > grid.depth[0]:
46-
_raise_field_out_of_bound_surface_error(z, 0, 0)
46+
_raise_field_out_of_bound_surface_error(z, None, None)
4747
elif z < grid.depth[-1]:
4848
_raise_field_out_of_bound_error(z, 0, 0)
4949
depth_indices = grid.depth >= z
@@ -106,7 +106,7 @@ def search_indices_vertical_s(
106106
else:
107107
zi = depth_indices.argmin() - 1 if z >= depth_vector[0] else 0
108108
if z < depth_vector[zi]:
109-
_raise_field_out_of_bound_surface_error(z, 0, 0)
109+
_raise_field_out_of_bound_surface_error(z, None, None)
110110
elif z > depth_vector[zi + 1]:
111111
_raise_field_out_of_bound_error(z, y, x)
112112
else:
@@ -116,7 +116,7 @@ def search_indices_vertical_s(
116116
else:
117117
zi = depth_indices.argmin() - 1 if z <= depth_vector[0] else 0
118118
if z > depth_vector[zi]:
119-
_raise_field_out_of_bound_surface_error(z, 0, 0)
119+
_raise_field_out_of_bound_surface_error(z, None, None)
120120
elif z < depth_vector[zi + 1]:
121121
_raise_field_out_of_bound_error(z, y, x)
122122
zeta = (z - depth_vector[zi]) / (depth_vector[zi + 1] - depth_vector[zi])

parcels/tools/statuscodes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ def _raise_field_out_of_bound_error(z, y, x):
6161
raise FieldOutOfBoundError(f"Field sampled out-of-bound, at (depth={z}, lat={y}, lon={x})")
6262

6363

64-
def _raise_field_out_of_bound_surface_error(z, y, x):
65-
raise FieldOutOfBoundSurfaceError(f"Field sampled out-of-bound at the surface, at (depth={z}, lat={y}, lon={x})")
64+
def _raise_field_out_of_bound_surface_error(z: float | None, y: float | None, x: float | None) -> None:
65+
def format_out(val):
66+
return "unknown" if val is None else val
67+
68+
raise FieldOutOfBoundSurfaceError(
69+
f"Field sampled out-of-bound at the surface, at (depth={format_out(z)}, lat={format_out(y)}, lon={format_out(x)})"
70+
)
6671

6772

6873
class TimeExtrapolationError(RuntimeError):

0 commit comments

Comments
 (0)