diff --git a/WeatherRoutingTool/ship/direct_power_boat.py b/WeatherRoutingTool/ship/direct_power_boat.py index 7a87ac4..43bcc6a 100644 --- a/WeatherRoutingTool/ship/direct_power_boat.py +++ b/WeatherRoutingTool/ship/direct_power_boat.py @@ -230,13 +230,17 @@ def get_apparent_wind(self, true_wind_speed, true_wind_angle): arg_arcsin = true_wind_speed[iang] * np.sin(np.radians(true_wind_angle[iang])) / apparent_wind_speed[ iang] * u.radian - # catch it if argument of arcsin is > 1 due to rounding issues but make sure to apply this only for - # rounding issues + # clamp arcsin argument to [-1, 1] to handle floating-point rounding diff_to_one = arg_arcsin - 1 * u.radian if diff_to_one > 0: assert diff_to_one < 0.000001 * u.radian arg_arcsin = 1 * u.radian + diff_to_neg_one = arg_arcsin + 1 * u.radian + if diff_to_neg_one < 0: + assert diff_to_neg_one > -0.000001 * u.radian + arg_arcsin = -1 * u.radian + if apparent_wind_speed[iang] > 0: apparent_wind_angle[iang] = np.arcsin(arg_arcsin.value) * u.radian else: diff --git a/tests/test_ship.py b/tests/test_ship.py index 496a2b3..987703b 100644 --- a/tests/test_ship.py +++ b/tests/test_ship.py @@ -39,7 +39,7 @@ def test_shipparams_get_element(self): salinity = np.array([6.4, 6.5, 6.41, 6.42]) water_temperature = np.array([6.7, 6.8, 6.71, 6.72]) status = np.array([1, 2, 2, 3]) - message = np.array(['OK', 'OK', 'Error' 'OK']) + message = np.array(['OK', 'OK', 'Error', 'OK']) sp = ShipParams(fuel_rate=fuel, power=power, rpm=rpm, speed=speed, r_wind=rwind, r_calm=rcalm, r_waves=rwaves, r_shallow=rshallow, r_roughness=rroughness, wave_height=wave_height, @@ -105,7 +105,7 @@ def test_shipparams_get_single(self): salinity = np.array([6.4, 6.5, 6.41, 6.42]) water_temperature = np.array([6.7, 6.8, 6.71, 6.72]) status = np.array([1, 2, 2, 3]) - message = np.array(['OK', 'OK', 'Error' 'OK']) + message = np.array(['OK', 'OK', 'Error', 'OK']) sp = ShipParams(fuel_rate=fuel, power=power, rpm=rpm, speed=speed, r_wind=rwind, r_calm=rcalm, r_waves=rwaves,