fix (ship): clamp arcsin argument to [-1, 1] with np.clip to prevent NaN - #202
Open
vaaiiibbhav wants to merge 1 commit into
Open
fix (ship): clamp arcsin argument to [-1, 1] with np.clip to prevent NaN#202vaaiiibbhav wants to merge 1 commit into
vaaiiibbhav wants to merge 1 commit into
Conversation
Floating-point rounding could push arg_arcsin in get_apparent_wind slightly outside the valid domain of np.arcsin. The previous manual check only clamped the upper bound, so values marginally below -1 produced silent NaNs that corrupted apparent wind angles and downstream fuel/route metrics. Replace the one-sided check with a two-sided np.clip. Fixes 52North#170 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vaaiiibbhav
force-pushed
the
vaibhav/fix-arcsin-nan
branch
from
July 18, 2026 14:41
ecd9d72 to
5241d23
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Floating-point rounding could push arg_arcsin in get_apparent_wind slightly outside the valid domain of np.arcsin. The previous manual check only clamped the upper bound, so values marginally below -1 produced silent NaNs that corrupted apparent wind angles and downstream fuel/route metrics. Replace the one-sided check with a two-sided np.clip.
Fixes #170
Related Issue / Discussion:
Fixes Issue #170
Changes:
WeatherRoutingTool/ship/direct_power_boat.py— Replaced the manual one-sided upper bound check forarg_arcsininsideget_apparent_wind()with a robust two-sidednp.clip.Further Details:
Summary:
get_apparent_wind(), floating-point rounding errors occasionally pushed the argument fornp.arcsin()slightly outside the strict math domain of [-1, 1]. While an existing manual check handled the upper threshold, values slightly falling below -1 bypassed it, generating silentNaNvalues that cascaded down into critical ship routing and fuel consumption metrics.diff_to_one) that only protected against exceeding the upper bound of 1.0.np.clip(arg_arcsin, -1 * u.radian, 1 * u.radian), ensuring absolute two-sided domain safety while cleanly preserving theastropy.unitsQuantity wrapper.Dependencies:
PR Checklist: