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
14:39:50 INFO opendrift:576: OpenDriftSimulation initialised (version 1.14.6 / v1.14.6-9-geaa6ee2)
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('drift: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)
14:39:50 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
14:39:55 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
14:39:55 INFO opendrift.models.basemodel.environment:230: x_sea_water_velocity: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: y_sea_water_velocity: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: sea_surface_height: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: upward_sea_water_velocity: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: ocean_vertical_diffusivity: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: ocean_mixed_layer_thickness: 50.000000
14:39:55 INFO opendrift.models.basemodel.environment:230: sea_floor_depth_below_sea_level: 10000.000000
===========================
Model: OceanDrift (OpenDrift version 1.14.6)
0 active Lagrangian3DArray particles (0 deactivated, 2000 scheduled)
-------------------
Environment variables:
-----
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)
14:39:55 INFO opendrift:1794: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
14:39:55 INFO opendrift:1794: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
14:39:55 INFO opendrift:1805: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:39:55 INFO opendrift:1805: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:39:55 INFO opendrift:1813: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
14:39:55 INFO opendrift:952: Using existing reader for land_binary_mask to move elements to ocean
14:39:55 INFO opendrift:982: All points are in ocean
14:39:55 INFO opendrift:2101: 2025-11-10 14:39:50.613917 - step 1 of 48 - 2000 active elements (0 deactivated)
14:39:55 INFO opendrift.readers:63: Opening file with xr.open_dataset
14:39:56 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
14:39:56 INFO opendrift.readers.basereader:176: Variable x_sea_water_velocity will be rotated from eastward_sea_water_velocity
14:39:56 INFO opendrift.readers.basereader:176: Variable y_sea_water_velocity will be rotated from northward_sea_water_velocity
14:39:56 INFO opendrift.readers.basereader:176: Variable x_wind will be rotated from eastward_wind
14:39:56 INFO opendrift.readers.basereader:176: Variable y_wind will be rotated from northward_wind
14:39:59 INFO opendrift:2101: 2025-11-10 15:09:50.613917 - step 2 of 48 - 2000 active elements (0 deactivated)
14:40:00 INFO opendrift:2101: 2025-11-10 15:39:50.613917 - step 3 of 48 - 2000 active elements (0 deactivated)
14:40:00 INFO opendrift:2101: 2025-11-10 16:09:50.613917 - step 4 of 48 - 2000 active elements (0 deactivated)
14:40:01 INFO opendrift:2101: 2025-11-10 16:39:50.613917 - step 5 of 48 - 2000 active elements (0 deactivated)
14:40:02 INFO opendrift:2101: 2025-11-10 17:09:50.613917 - step 6 of 48 - 2000 active elements (0 deactivated)
14:40:03 INFO opendrift:2101: 2025-11-10 17:39:50.613917 - step 7 of 48 - 2000 active elements (0 deactivated)
14:40:03 INFO opendrift:2101: 2025-11-10 18:09:50.613917 - step 8 of 48 - 2000 active elements (0 deactivated)
14:40:04 INFO opendrift:2101: 2025-11-10 18:39:50.613917 - step 9 of 48 - 2000 active elements (0 deactivated)
14:40:04 INFO opendrift:2101: 2025-11-10 19:09:50.613917 - step 10 of 48 - 2000 active elements (0 deactivated)
14:40:05 INFO opendrift:2101: 2025-11-10 19:39:50.613917 - step 11 of 48 - 2000 active elements (0 deactivated)
14:40:05 INFO opendrift:2101: 2025-11-10 20:09:50.613917 - step 12 of 48 - 2000 active elements (0 deactivated)
14:40:07 INFO opendrift:2101: 2025-11-10 20:39:50.613917 - step 13 of 48 - 2000 active elements (0 deactivated)
14:40:07 INFO opendrift:2101: 2025-11-10 21:09:50.613917 - step 14 of 48 - 2000 active elements (0 deactivated)
14:40:08 INFO opendrift:2101: 2025-11-10 21:39:50.613917 - step 15 of 48 - 2000 active elements (0 deactivated)
14:40:08 INFO opendrift:2101: 2025-11-10 22:09:50.613917 - step 16 of 48 - 2000 active elements (0 deactivated)
14:40:10 INFO opendrift:2101: 2025-11-10 22:39:50.613917 - step 17 of 48 - 2000 active elements (0 deactivated)
14:40:10 INFO opendrift:2101: 2025-11-10 23:09:50.613917 - step 18 of 48 - 2000 active elements (0 deactivated)
14:40:11 INFO opendrift:2101: 2025-11-10 23:39:50.613917 - step 19 of 48 - 2000 active elements (0 deactivated)
14:40:11 INFO opendrift:2101: 2025-11-11 00:09:50.613917 - step 20 of 48 - 2000 active elements (0 deactivated)
14:40:14 INFO opendrift:2101: 2025-11-11 00:39:50.613917 - step 21 of 48 - 2000 active elements (0 deactivated)
14:40:14 INFO opendrift:2101: 2025-11-11 01:09:50.613917 - step 22 of 48 - 2000 active elements (0 deactivated)
14:40:16 INFO opendrift:2101: 2025-11-11 01:39:50.613917 - step 23 of 48 - 2000 active elements (0 deactivated)
14:40:16 INFO opendrift:2101: 2025-11-11 02:09:50.613917 - step 24 of 48 - 2000 active elements (0 deactivated)
14:40:18 INFO opendrift:2101: 2025-11-11 02:39:50.613917 - step 25 of 48 - 2000 active elements (0 deactivated)
14:40:18 INFO opendrift:2101: 2025-11-11 03:09:50.613917 - step 26 of 48 - 2000 active elements (0 deactivated)
14:40:19 INFO opendrift:2101: 2025-11-11 03:39:50.613917 - step 27 of 48 - 2000 active elements (0 deactivated)
14:40:19 INFO opendrift:2101: 2025-11-11 04:09:50.613917 - step 28 of 48 - 2000 active elements (0 deactivated)
14:40:22 INFO opendrift:2101: 2025-11-11 04:39:50.613917 - step 29 of 48 - 2000 active elements (0 deactivated)
14:40:24 INFO opendrift:2101: 2025-11-11 05:09:50.613917 - step 30 of 48 - 1999 active elements (1 deactivated)
14:40:26 INFO opendrift:2101: 2025-11-11 05:39:50.613917 - step 31 of 48 - 1998 active elements (2 deactivated)
14:40:26 INFO opendrift:2101: 2025-11-11 06:09:50.613917 - step 32 of 48 - 1995 active elements (5 deactivated)
14:40:27 INFO opendrift:2101: 2025-11-11 06:39:50.613917 - step 33 of 48 - 1989 active elements (11 deactivated)
14:40:27 INFO opendrift:2101: 2025-11-11 07:09:50.613917 - step 34 of 48 - 1984 active elements (16 deactivated)
14:40:29 INFO opendrift:2101: 2025-11-11 07:39:50.613917 - step 35 of 48 - 1976 active elements (24 deactivated)
14:40:29 INFO opendrift:2101: 2025-11-11 08:09:50.613917 - step 36 of 48 - 1974 active elements (26 deactivated)
14:40:31 INFO opendrift:2101: 2025-11-11 08:39:50.613917 - step 37 of 48 - 1964 active elements (36 deactivated)
14:40:31 INFO opendrift:2101: 2025-11-11 09:09:50.613917 - step 38 of 48 - 1958 active elements (42 deactivated)
14:40:32 INFO opendrift:2101: 2025-11-11 09:39:50.613917 - step 39 of 48 - 1949 active elements (51 deactivated)
14:40:32 INFO opendrift:2101: 2025-11-11 10:09:50.613917 - step 40 of 48 - 1938 active elements (62 deactivated)
14:40:34 INFO opendrift:2101: 2025-11-11 10:39:50.613917 - step 41 of 48 - 1925 active elements (75 deactivated)
14:40:34 INFO opendrift:2101: 2025-11-11 11:09:50.613917 - step 42 of 48 - 1915 active elements (85 deactivated)
14:40:36 INFO opendrift:2101: 2025-11-11 11:39:50.613917 - step 43 of 48 - 1905 active elements (95 deactivated)
14:40:36 INFO opendrift:2101: 2025-11-11 12:09:50.613917 - step 44 of 48 - 1892 active elements (108 deactivated)
14:40:38 INFO opendrift:2101: 2025-11-11 12:39:50.613917 - step 45 of 48 - 1885 active elements (115 deactivated)
14:40:38 INFO opendrift:2101: 2025-11-11 13:09:50.613917 - step 46 of 48 - 1875 active elements (125 deactivated)
14:40:40 INFO opendrift:2101: 2025-11-11 13:39:50.613917 - step 47 of 48 - 1869 active elements (131 deactivated)
14:40:40 INFO opendrift:2101: 2025-11-11 14:09:50.613917 - step 48 of 48 - 1867 active elements (133 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:
--------------------
global_landmask
0:00:01.6 total
0:00:00.0 preparing
0:00:01.6 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be
0:00:39.6 total
0:00:00.0 preparing
0:00:39.1 reading
0:00:01.0 interpolation
0:00:00.0 interpolation_time
0:00:00.4 rotating vectors
0:00:00.0 masking
--------------------
Performance:
51.2 total time
4.8 configuration
0.0 preparing main loop
0.0 moving elements to ocean
46.4 main loop
0.1 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.14.6)
1862 active Lagrangian3DArray particles (138 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
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: 2025-11-10 14:39:50.613917 UTC
Present: 2025-11-11 14:39:50.613917 UTC
Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
Output steps: 49 * 0:30:00
===========================
14:41:42 INFO opendrift:4636: Saving animation to /root/project/docs/source/gallery/animations/example_depth_0.gif...
14:42:14 INFO opendrift:3071: Time to make animation: 0:00:33.815451
Total running time of the script: (2 minutes 34.214 seconds)