Skip to content

Commit d59deba

Browse files
authored
Merge pull request #1740 from knutfrode/dev
OpenBerg: added min and max values for iceberg dimensions. Added defa…
2 parents 2e50c5d + 04db311 commit d59deba

6 files changed

Lines changed: 38 additions & 18 deletions

File tree

opendrift/models/basemodel/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,7 @@ def set_up_map(self,
25262526
land_color = 'gray'
25272527
else:
25282528
land_color = cfeature.COLORS['land']
2529+
land_zorder = kwargs.pop('land_zorder', 10)
25292530

25302531
if 'text' in kwargs:
25312532
if not isinstance(kwargs['text'], list):
@@ -2582,9 +2583,10 @@ def set_up_map(self,
25822583
facecolor=facecolor,
25832584
edgecolor='black')
25842585
else:
2585-
reader_global_landmask.plot_land(ax, lonmin, latmin, lonmax,
2586-
latmax, fast, ocean_color,
2587-
land_color, lscale,
2586+
reader_global_landmask.plot_land(ax, lonmin, latmin, lonmax, latmax,
2587+
fast=fast, ocean_color=ocean_color,
2588+
land_color=land_color, land_zorder=land_zorder,
2589+
lscale=lscale,
25882590
crs_plot=self.crs_plot,
25892591
crs_lonlat=self.crs_lonlat)
25902592

opendrift/models/openberg.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,29 @@ class IcebergObj(LagrangianArray):
5151
('sail', {'dtype': np.float32,
5252
'units': 'm',
5353
'default': 10,
54+
'min': 1,
55+
'max': 100,
5456
'description': 'Sail of iceberg (part above waterline)',
5557
'level': CONFIG_LEVEL_ESSENTIAL}),
5658
('draft', {'dtype': np.float32,
5759
'units': 'm',
5860
'default': 90,
61+
'min': 1,
62+
'max': 1000,
5963
'description': 'Draft of iceberg (part below waterline)',
6064
'level': CONFIG_LEVEL_ESSENTIAL}),
6165
('length', {'dtype': np.float32,
6266
'units': 'm',
6367
'default': 100,
68+
'min': 1,
69+
'max': 10000,
6470
'description': 'Length of iceberg',
6571
'level': CONFIG_LEVEL_ESSENTIAL}),
6672
('width', {'dtype': np.float32,
6773
'units': 'm',
6874
'default': 30,
75+
'min': 1,
76+
'max': 10000,
6977
'description': 'Width of iceberg)',
7078
'level': CONFIG_LEVEL_ESSENTIAL}),
7179
('weight_coef', {'dtype': np.float32, #This parameter is relative to the shape of iceberg (e.g. 1 for tabular; 0.3 for pinnacle: It affects the mass only)
@@ -287,15 +295,15 @@ class OpenBerg(OpenDriftSimulation):
287295
"x_sea_water_velocity": {"fallback": None, "profiles": True},
288296
"y_sea_water_velocity": {"fallback": None, "profiles": True},
289297
"sea_floor_depth_below_sea_level": {"fallback": 10000},
290-
'sea_surface_height': {'fallback': 0},
291-
"sea_surface_x_slope": {"fallback": 0},
292-
"sea_surface_y_slope": {"fallback": 0},
298+
'sea_surface_height': {'fallback': 0, 'important': False},
299+
"sea_surface_x_slope": {"fallback": 0, 'important': False},
300+
"sea_surface_y_slope": {"fallback": 0, 'important': False},
293301
"x_wind": {"fallback": None, "important": True},
294302
"y_wind": {"fallback": None, "important": True},
295303
"sea_surface_wave_significant_height": {"fallback": 0},
296304
"sea_surface_wave_from_direction": {"fallback": 0},
297-
"sea_surface_wave_stokes_drift_x_velocity": {"fallback": 0},
298-
"sea_surface_wave_stokes_drift_y_velocity": {"fallback": 0},
305+
"sea_surface_wave_stokes_drift_x_velocity": {"fallback": 0, 'important': False},
306+
"sea_surface_wave_stokes_drift_y_velocity": {"fallback": 0, 'important': False},
299307
"sea_water_temperature": {"fallback": 2, "profiles": True},
300308
"sea_water_salinity": {"fallback": 35, "profiles": True},
301309
"sea_ice_area_fraction": {"fallback": 0},
@@ -408,6 +416,11 @@ def __init__(self, *args, **kwargs):
408416
},
409417
})
410418

419+
# Since OpenBerg model is deterministic for given iceberg size,
420+
# (in contrast to the Leeway model), we use a default diffusivity
421+
# to yield some variability.
422+
self._set_config_default('drift:horizontal_diffusivity', 100)
423+
411424

412425
def advect_iceberg(self):
413426
sail = self.elements.sail
@@ -504,8 +517,7 @@ def dynamic(t,iceb_vel, water_vel, wind_vel, wave_height, wave_direction, Avo, A
504517
if grounding:
505518
# Determine which icebergs are grounded
506519
if np.any(grounded):
507-
logger.debug(f"Grounding condition: Icebergs grounded = {np.sum(grounded)}, "
508-
f"hwall = {np.round(hwall[grounded], 3)} meters")
520+
logger.debug(f"Grounding condition: Icebergs grounded = {np.sum(grounded)}")
509521
# Grounded icebergs stop moving
510522
self.elements.moving[grounded] = 0
511523
else:
@@ -514,8 +526,7 @@ def dynamic(t,iceb_vel, water_vel, wind_vel, wave_height, wave_direction, Avo, A
514526
# Check for Degrounding regardless of whether grounding occurred now
515527
degrounding = np.logical_and(self.elements.moving == 0, hwall < 0)
516528
if np.any(degrounding):
517-
logger.debug(f"Degrounding condition: Icebergs degrounded = {np.sum(degrounding)}, "
518-
f"hwall = {np.round(hwall[degrounding], 3)} meters")
529+
logger.debug(f"Degrounding condition: Icebergs degrounded = {np.sum(degrounding)}")
519530
# Degrounded icebergs start moving again
520531
self.elements.moving[degrounding] = 1
521532
else:

opendrift/readers/reader_global_landmask.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def intersecting_geometries(self, extent):
123123
logger.debug(f"Adding GSHHG shapes from cartopy, scale: {scale}, extent: {extent}..")
124124
return super().intersecting_geometries(extent)
125125

126-
def plot_land(ax, lonmin, latmin, lonmax, latmax, fast, ocean_color = 'white', land_color = cfeature.COLORS['land'], lscale = 'auto', crs_plot=None, crs_lonlat=None):
126+
def plot_land(ax, lonmin, latmin, lonmax, latmax, fast,
127+
ocean_color='white', land_color=cfeature.COLORS['land'], land_zorder=0,
128+
lscale='auto', crs_plot=None, crs_lonlat=None):
127129
"""
128130
Plot the landmask or the shapes from GSHHG.
129131
"""
@@ -166,7 +168,7 @@ def show_landmask_roaring(roaring):
166168
cmap = colors.ListedColormap([ocean_color, land_color])
167169

168170
ax.imshow(img, origin = 'lower',
169-
extent=extent, zorder=0, cmap=cmap,
171+
extent=extent, zorder=land_zorder, cmap=cmap,
170172
transform=transform)
171173

172174
if fast:
@@ -190,7 +192,7 @@ def show_landmask_roaring(roaring):
190192

191193
land = LandmaskFeature(scale=lscale, facecolor=land_color, globe=crs_lonlat.globe, levels=[1,5,6])
192194

193-
ax.add_feature(land, zorder=0,
195+
ax.add_feature(land, zorder=land_zorder,
194196
facecolor=land_color,
195197
edgecolor='black')
196198

tests/models/test_openberg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_openberg_constant_forcing():
3636
o.set_config('environment:constant:y_sea_water_velocity', 1)
3737
o.set_config('environment:constant:x_wind', 0)
3838
o.set_config('environment:constant:y_wind', 0)
39+
o.set_config('drift:horizontal_diffusivity', 0)
3940
o.set_config('drift:coriolis', False)
4041
o.seed_elements(4, 60, time=datetime.now())
4142
o.run(steps=2)
@@ -48,6 +49,7 @@ def test_openberg_constant_forcing():
4849
o.set_config('environment:constant:y_sea_water_velocity', 1)
4950
o.set_config('environment:constant:x_wind', 0)
5051
o.set_config('environment:constant:y_wind', 0)
52+
o.set_config('drift:horizontal_diffusivity', 0)
5153
o.set_config('drift:coriolis', True)
5254
o.seed_elements(4, 60, time=datetime.now())
5355
o.run(steps=2)
@@ -60,6 +62,7 @@ def test_openberg_constant_forcing():
6062
o.set_config('environment:constant:y_sea_water_velocity', 1)
6163
o.set_config('environment:constant:x_wind', 10)
6264
o.set_config('environment:constant:y_wind', 0)
65+
o.set_config('drift:horizontal_diffusivity', 0)
6366
o.set_config('drift:coriolis', True)
6467
o.seed_elements(4, 60, time=datetime.now())
6568
o.run(steps=2)
@@ -74,6 +77,7 @@ def test_openberg_norkyst():
7477
o.add_reader(reader_current)
7578
o.set_config('environment:constant:x_wind', 0)
7679
o.set_config('environment:constant:y_wind', 0)
80+
o.set_config('drift:horizontal_diffusivity', 0)
7781
o.seed_elements(4., 62., time=reader_current.start_time)
7882
o.run(steps=3)
7983

@@ -93,6 +97,7 @@ def test_grounding_and_degrounding():
9397
o.set_config('environment:constant:x_wind', 0)
9498
o.set_config('environment:constant:y_wind', 0)
9599
o.set_config('environment:constant:sea_floor_depth_below_sea_level', 20)
100+
o.set_config('drift:horizontal_diffusivity', 0)
96101
o.set_config('processes:roll_over', False)
97102

98103
drafts=np.arange(15,23)

tests/plotting/test_norkyst.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_fast_norkyst():
2020
time=rn.start_time)
2121
o.run(steps=2)
2222

23-
return o.plot(fast=True, buffer=.2)[1]
23+
return o.plot(fast=True, buffer=.2, land_zorder=0)[1]
2424

2525

2626
@pytest.mark.slow
@@ -38,4 +38,4 @@ def test_norkyst():
3838
time=rn.start_time)
3939
o.run(steps=2)
4040

41-
return o.plot(fast=False, buffer=.2)[1]
41+
return o.plot(fast=False, buffer=.2, land_zorder=0)[1]

tests/readers/test_global_landmask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_plot_auto_scale(test_data, scale, fast, show_plot):
8787
time=reader_nordic.start_time)
8888
oc.run(steps=2)
8989

90-
fig = oc.plot(buffer=5., lscale=scale, fast=fast, show=show_plot)[1]
90+
fig = oc.plot(buffer=5., lscale=scale, fast=fast, show=show_plot, land_zorder=0)[1]
9191
print(fig)
9292
return fig
9393

0 commit comments

Comments
 (0)