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
09:55:28 INFO opendrift:509: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-59-g60ee835)
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)
o.set_config('environment:fallback:sea_surface_wave_period_at_variance_spectral_density_maximum', 8)
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:23: 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()
09:55:28 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
09:55:32 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
09:55:32 INFO opendrift.models.basemodel.environment:232: x_sea_water_velocity: 0.100000
09:55:32 INFO opendrift.models.basemodel.environment:232: y_sea_water_velocity: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_height: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: x_wind: 7.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: y_wind: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 2.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.200000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_period_at_variance_spectral_density_maximum: 8.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_swell_wave_to_direction: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_swell_wave_significant_height: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wind_wave_to_direction: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wind_wave_mean_period: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: sea_surface_wind_wave_significant_height: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: surface_downward_x_stress: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: surface_downward_y_stress: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: turbulent_kinetic_energy: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: turbulent_generic_length_scale: 0.000000
09:55:32 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000
09:55:32 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)
09:55:32 INFO opendrift:885: Using existing reader for land_binary_mask
09:55:32 INFO opendrift:914: All points are in ocean
09:55:32 INFO opendrift:2035: Storing previous position of elements for coastline interaction
09:55:32 INFO opendrift:2096: 2025-06-26 09:55:28.597414 - step 1 of 36 - 50 active elements (0 deactivated)
09:55:32 INFO opendrift:2096: 2025-06-26 10:05:28.597414 - step 2 of 36 - 50 active elements (0 deactivated)
09:55:32 INFO opendrift:2096: 2025-06-26 10:15:28.597414 - step 3 of 36 - 50 active elements (0 deactivated)
09:55:32 INFO opendrift:2096: 2025-06-26 10:25:28.597414 - step 4 of 36 - 50 active elements (0 deactivated)
09:55:32 INFO opendrift:2096: 2025-06-26 10:35:28.597414 - step 5 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 10:45:28.597414 - step 6 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 10:55:28.597414 - step 7 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 11:05:28.597414 - step 8 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 11:15:28.597414 - step 9 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 11:25:28.597414 - step 10 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 11:35:28.597414 - step 11 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 11:45:28.597414 - step 12 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 11:55:28.597414 - step 13 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 12:05:28.597414 - step 14 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 12:15:28.597414 - step 15 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 12:25:28.597414 - step 16 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 12:35:28.597414 - step 17 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 12:45:28.597414 - step 18 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 12:55:28.597414 - step 19 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 13:05:28.597414 - step 20 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 13:15:28.597414 - step 21 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 13:25:28.597414 - step 22 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 13:35:28.597414 - step 23 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 13:45:28.597414 - step 24 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 13:55:28.597414 - step 25 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 14:05:28.597414 - step 26 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 14:15:28.597414 - step 27 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 14:25:28.597414 - step 28 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 14:35:28.597414 - step 29 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 14:45:28.597414 - step 30 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 14:55:28.597414 - step 31 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 15:05:28.597414 - step 32 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 15:15:28.597414 - step 33 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 15:25:28.597414 - step 34 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 15:35:28.597414 - step 35 of 36 - 50 active elements (0 deactivated)
09:55:33 INFO opendrift:2096: 2025-06-26 15:45:28.597414 - 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()
09:55:34 INFO opendrift:4607: Saving animation to /root/project/docs/source/gallery/animations/example_2d_0.gif...
09:55:39 INFO opendrift:3265: Time to make animation: 0:00:05.552605

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