Skip to content

fix: correct misplaced parentheses in _Spatialslip zeta corrections#2743

Open
steps-re wants to merge 1 commit into
Parcels-code:mainfrom
steps-re:fix/spatialslip-zeta-parentheses
Open

fix: correct misplaced parentheses in _Spatialslip zeta corrections#2743
steps-re wants to merge 1 commit into
Parcels-code:mainfrom
steps-re:fix/spatialslip-zeta-parentheses

Conversation

@steps-re

Copy link
Copy Markdown
Contributor

What

In the 3D branch of _Spatialslip (src/parcels/interpolators/_xinterpolators.py), the four vertical (zeta) slip corrections have a misplaced closing parenthesis:

f_u = np.where(
    is_land(0, 0, 0, 0) & is_land(0, 0, 0, 1) & is_land(0, 0, 1, 0 & is_land(0, 0, 1, 1) & (zeta > 0)),
    f_u * (a + b * zeta) / zeta,
    f_u,
)

The ) after is_land(0, 0, 1, 0 is missing, so 0 & is_land(0, 0, 1, 1) & (zeta > 0) is passed as is_land's 4th positional argument (the x-index) instead of 0. The & is_land(...) & (zeta > 0) mask that should gate np.where is swallowed into that argument, so both the land test and the zeta position gate are wrong. This breaks the vertical free-/partial-slip boundary correction for 3D C-grid velocities.

Fix

Move the parenthesis so each line matches the analogous, correctly-formed eta/xsi corrections in the same function:

is_land(0, 0, 0, 0) & is_land(0, 0, 0, 1) & is_land(0, 0, 1, 0) & is_land(0, 0, 1, 1) & (zeta > 0)

Same correction applied to all four affected lines (the zeta > 0 and zeta < 1 gates for f_u and f_v).

Testing

pytest tests/test_interpolation.py tests/test_convert.py passes (29 passed, 1 xfailed) with the change. Note the cgrid_velocity case in test_interpolation.py is currently commented out, which is likely why this went unnoticed.

In the 3D branch of _Spatialslip, the four vertical (zeta) slip corrections
had a misplaced closing parenthesis, e.g.:

    is_land(0, 0, 1, 0 & is_land(0, 0, 1, 1) & (zeta > 0))

so the `& is_land(...) & (zeta > 0)` mask meant to gate np.where was instead
swallowed into is_land's 4th positional argument (the x-index). Both the land
test and the zeta position gate were therefore wrong, breaking the vertical
free-/partial-slip boundary correction for 3D C-grid velocities.

Fixed to match the analogous, correctly-formed eta/xsi corrections in the same
function:

    is_land(0, 0, 1, 0) & is_land(0, 0, 1, 1) & (zeta > 0)

Existing interpolation and convert tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant