Note
Go to the end to download the full example code.
Drift at different depths
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
17:01:52 INFO opendrift:569: OpenDriftSimulation initialised (version 1.14.11 / v1.14.12-66-g07283eb)
Using live data from Thredds
o.add_readers_from_list([
'https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be'])
Adding some diffusion
o.set_config('environment:constant:horizontal_diffusivity', 10) # m2/s
Seed 1000 elements at random depths
z = -np.random.rand(2000)*50
o.seed_elements(lon=4.8, lat=60.0, z=z, radius=0, number=2000,
time=datetime.now())
print(o)
17:01:52 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
17:01:59 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
17:01:59 INFO opendrift.models.basemodel.environment:230: x_sea_water_velocity: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: y_sea_water_velocity: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: sea_surface_height: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: upward_sea_water_velocity: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: ocean_vertical_diffusivity: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: ocean_mixed_layer_thickness: 50.000000
17:01:59 INFO opendrift.models.basemodel.environment:230: sea_floor_depth_below_sea_level: 10000.000000
===========================
Model: OceanDrift (OpenDrift version 1.14.11)
0 active Lagrangian3DArray particles (0 deactivated, 2000 scheduled)
-------------------
Environment variables:
-----
horizontal_diffusivity
1) constant_reader
-----
land_binary_mask
1) global_landmask
-----
Readers not added for the following variables:
ocean_mixed_layer_thickness
ocean_vertical_diffusivity
sea_floor_depth_below_sea_level
sea_surface_height
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
upward_sea_water_velocity
x_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
---
Lazy readers:
LazyReader: https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be
Discarded readers:
===========================
Running model
o.run(duration=timedelta(hours=24), time_step=1800)
17:01:59 INFO opendrift:1911: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
17:01:59 INFO opendrift:1911: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
17:01:59 INFO opendrift:1922: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
17:01:59 INFO opendrift:1922: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
17:01:59 INFO opendrift:1930: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
17:01:59 INFO opendrift:958: Using existing reader for land_binary_mask to move elements to ocean
17:01:59 INFO opendrift:990: All points are in ocean
17:01:59 INFO opendrift:2238: 2026-10-26 17:01:52.668450 - step 1 of 48 - 2000 active elements (0 deactivated)
17:01:59 INFO opendrift.readers:67: Opening file with xr.open_dataset
17:02:04 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
17:02:04 INFO opendrift.readers.basereader:175: Variable x_sea_water_velocity will be rotated from eastward_sea_water_velocity
17:02:04 INFO opendrift.readers.basereader:175: Variable y_sea_water_velocity will be rotated from northward_sea_water_velocity
17:02:04 INFO opendrift.readers.basereader:175: Variable x_wind will be rotated from eastward_wind
17:02:04 INFO opendrift.readers.basereader:175: Variable y_wind will be rotated from northward_wind
17:02:09 INFO opendrift:2238: 2026-10-26 17:31:52.668450 - step 2 of 48 - 2000 active elements (0 deactivated)
17:02:09 INFO opendrift:2238: 2026-10-26 18:01:52.668450 - step 3 of 48 - 2000 active elements (0 deactivated)
17:02:11 INFO opendrift:2238: 2026-10-26 18:31:52.668450 - step 4 of 48 - 2000 active elements (0 deactivated)
17:02:12 INFO opendrift:2238: 2026-10-26 19:01:52.668450 - step 5 of 48 - 2000 active elements (0 deactivated)
17:02:14 INFO opendrift:2238: 2026-10-26 19:31:52.668450 - step 6 of 48 - 2000 active elements (0 deactivated)
17:02:14 INFO opendrift:2238: 2026-10-26 20:01:52.668450 - step 7 of 48 - 2000 active elements (0 deactivated)
17:02:17 INFO opendrift:2238: 2026-10-26 20:31:52.668450 - step 8 of 48 - 2000 active elements (0 deactivated)
17:02:17 INFO opendrift:2238: 2026-10-26 21:01:52.668450 - step 9 of 48 - 2000 active elements (0 deactivated)
17:02:20 INFO opendrift:2238: 2026-10-26 21:31:52.668450 - step 10 of 48 - 2000 active elements (0 deactivated)
17:02:20 INFO opendrift:2238: 2026-10-26 22:01:52.668450 - step 11 of 48 - 2000 active elements (0 deactivated)
17:02:22 INFO opendrift:2238: 2026-10-26 22:31:52.668450 - step 12 of 48 - 2000 active elements (0 deactivated)
17:02:22 INFO opendrift:2238: 2026-10-26 23:01:52.668450 - step 13 of 48 - 2000 active elements (0 deactivated)
17:02:24 INFO opendrift:2238: 2026-10-26 23:31:52.668450 - step 14 of 48 - 2000 active elements (0 deactivated)
17:02:24 INFO opendrift:2238: 2026-10-27 00:01:52.668450 - step 15 of 48 - 2000 active elements (0 deactivated)
17:02:27 INFO opendrift:2238: 2026-10-27 00:31:52.668450 - step 16 of 48 - 2000 active elements (0 deactivated)
17:02:27 INFO opendrift:2238: 2026-10-27 01:01:52.668450 - step 17 of 48 - 2000 active elements (0 deactivated)
17:02:30 INFO opendrift:2238: 2026-10-27 01:31:52.668450 - step 18 of 48 - 2000 active elements (0 deactivated)
17:02:30 INFO opendrift:2238: 2026-10-27 02:01:52.668450 - step 19 of 48 - 2000 active elements (0 deactivated)
17:02:32 INFO opendrift:2238: 2026-10-27 02:31:52.668450 - step 20 of 48 - 2000 active elements (0 deactivated)
17:02:32 INFO opendrift:2238: 2026-10-27 03:01:52.668450 - step 21 of 48 - 2000 active elements (0 deactivated)
17:02:35 INFO opendrift:2238: 2026-10-27 03:31:52.668450 - step 22 of 48 - 2000 active elements (0 deactivated)
17:02:35 INFO opendrift:2238: 2026-10-27 04:01:52.668450 - step 23 of 48 - 2000 active elements (0 deactivated)
17:02:37 INFO opendrift:2238: 2026-10-27 04:31:52.668450 - step 24 of 48 - 2000 active elements (0 deactivated)
17:02:37 INFO opendrift:2238: 2026-10-27 05:01:52.668450 - step 25 of 48 - 2000 active elements (0 deactivated)
17:02:43 INFO opendrift:2238: 2026-10-27 05:31:52.668450 - step 26 of 48 - 2000 active elements (0 deactivated)
17:02:43 INFO opendrift:2238: 2026-10-27 06:01:52.668450 - step 27 of 48 - 2000 active elements (0 deactivated)
17:02:45 INFO opendrift:2238: 2026-10-27 06:31:52.668450 - step 28 of 48 - 2000 active elements (0 deactivated)
17:02:45 INFO opendrift:2238: 2026-10-27 07:01:52.668450 - step 29 of 48 - 2000 active elements (0 deactivated)
17:02:48 INFO opendrift:2238: 2026-10-27 07:31:52.668450 - step 30 of 48 - 2000 active elements (0 deactivated)
17:02:49 INFO opendrift:2238: 2026-10-27 08:01:52.668450 - step 31 of 48 - 2000 active elements (0 deactivated)
17:02:52 INFO opendrift:2238: 2026-10-27 08:31:52.668450 - step 32 of 48 - 2000 active elements (0 deactivated)
17:02:52 INFO opendrift:2238: 2026-10-27 09:01:52.668450 - step 33 of 48 - 2000 active elements (0 deactivated)
17:02:55 INFO opendrift:2238: 2026-10-27 09:31:52.668450 - step 34 of 48 - 2000 active elements (0 deactivated)
17:02:55 INFO opendrift:2238: 2026-10-27 10:01:52.668450 - step 35 of 48 - 2000 active elements (0 deactivated)
17:02:56 INFO opendrift:2238: 2026-10-27 10:31:52.668450 - step 36 of 48 - 1998 active elements (2 deactivated)
17:02:56 INFO opendrift:2238: 2026-10-27 11:01:52.668450 - step 37 of 48 - 1996 active elements (4 deactivated)
17:02:59 INFO opendrift:2238: 2026-10-27 11:31:52.668450 - step 38 of 48 - 1996 active elements (4 deactivated)
17:02:59 INFO opendrift:2238: 2026-10-27 12:01:52.668450 - step 39 of 48 - 1996 active elements (4 deactivated)
17:03:04 INFO opendrift:2238: 2026-10-27 12:31:52.668450 - step 40 of 48 - 1995 active elements (5 deactivated)
17:03:04 INFO opendrift:2238: 2026-10-27 13:01:52.668450 - step 41 of 48 - 1989 active elements (11 deactivated)
17:03:06 INFO opendrift:2238: 2026-10-27 13:31:52.668450 - step 42 of 48 - 1987 active elements (13 deactivated)
17:03:06 INFO opendrift:2238: 2026-10-27 14:01:52.668450 - step 43 of 48 - 1981 active elements (19 deactivated)
17:03:07 INFO opendrift:2238: 2026-10-27 14:31:52.668450 - step 44 of 48 - 1976 active elements (24 deactivated)
17:03:07 INFO opendrift:2238: 2026-10-27 15:01:52.668450 - step 45 of 48 - 1964 active elements (36 deactivated)
17:03:09 INFO opendrift:2238: 2026-10-27 15:31:52.668450 - step 46 of 48 - 1948 active elements (52 deactivated)
17:03:09 INFO opendrift:2238: 2026-10-27 16:01:52.668450 - step 47 of 48 - 1937 active elements (63 deactivated)
17:03:12 INFO opendrift:2238: 2026-10-27 16:31:52.668450 - step 48 of 48 - 1930 active elements (70 deactivated)
Plot results with lines and particles colored by depth
print(o)
o.plot(linecolor='z', buffer=.1, show_elements=False)
o.animation(color='z', buffer=.1)

===========================
--------------------
Reader performance:
--------------------
constant_reader
0:00:00.0 total
0:00:00.0 preparing
0:00:00.0 reading
0:00:00.0 masking
--------------------
global_landmask
0:00:00.0 total
0:00:00.0 preparing
0:00:00.0 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be
0:01:06.5 total
0:00:00.0 preparing
0:01:06.0 reading
0:00:01.0 interpolation
0:00:00.0 interpolation_time
0:00:00.4 rotating vectors
0:00:00.0 masking
--------------------
Performance:
1:20.4 total time
6.5 configuration
0.1 preparing main loop
0.0 moving elements to ocean
1:13.7 main loop
0.1 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.14.11)
1903 active Lagrangian3DArray particles (97 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
horizontal_diffusivity
1) constant_reader
-----
land_binary_mask
1) global_landmask
-----
sea_floor_depth_below_sea_level
sea_surface_height
upward_sea_water_velocity
x_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
1) https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be
-----
Readers not added for the following variables:
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
Discarded readers:
Time:
Start: 2026-10-26 17:01:52.668450 UTC
Present: 2026-10-27 17:01:52.668450 UTC
Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
Output steps: 49 * 0:30:00
===========================
17:04:05 INFO opendrift:4889: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
17:04:18 INFO opendrift:3297: Time to make animation: 0:00:14.767810
Total running time of the script: (2 minutes 38.515 seconds)