Skip to content

Commit

Permalink
Copying #1834 changes into new _index_search functions
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvansebille committed Jan 31, 2025
1 parent baaf04c commit 10a44f8
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions parcels/_index_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ def search_indices_vertical_z(grid: Grid, gridindexingtype: GridIndexingType, z:
# In case of CROCO, allow particles in last (uppermost) layer using depth[-1]
if gridindexingtype in ["croco"] and z < 0:
return (-2, 1)
_raise_field_out_of_bound_error(z, 0, 0)
depth_indices = grid.depth <= z
_raise_field_out_of_bound_error(z, None, None)
depth_indices = grid.depth < z
if z >= grid.depth[-1]:
zi = len(grid.depth) - 2

Check warning on line 41 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L38-L41

Added lines #L38 - L41 were not covered by tests
else:
zi = depth_indices.argmin() - 1 if z >= grid.depth[0] else 0
zi = depth_indices.argmin() - 1 if z > grid.depth[0] else 0

Check warning on line 43 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L43

Added line #L43 was not covered by tests
else:
if z > grid.depth[0]:

Check warning on line 45 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L45

Added line #L45 was not covered by tests
_raise_field_out_of_bound_surface_error(z, None, None)
elif z < grid.depth[-1]:
_raise_field_out_of_bound_error(z, 0, 0)
depth_indices = grid.depth >= z
_raise_field_out_of_bound_error(z, None, None)
depth_indices = grid.depth > z
if z <= grid.depth[-1]:
zi = len(grid.depth) - 2

Check warning on line 51 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L47-L51

Added lines #L47 - L51 were not covered by tests
else:
zi = depth_indices.argmin() - 1 if z <= grid.depth[0] else 0
zi = depth_indices.argmin() - 1 if z < grid.depth[0] else 0
zeta = (z - grid.depth[zi]) / (grid.depth[zi + 1] - grid.depth[zi])
while zeta > 1:

Check warning on line 55 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L53-L55

Added lines #L53 - L55 were not covered by tests
zi += 1
zeta = (z - grid.depth[zi]) / (grid.depth[zi + 1] - grid.depth[zi])
while zeta < 0:

Check warning on line 58 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L57-L58

Added lines #L57 - L58 were not covered by tests
zi -= 1
zeta = (z - grid.depth[zi]) / (grid.depth[zi + 1] - grid.depth[zi])
return (zi, zeta)

Check warning on line 61 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L60-L61

Added lines #L60 - L61 were not covered by tests


Expand Down Expand Up @@ -98,28 +104,35 @@ def search_indices_vertical_s(
+ xsi * eta * grid.depth[:, yi + 1, xi + 1]
+ (1 - xsi) * eta * grid.depth[:, yi + 1, xi]

Check warning on line 105 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L101-L105

Added lines #L101 - L105 were not covered by tests
)
z = np.float32(z) # type: ignore # TODO: remove type ignore once we migrate to float64

if depth_vector[-1] > depth_vector[0]:
depth_indices = depth_vector <= z
if z < depth_vector[0]:
_raise_field_out_of_bound_error(z, None, None)
elif z > depth_vector[-1]:
_raise_field_out_of_bound_error(z, None, None)
depth_indices = depth_vector < z
if z >= depth_vector[-1]:
zi = len(depth_vector) - 2

Check warning on line 116 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L109-L116

Added lines #L109 - L116 were not covered by tests
else:
zi = depth_indices.argmin() - 1 if z >= depth_vector[0] else 0
if z < depth_vector[zi]:
_raise_field_out_of_bound_surface_error(z, None, None)
elif z > depth_vector[zi + 1]:
_raise_field_out_of_bound_error(z, y, x)
zi = depth_indices.argmin() - 1 if z > depth_vector[0] else 0

Check warning on line 118 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L118

Added line #L118 was not covered by tests
else:
depth_indices = depth_vector >= z
if z > depth_vector[0]:
_raise_field_out_of_bound_error(z, None, None)
elif z < depth_vector[-1]:
_raise_field_out_of_bound_error(z, None, None)
depth_indices = depth_vector > z
if z <= depth_vector[-1]:
zi = len(depth_vector) - 2

Check warning on line 126 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L120-L126

Added lines #L120 - L126 were not covered by tests
else:
zi = depth_indices.argmin() - 1 if z <= depth_vector[0] else 0
if z > depth_vector[zi]:
_raise_field_out_of_bound_surface_error(z, None, None)
elif z < depth_vector[zi + 1]:
_raise_field_out_of_bound_error(z, y, x)
zi = depth_indices.argmin() - 1 if z < depth_vector[0] else 0
zeta = (z - depth_vector[zi]) / (depth_vector[zi + 1] - depth_vector[zi])
while zeta > 1:

Check warning on line 130 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L128-L130

Added lines #L128 - L130 were not covered by tests
zi += 1
zeta = (z - depth_vector[zi]) / (depth_vector[zi + 1] - depth_vector[zi])
while zeta < 0:

Check warning on line 133 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L132-L133

Added lines #L132 - L133 were not covered by tests
zi -= 1
zeta = (z - depth_vector[zi]) / (depth_vector[zi + 1] - depth_vector[zi])
return (zi, zeta)

Check warning on line 136 in parcels/_index_search.py

View check run for this annotation

Codecov / codecov/patch

parcels/_index_search.py#L135-L136

Added lines #L135 - L136 were not covered by tests


Expand Down

0 comments on commit 10a44f8

Please sign in to comment.