Note
Go to the end to download the full example code.
2D simulation profile
from datetime import datetime, timedelta
import numpy as np
from opendrift.models.oceandrift import OceanDrift
o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
13:20:24 INFO opendrift:568: OpenDriftSimulation initialised (version 1.14.3 / v1.14.3-2-g7a367c6)
Define some constant current, wind and Stokes drift
o.set_config('environment:fallback:x_wind', 7)
o.set_config('environment:fallback:x_sea_water_velocity', .1)
o.set_config('environment:fallback:sea_surface_wave_stokes_drift_x_velocity', .2)
o.set_config('environment:fallback:sea_surface_wave_significant_height', 2)
Seed elements between surface and 5m depth
time = datetime.utcnow()
z = -np.linspace(0, 5, 50)
o.seed_elements(lon=4.5, lat=60.0, z=z, radius=0, number=len(z), time=time)
/root/project/examples/example_2d.py:22: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
time = datetime.utcnow()
13:20:24 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
13:20:28 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
13:20:28 INFO opendrift.models.basemodel.environment:232: x_sea_water_velocity: 0.100000
13:20:28 INFO opendrift.models.basemodel.environment:232: y_sea_water_velocity: 0.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: sea_surface_height: 0.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: x_wind: 7.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: y_wind: 0.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 2.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.200000
13:20:28 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000
13:20:28 INFO opendrift.models.basemodel.environment:232: sea_floor_depth_below_sea_level: 10000.000000
Running model for 6 hours
o.run(duration=timedelta(hours=6), time_step=600)
13:20:28 INFO opendrift:1778: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
13:20:28 INFO opendrift:1778: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
13:20:28 INFO opendrift:1789: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:20:28 INFO opendrift:1789: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:20:28 INFO opendrift:1797: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
13:20:28 INFO opendrift:944: Using existing reader for land_binary_mask to move elements to ocean
13:20:28 INFO opendrift:974: All points are in ocean
13:20:28 INFO opendrift:2085: 2025-09-01 13:20:24.047008 - step 1 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 13:30:24.047008 - step 2 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 13:40:24.047008 - step 3 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 13:50:24.047008 - step 4 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 14:00:24.047008 - step 5 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 14:10:24.047008 - step 6 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 14:20:24.047008 - step 7 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 14:30:24.047008 - step 8 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 14:40:24.047008 - step 9 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 14:50:24.047008 - step 10 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 15:00:24.047008 - step 11 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 15:10:24.047008 - step 12 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 15:20:24.047008 - step 13 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 15:30:24.047008 - step 14 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 15:40:24.047008 - step 15 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 15:50:24.047008 - step 16 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 16:00:24.047008 - step 17 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 16:10:24.047008 - step 18 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 16:20:24.047008 - step 19 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 16:30:24.047008 - step 20 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 16:40:24.047008 - step 21 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 16:50:24.047008 - step 22 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 17:00:24.047008 - step 23 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 17:10:24.047008 - step 24 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 17:20:24.047008 - step 25 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 17:30:24.047008 - step 26 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 17:40:24.047008 - step 27 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 17:50:24.047008 - step 28 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 18:00:24.047008 - step 29 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 18:10:24.047008 - step 30 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 18:20:24.047008 - step 31 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 18:30:24.047008 - step 32 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 18:40:24.047008 - step 33 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 18:50:24.047008 - step 34 of 36 - 50 active elements (0 deactivated)
13:20:28 INFO opendrift:2085: 2025-09-01 19:00:24.047008 - step 35 of 36 - 50 active elements (0 deactivated)
13:20:29 INFO opendrift:2085: 2025-09-01 19:10:24.047008 - step 36 of 36 - 50 active elements (0 deactivated)
To check that z is really kept constant for all particles
o.plot_property('z')

Vertical profile of advection. Note the decaying importance of Stokes drift, and the additional windage of the element at surface
o.animation_profile()
13:20:29 INFO opendrift:4609: Saving animation to /root/project/docs/source/gallery/animations/example_2d_0.gif...
13:20:34 INFO opendrift:3260: Time to make animation: 0:00:05.552693

Total running time of the script: (0 minutes 16.540 seconds)