Skip to content
Merged
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
42 changes: 27 additions & 15 deletions parcels/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,22 +1006,28 @@
if self.gridindexingtype in ["croco"] and z < 0:
return (-2, 1)
raise FieldOutOfBoundError(z, 0, 0, field=self)
depth_indices = grid.depth <= z
depth_indices = grid.depth < z
if z >= grid.depth[-1]:
zi = len(grid.depth) - 2
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
else:
if z > grid.depth[0]:
raise FieldOutOfBoundSurfaceError(z, 0, 0, field=self)
elif z < grid.depth[-1]:
raise FieldOutOfBoundError(z, 0, 0, field=self)
depth_indices = grid.depth >= z
depth_indices = grid.depth > z
if z <= grid.depth[-1]:
zi = len(grid.depth) - 2
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:
zi += 1
zeta = (z - grid.depth[zi]) / (grid.depth[zi + 1] - grid.depth[zi])

Check warning on line 1027 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1026-L1027

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

Check warning on line 1030 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1029-L1030

Added lines #L1029 - L1030 were not covered by tests
return (zi, zeta)

@deprecated_made_private # TODO: Remove 6 months after v3.1.0
Expand Down Expand Up @@ -1065,26 +1071,32 @@
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 FieldOutOfBoundSurfaceError(z, 0, 0, field=self)

Check warning on line 1075 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1075

Added line #L1075 was not covered by tests
elif z > depth_vector[-1]:
raise FieldOutOfBoundError(z, y, x, field=self)
depth_indices = depth_vector < z
if z >= depth_vector[-1]:
zi = len(depth_vector) - 2
else:
zi = depth_indices.argmin() - 1 if z >= depth_vector[0] else 0
if z < depth_vector[zi]:
zi = depth_indices.argmin() - 1 if z > depth_vector[0] else 0
else:
if z > depth_vector[0]:

Check warning on line 1084 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1084

Added line #L1084 was not covered by tests
raise FieldOutOfBoundSurfaceError(z, 0, 0, field=self)
elif z > depth_vector[zi + 1]:
elif z < depth_vector[-1]:

Check warning on line 1086 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1086

Added line #L1086 was not covered by tests
raise FieldOutOfBoundError(z, y, x, field=self)
else:
depth_indices = depth_vector >= z
depth_indices = depth_vector > z

Check warning on line 1088 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1088

Added line #L1088 was not covered by tests
if z <= depth_vector[-1]:
zi = len(depth_vector) - 2
else:
zi = depth_indices.argmin() - 1 if z <= depth_vector[0] else 0
if z > depth_vector[zi]:
raise FieldOutOfBoundSurfaceError(z, 0, 0, field=self)
elif z < depth_vector[zi + 1]:
raise FieldOutOfBoundError(z, y, x, field=self)
zi = depth_indices.argmin() - 1 if z < depth_vector[0] else 0

Check warning on line 1092 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1092

Added line #L1092 was not covered by tests
zeta = (z - depth_vector[zi]) / (depth_vector[zi + 1] - depth_vector[zi])
while zeta > 1:
zi += 1
zeta = (z - depth_vector[zi]) / (depth_vector[zi + 1] - depth_vector[zi])

Check warning on line 1096 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1096

Added line #L1096 was not covered by tests
while zeta < 0:
zi -= 1
zeta = (z - depth_vector[zi]) / (depth_vector[zi + 1] - depth_vector[zi])

Check warning on line 1099 in parcels/field.py

View check run for this annotation

Codecov / codecov/patch

parcels/field.py#L1099

Added line #L1099 was not covered by tests
return (zi, zeta)

@deprecated_made_private # TODO: Remove 6 months after v3.1.0
Expand Down
Loading