Skip to content

Fix arcsin lower bound#184

Open
shreyadesai20042009 wants to merge 3 commits into52North:mainfrom
shreyadesai20042009:fix-arcsin-lower-bound
Open

Fix arcsin lower bound#184
shreyadesai20042009 wants to merge 3 commits into52North:mainfrom
shreyadesai20042009:fix-arcsin-lower-bound

Conversation

@shreyadesai20042009
Copy link
Copy Markdown

@shreyadesai20042009 shreyadesai20042009 commented Mar 24, 2026

Related Issue / Discussion:

Fixes Issue #170


Changes:

Please list the central functionalities that have been changed:

  • Modified class / file: WeatherRoutingTool/ship/direct_power_boat.py
  • Modified function: get_apparent_wind
  • Added test: test_get_apparent_wind_no_nan_with_edge_values
  • Additional test for zero wind speed case

Further Details:

Summary:

This PR addresses an issue where NaN values were produced in the apparent wind calculation for certain edge cases of wind direction and speed.

Previously, floating-point precision errors caused invalid inputs to trigonometric functions (specifically arcsin), leading to NaN outputs. This affected the reliability of downstream routing computations.

After the fix:

  • Inputs to trigonometric functions are properly bounded
  • Numerical stability is ensured
  • No NaN values are produced for edge cases

🧪 Test Coverage

Added test to validate behavior:

def test_get_apparent_wind_no_nan_with_edge_values(self):
    wind_dir = np.array([0, 90, 180]) * u.degree
    wind_speed = np.array([10, 10, 10]) * u.meter / u.second

    pol = basic_test_func.create_dummy_Direct_Power_Ship('simpleship')
    wind_result = pol.get_apparent_wind(wind_speed, wind_dir)

    assert not np.isnan(wind_result['app_wind_speed']).any()
    assert not np.isnan(wind_result['app_wind_angle']).any()

🚀 Additional Improvement

To further improve robustness:

def test_get_apparent_wind_zero_speed(self):
    wind_dir = np.array([0, 90, 180]) * u.degree
    wind_speed = np.array([0, 0, 0]) * u.meter / u.second

    pol = basic_test_func.create_dummy_Direct_Power_Ship('simpleship')
    wind_result = pol.get_apparent_wind(wind_speed, wind_dir)

    assert not np.isnan(wind_result['app_wind_speed']).any()
    assert not np.isnan(wind_result['app_wind_angle']).any()

⚠️ Troubleshooting

❌ Case 2: Test FAILED

👉 Copy the error and paste it here.

Common causes:

  • Incorrect calculation in get_apparent_wind
  • NaN values still being generated

⚠️ Case 3: Missing Modules

Example:

ModuleNotFoundError: numpy / scipy / pandas

👉 Install dependencies:

pip install numpy scipy pandas

Dependencies:

  • No new dependencies introduced

PR Checklist:

In the context of this PR, I:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant