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
08:23:57 INFO    opendrift:568: OpenDriftSimulation initialised (version 1.14.9 / v1.14.9-9-gcde0dcf)

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()
08:23:57 INFO    opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
08:24:02 INFO    opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
08:24:02 INFO    opendrift.models.basemodel.environment:230:    x_sea_water_velocity: 0.100000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    y_sea_water_velocity: 0.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    sea_surface_height: 0.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    x_wind: 7.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    y_wind: 0.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    upward_sea_water_velocity: 0.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    ocean_vertical_diffusivity: 0.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    horizontal_diffusivity: 0.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_significant_height: 2.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_x_velocity: 0.200000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    ocean_mixed_layer_thickness: 50.000000
08:24:02 INFO    opendrift.models.basemodel.environment:230:    sea_floor_depth_below_sea_level: 10000.000000

Running model for 6 hours

o.run(duration=timedelta(hours=6), time_step=600)
08:24:02 INFO    opendrift:1828: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
08:24:02 INFO    opendrift:1828: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
08:24:02 INFO    opendrift:1839: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
08:24:02 INFO    opendrift:1839: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
08:24:02 INFO    opendrift:1847: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
08:24:02 INFO    opendrift:947: Using existing reader for land_binary_mask to move elements to ocean
08:24:02 INFO    opendrift:978: All points are in ocean
08:24:02 INFO    opendrift:2136: 2026-03-25 08:23:57.591089 - step 1 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 08:33:57.591089 - step 2 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 08:43:57.591089 - step 3 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 08:53:57.591089 - step 4 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 09:03:57.591089 - step 5 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 09:13:57.591089 - step 6 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 09:23:57.591089 - step 7 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 09:33:57.591089 - step 8 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 09:43:57.591089 - step 9 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 09:53:57.591089 - step 10 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 10:03:57.591089 - step 11 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 10:13:57.591089 - step 12 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 10:23:57.591089 - step 13 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 10:33:57.591089 - step 14 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 10:43:57.591089 - step 15 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 10:53:57.591089 - step 16 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 11:03:57.591089 - step 17 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 11:13:57.591089 - step 18 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 11:23:57.591089 - step 19 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 11:33:57.591089 - step 20 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 11:43:57.591089 - step 21 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 11:53:57.591089 - step 22 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 12:03:57.591089 - step 23 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 12:13:57.591089 - step 24 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 12:23:57.591089 - step 25 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 12:33:57.591089 - step 26 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 12:43:57.591089 - step 27 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 12:53:57.591089 - step 28 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 13:03:57.591089 - step 29 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 13:13:57.591089 - step 30 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 13:23:57.591089 - step 31 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 13:33:57.591089 - step 32 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 13:43:57.591089 - step 33 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 13:53:57.591089 - step 34 of 36 - 50 active elements (0 deactivated)
08:24:02 INFO    opendrift:2136: 2026-03-25 14:03:57.591089 - step 35 of 36 - 50 active elements (0 deactivated)
08:24:03 INFO    opendrift:2136: 2026-03-25 14:13:57.591089 - step 36 of 36 - 50 active elements (0 deactivated)
<xarray.Dataset> Size: 163kB
Dimensions:                                   (trajectory: 50, time: 37)
Coordinates:
  * trajectory                                (trajectory) int64 400B 0 1 ... 49
  * time                                      (time) datetime64[ns] 296B 2026...
Data variables: (12/22)
    status                                    (trajectory, time) float32 7kB ...
    moving                                    (trajectory, time) float32 7kB ...
    age_seconds                               (trajectory, time) float32 7kB ...
    origin_marker                             (trajectory, time) float32 7kB ...
    lon                                       (trajectory, time) float32 7kB ...
    lat                                       (trajectory, time) float32 7kB ...
    ...                                        ...
    horizontal_diffusivity                    (trajectory, time) float32 7kB ...
    sea_surface_wave_significant_height       (trajectory, time) float32 7kB ...
    sea_surface_wave_stokes_drift_x_velocity  (trajectory, time) float32 7kB ...
    sea_surface_wave_stokes_drift_y_velocity  (trajectory, time) float32 7kB ...
    sea_floor_depth_below_sea_level           (trajectory, time) float32 7kB ...
    land_binary_mask                          (trajectory, time) float32 7kB ...
Attributes: (12/121)
    Conventions:                                                           CF...
    standard_name_vocabulary:                                              CF...
    featureType:                                                           tr...
    title:                                                                 Op...
    summary:                                                               Ou...
    keywords:                                                              tr...
    ...                                                                    ...
    geospatial_lon_units:                                                  de...
    geospatial_lon_resolution:                                             point
    runtime:                                                               0:...
    geospatial_vertical_min:                                               -5.0
    geospatial_vertical_max:                                               -0.0
    geospatial_vertical_positive:                                          up


To check that z is really kept constant for all particles

o.plot_property('z')
z

Vertical profile of advection. Note the decaying importance of Stokes drift, and the additional windage of the element at surface

o.animation_profile()
08:24:03 INFO    opendrift:4697: Saving animation to /root/project/docs/source/gallery/animations/example_2d_0.gif...
08:24:09 INFO    opendrift:3336: Time to make animation: 0:00:05.864038
../_images/example_2d_0.gif

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

Gallery generated by Sphinx-Gallery