Skip to content

Commit 33ed766

Browse files
authored
Merge pull request #1761 from knutfrode/dev
Added more tests for OpenBerg, revealing a 180 degree error of wave d…
2 parents a8634a5 + a6b0db9 commit 33ed766

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

opendrift/models/openberg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def advect_iceberg(self):
443443
sea_slope_y = self.environment.sea_surface_y_slope
444444
sea_surface_height= self.environment.sea_surface_height
445445
wave_height = self.environment.sea_surface_wave_significant_height
446-
wave_direction = self.environment.sea_surface_wave_from_direction
446+
wave_direction = -self.environment.sea_surface_wave_from_direction
447447
sea_ice_thickness = self.environment.sea_ice_thickness
448448
sea_ice_conc = self.environment.sea_ice_area_fraction
449449
water_depth = self.environment.sea_floor_depth_below_sea_level

opendrift/models/physics_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def calculate_missing_environment_variables(self):
828828
if hasattr(self.environment, 'sea_surface_wave_from_direction') and \
829829
self.environment.sea_surface_wave_from_direction.max() == 0:
830830
wave_direction = np.rad2deg(np.arctan2(self.environment.x_wind, self.environment.y_wind))
831-
self.environment.sea_surface_wave_from_direction = wave_direction
831+
self.environment.sea_surface_wave_from_direction = -wave_direction
832832
logger.warning('Setting wave direction equal to wind direction, min: %f, mean: %f, max: %f' %
833833
(wave_direction.min(), wave_direction.mean(), wave_direction.max()))
834834

tests/models/test_openberg.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,36 @@
3030

3131
def test_openberg_constant_forcing():
3232

33+
# No current and wind, waves from west
34+
o = OpenBerg(loglevel=50)
35+
o.set_config('environment:constant:x_sea_water_velocity', 0)
36+
o.set_config('environment:constant:y_sea_water_velocity', 0)
37+
o.set_config('environment:constant:x_wind', 0)
38+
o.set_config('environment:constant:y_wind', 0)
39+
o.set_config('environment:constant:sea_surface_wave_significant_height', 3)
40+
o.set_config('environment:constant:sea_surface_wave_from_direction', 270)
41+
o.set_config('drift:horizontal_diffusivity', 0)
42+
o.set_config('drift:coriolis', False)
43+
o.seed_elements(4, 60, time=datetime.now())
44+
o.run(steps=2)
45+
np.testing.assert_almost_equal(o.result.lon.isel(time=-1), 4.127, 3)
46+
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 60.0, 3)
47+
48+
# No current and wind, waves from east
49+
o = OpenBerg(loglevel=50)
50+
o.set_config('environment:constant:x_sea_water_velocity', 0)
51+
o.set_config('environment:constant:y_sea_water_velocity', 0)
52+
o.set_config('environment:constant:x_wind', 0)
53+
o.set_config('environment:constant:y_wind', 0)
54+
o.set_config('environment:constant:sea_surface_wave_significant_height', 3)
55+
o.set_config('environment:constant:sea_surface_wave_from_direction', 90)
56+
o.set_config('drift:horizontal_diffusivity', 0)
57+
o.set_config('drift:coriolis', False)
58+
o.seed_elements(4, 60, time=datetime.now())
59+
o.run(steps=2)
60+
np.testing.assert_almost_equal(o.result.lon.isel(time=-1), 3.873, 3)
61+
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 60.0, 3)
62+
3363
# Northwards current, no wind, no Coriolis
3464
o = OpenBerg(loglevel=50)
3565
o.set_config('environment:constant:x_sea_water_velocity', 0)
@@ -70,7 +100,7 @@ def test_openberg_constant_forcing():
70100
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 60.058, 3)
71101

72102
# No current, eastwards wind
73-
o = OpenBerg(loglevel=0)
103+
o = OpenBerg(loglevel=50)
74104
o.set_config('environment:constant:x_sea_water_velocity', 0)
75105
o.set_config('environment:constant:y_sea_water_velocity', 0)
76106
o.set_config('environment:constant:x_wind', 10)
@@ -83,7 +113,7 @@ def test_openberg_constant_forcing():
83113
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 60.000, 3)
84114

85115
# No current, weaker eastwards wind
86-
o = OpenBerg(loglevel=0)
116+
o = OpenBerg(loglevel=50)
87117
o.set_config('environment:constant:x_sea_water_velocity', 0)
88118
o.set_config('environment:constant:y_sea_water_velocity', 0)
89119
o.set_config('environment:constant:x_wind', 5)
@@ -97,7 +127,7 @@ def test_openberg_constant_forcing():
97127
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 60.000, 3)
98128

99129
# No current, westwards wind
100-
o = OpenBerg(loglevel=0)
130+
o = OpenBerg(loglevel=50)
101131
o.set_config('environment:constant:x_sea_water_velocity', 0)
102132
o.set_config('environment:constant:y_sea_water_velocity', 0)
103133
o.set_config('environment:constant:x_wind', -10)
@@ -110,7 +140,7 @@ def test_openberg_constant_forcing():
110140
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 60.000, 3)
111141

112142
# No current, northwards wind
113-
o = OpenBerg(loglevel=0)
143+
o = OpenBerg(loglevel=50)
114144
o.set_config('environment:constant:x_sea_water_velocity', 0)
115145
o.set_config('environment:constant:y_sea_water_velocity', 0)
116146
o.set_config('environment:constant:x_wind', 0)
@@ -123,7 +153,7 @@ def test_openberg_constant_forcing():
123153
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 60.054, 3)
124154

125155
# No current, southwards wind
126-
o = OpenBerg(loglevel=0)
156+
o = OpenBerg(loglevel=50)
127157
o.set_config('environment:constant:x_sea_water_velocity', 0)
128158
o.set_config('environment:constant:y_sea_water_velocity', 0)
129159
o.set_config('environment:constant:x_wind', 0)
@@ -136,9 +166,6 @@ def test_openberg_constant_forcing():
136166
np.testing.assert_almost_equal(o.result.lat.isel(time=-1), 59.946, 3)
137167

138168

139-
140-
141-
142169
def test_openberg_norkyst():
143170
o = OpenBerg()
144171
reader_current = reader_netCDF_CF_generic.Reader(tdf +

0 commit comments

Comments
 (0)