Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions WeatherRoutingTool/ship/direct_power_boat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ship.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down