|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +Water column stretching |
| 4 | +======================== |
| 5 | +""" |
| 6 | + |
| 7 | +from datetime import datetime, timedelta |
| 8 | +import numpy as np |
| 9 | +import matplotlib.pyplot as plt |
| 10 | +from opendrift.readers import reader_oscillating |
| 11 | +from opendrift.models.oceandrift import OceanDrift |
| 12 | + |
| 13 | + |
| 14 | +#%% |
| 15 | +# In OpenDrift, the vertical position of elements ("z") is defined as relative to actual surface, |
| 16 | +# and not an absolute reference level (e.g. mean sea surface height). |
| 17 | +# Thus if sea surface elevation changes with time (e.g. tides), |
| 18 | +# we need to add a "correction / perturbation" to z, otherwise elements at/near seafloor |
| 19 | +# will be lifted if surface elevation increases and z (relative to surface) remains unchanged. |
| 20 | +# This correction is presently only implemented for OceanDrift, and must be switched on |
| 21 | +# with config setting "drift:water:column_stretching" |
| 22 | + |
| 23 | +# To illustrate, we add a reader with oscillating sea surface elevation (tidal) |
| 24 | +# with amplitude of 1m and peroid of 6 hours |
| 25 | +time = datetime.now() |
| 26 | +reader_tidal = reader_oscillating.Reader('sea_surface_height', amplitude=-1, |
| 27 | + period=timedelta(hours=6), zero_time=time) |
| 28 | + |
| 29 | +#%% |
| 30 | +# First an illustration withouth this correction. |
| 31 | +o = OceanDrift(loglevel=20) |
| 32 | +o.add_reader(reader_tidal) |
| 33 | +o.set_config('drift:water_column_stretching', False) |
| 34 | +o.set_config('environment:constant:sea_floor_depth_below_sea_level', 10) |
| 35 | +z = np.arange(0, -11, -1) # Seeding one particle every meter from surface to 10m depth |
| 36 | +o.seed_elements(lon=0, lat=0, time=time, z=z, number=11) |
| 37 | +o.run(duration=timedelta(hours=24), time_step=1800) |
| 38 | +o.result.z.plot.line(x='time', add_legend=False) |
| 39 | +plt.show() |
| 40 | + |
| 41 | +#%% |
| 42 | +# We see that the particles remain at their initial depths (since we have no vertical advection or mixing), |
| 43 | +# except for the element starting at seafloor, which is lifted up when sea level rises, |
| 44 | +# since the config setting `drift:seafloor_action` is `lift_to_seafloor` by default. |
| 45 | +# This lifting is in this case unphysical. |
| 46 | + |
| 47 | +#%% |
| 48 | +o = OceanDrift(loglevel=20) |
| 49 | +o.add_reader(reader_tidal) |
| 50 | +o.set_config('drift:water_column_stretching', True) |
| 51 | +o.set_config('environment:constant:sea_floor_depth_below_sea_level', 10) |
| 52 | +o.seed_elements(lon=0, lat=0, time=time, z=z, number=11) |
| 53 | +o.run(duration=timedelta(hours=24), time_step=1800) |
| 54 | +o.result.z.plot.line(x='time', add_legend=False) |
| 55 | +plt.show() |
| 56 | + |
| 57 | +# Here we see that element depth (z, relative to surface) is changed so that |
| 58 | +# elements at surface and seafloor remain at resp surface (z=0) and |
| 59 | +# seafloor (z = sea_floor_depth + sea_surface_elevation) |
0 commit comments