Skip to content

Commit c16984d

Browse files
authored
Merge pull request #1652 from knutfrode/dev
Skipping water_column_stretching and vertical_advection_correction if…
2 parents 3aadc59 + 1d95ad1 commit c16984d

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

opendrift/models/oceandrift.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ def water_column_stretching(self):
301301
if self.get_config('drift:water_column_stretching') is False:
302302
return
303303

304+
if self.environment_previous is None or 'sea_surface_height' not in self.environment_previous:
305+
logger.warning('water_column_stretching requires storing '
306+
'previous value of sea_surface_height')
307+
return
308+
304309
delta_zeta = self.environment.sea_surface_height - self.environment_previous.sea_surface_height
305310
logger.info('Compensating for change in surface elevation')
306311
self.elements.z = self.elements.z + delta_zeta*(self.elements.z/self.environment.sea_floor_depth_below_sea_level)
@@ -327,13 +332,17 @@ def vertical_advection(self):
327332
w = self.environment.upward_sea_water_velocity[applicable]
328333

329334
if self.get_config('drift:vertical_advection_correction', None) is True:
330-
logger.debug('Subtracting motion due to elevation change from vertical water velocity')
331-
delta_zeta = self.environment.sea_surface_height[applicable] - self.environment_previous.sea_surface_height[applicable]
332-
w_surface = delta_zeta / self.time_step.total_seconds()
333-
total_depth = self.environment.sea_surface_height[applicable] + \
334-
self.environment.sea_floor_depth_below_sea_level[applicable]
335-
w_elevation = w_surface * (self.elements.z[applicable] + total_depth) / total_depth
336-
w = w - w_elevation
335+
if self.environment_previous is not None and 'sea_surface_height' in self.environment_previous:
336+
logger.debug('Subtracting motion due to elevation change from vertical water velocity')
337+
delta_zeta = self.environment.sea_surface_height[applicable] - self.environment_previous.sea_surface_height[applicable]
338+
w_surface = delta_zeta / self.time_step.total_seconds()
339+
total_depth = self.environment.sea_surface_height[applicable] + \
340+
self.environment.sea_floor_depth_below_sea_level[applicable]
341+
w_elevation = w_surface * (self.elements.z[applicable] + total_depth) / total_depth
342+
w = w - w_elevation
343+
else:
344+
logger.warning('vertical_advection_correction requires storing '
345+
'previous value of sea_surface_height')
337346

338347
self.elements.z[applicable] = np.minimum(0,
339348
self.elements.z[applicable] + self.elements.moving[applicable] * w *

0 commit comments

Comments
 (0)