|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +Vertical advection correction |
| 4 | +============================= |
| 5 | +""" |
| 6 | + |
| 7 | +#%% |
| 8 | +# In OpenDrift, element depth (z) is relative to actual surface, and not mean sea level. |
| 9 | +# Vertical velocity from ocean models contain a contribution which is due to |
| 10 | +# change in sea surface elevation, however, this should in OpenDrift be subtracted |
| 11 | +# due to the choice of defining z relative to actual surface elevation |
| 12 | +# This correction is activated with config setting 'drift:vertical_advection_correction' |
| 13 | +# The effect is illustrated with the simulations below. |
| 14 | + |
| 15 | + |
| 16 | +from datetime import datetime, timedelta |
| 17 | +import numpy as np |
| 18 | +import matplotlib.pyplot as plt |
| 19 | +from opendrift.readers import reader_oscillating |
| 20 | +from opendrift.models.oceandrift import OceanDrift |
| 21 | + |
| 22 | +time = datetime.now() |
| 23 | +reader_tidal = reader_oscillating.Reader('sea_surface_height', amplitude=-1, |
| 24 | + period=timedelta(hours=6), zero_time=time) |
| 25 | +lat=59.8113; lon=10.5517 # Oslo fjord |
| 26 | +z = np.arange(0, -60, -5) # Seeding one particle every 5 meter from surface to 60m depth |
| 27 | + |
| 28 | +# Without stetching |
| 29 | +o = OceanDrift(loglevel=0) |
| 30 | +o.add_reader(reader_tidal) |
| 31 | +o.add_readers_from_list(['https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be']) |
| 32 | +o.set_config('drift:water_column_stretching', False) |
| 33 | +o.set_config('drift:vertical_advection', True) |
| 34 | +o.seed_elements(lon=lon, lat=lat, time=time, z=z, number=len(z)) |
| 35 | +o.run(duration=timedelta(hours=24), time_step=1800) |
| 36 | + |
| 37 | +# With stetching |
| 38 | +o2 = OceanDrift(loglevel=0) |
| 39 | +o2.add_reader(reader_tidal) |
| 40 | +o2.add_readers_from_list(['https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be']) |
| 41 | +o2.set_config('drift:water_column_stretching', True) |
| 42 | +o2.set_config('drift:vertical_advection', True) |
| 43 | +o2.seed_elements(lon=lon, lat=lat, time=time, z=z, number=len(z)) |
| 44 | +o2.run(duration=timedelta(hours=24), time_step=1800) |
| 45 | + |
| 46 | +# With w correction |
| 47 | +o3 = OceanDrift(loglevel=0) |
| 48 | +o3.add_reader(reader_tidal) |
| 49 | +o3.add_readers_from_list(['https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be']) |
| 50 | +o3.set_config('drift:water_column_stretching', False) |
| 51 | +o3.set_config('drift:vertical_advection', True) |
| 52 | +o3.set_config('drift:vertical_advection_correction', True) |
| 53 | +o3.seed_elements(lon=lon, lat=lat, time=time, z=z, number=len(z)) |
| 54 | +o3.run(duration=timedelta(hours=24), time_step=1800) |
| 55 | + |
| 56 | + |
| 57 | +plt.subplot(3,1,1) |
| 58 | +o.result.z.plot.line(x='time', add_legend=False, color='k') |
| 59 | +o2.result.z.plot.line(x='time', add_legend=False, color='r') |
| 60 | +o3.result.z.plot.line(x='time', add_legend=False, color='g') |
| 61 | +plt.plot([], [], color='k', label='No stretching or correction') |
| 62 | +plt.plot([], [], color='r', label='Column stretching') |
| 63 | +plt.plot([], [], color='g', label='Vertical velocity correction') |
| 64 | +plt.legend() |
| 65 | +plt.subplot(3,1,2) |
| 66 | +o.result.sea_floor_depth_below_sea_level.plot.line(x='time', add_legend=False, color='k') |
| 67 | +plt.subplot(3,1,3) |
| 68 | +o.result.upward_sea_water_velocity.plot.line(x='time', add_legend=False, color='k') |
| 69 | +plt.show() |
0 commit comments