Note
Go to the end to download the full example code.
Reader boundary
Seeding elements around the border of a ocean model domain (NorKyst800) to demonstrate autmatic transition back and forth with another model covering a larger domain (Topaz).
from datetime import datetime
import numpy as np
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.models.oceandrift import OceanDrift
o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
# Norkyst
reader_norkyst = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be')
# Topaz
reader_topaz = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml')
o.add_reader([reader_norkyst, reader_topaz])
o.set_config('environment:fallback:land_binary_mask', 0)
o.set_config('drift:vertical_mixing', False)
13:35:18 INFO opendrift:579: OpenDriftSimulation initialised (version 1.14.11 / v1.14.12-91-g231396a)
13:35:18 INFO opendrift.readers:67: Opening file with xr.open_dataset
13:35:30 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
13:35:30 INFO opendrift.readers.basereader:175: Variable x_sea_water_velocity will be rotated from eastward_sea_water_velocity
13:35:30 INFO opendrift.readers.basereader:175: Variable y_sea_water_velocity will be rotated from northward_sea_water_velocity
13:35:30 INFO opendrift.readers.basereader:175: Variable x_wind will be rotated from eastward_wind
13:35:30 INFO opendrift.readers.basereader:175: Variable y_wind will be rotated from northward_wind
13:35:30 INFO opendrift.readers:67: Opening file with xr.open_dataset
13:35:39 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
Seeding some particles
lons = np.linspace(5, 8, 50)
lats = np.linspace(69.8, 70.8, 50)
lons, lats = np.meshgrid(lons, lats)
Seed oil elements at defined position and time
o.seed_elements(lons, lats, radius=0, number=2500,
time=datetime.now())
13:35:39 INFO opendrift.models.basemodel.environment:204: Adding a global landmask from GSHHG
13:35:47 INFO opendrift.models.basemodel.environment:238: Fallback values will be used for the following variables which have no readers:
13:35:47 INFO opendrift.models.basemodel.environment:241: horizontal_diffusivity: 0.000000
13:35:47 INFO opendrift.models.basemodel.environment:241: sea_surface_wave_significant_height: 0.000000
13:35:47 INFO opendrift.models.basemodel.environment:241: sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:35:47 INFO opendrift.models.basemodel.environment:241: sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:35:47 INFO opendrift.models.basemodel.environment:241: ocean_mixed_layer_thickness: 50.000000
Running model
o.run(steps=16*4, time_step=900, time_step_output=1800)
13:35:47 INFO opendrift:1921: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
13:35:47 INFO opendrift:1921: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
13:35:47 INFO opendrift:1932: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:35:47 INFO opendrift:1932: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:35:47 INFO opendrift:1940: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
13:35:47 INFO opendrift:968: Using existing reader for land_binary_mask to move elements to ocean
13:35:47 INFO opendrift:1000: All points are in ocean
13:35:47 INFO opendrift:2248: 2026-11-17 13:35:39.604236 - step 1 of 64 - 2500 active elements (0 deactivated)
13:36:33 INFO opendrift:2248: 2026-11-17 13:50:39.604236 - step 2 of 64 - 2500 active elements (0 deactivated)
13:36:37 INFO opendrift:2248: 2026-11-17 14:05:39.604236 - step 3 of 64 - 2500 active elements (0 deactivated)
13:36:57 INFO opendrift:2248: 2026-11-17 14:20:39.604236 - step 4 of 64 - 2500 active elements (0 deactivated)
13:36:58 INFO opendrift:2248: 2026-11-17 14:35:39.604236 - step 5 of 64 - 2500 active elements (0 deactivated)
13:37:00 INFO opendrift:2248: 2026-11-17 14:50:39.604236 - step 6 of 64 - 2500 active elements (0 deactivated)
13:37:02 INFO opendrift:2248: 2026-11-17 15:05:39.604236 - step 7 of 64 - 2500 active elements (0 deactivated)
13:37:21 INFO opendrift:2248: 2026-11-17 15:20:39.604236 - step 8 of 64 - 2500 active elements (0 deactivated)
13:37:23 INFO opendrift:2248: 2026-11-17 15:35:39.604236 - step 9 of 64 - 2500 active elements (0 deactivated)
13:37:25 INFO opendrift:2248: 2026-11-17 15:50:39.604236 - step 10 of 64 - 2500 active elements (0 deactivated)
13:37:27 INFO opendrift:2248: 2026-11-17 16:05:39.604236 - step 11 of 64 - 2500 active elements (0 deactivated)
13:37:45 INFO opendrift:2248: 2026-11-17 16:20:39.604236 - step 12 of 64 - 2500 active elements (0 deactivated)
13:37:46 INFO opendrift:2248: 2026-11-17 16:35:39.604236 - step 13 of 64 - 2500 active elements (0 deactivated)
13:37:49 INFO opendrift:2248: 2026-11-17 16:50:39.604236 - step 14 of 64 - 2500 active elements (0 deactivated)
13:37:51 INFO opendrift:2248: 2026-11-17 17:05:39.604236 - step 15 of 64 - 2500 active elements (0 deactivated)
13:38:10 INFO opendrift:2248: 2026-11-17 17:20:39.604236 - step 16 of 64 - 2500 active elements (0 deactivated)
13:38:12 INFO opendrift:2248: 2026-11-17 17:35:39.604236 - step 17 of 64 - 2500 active elements (0 deactivated)
13:38:14 INFO opendrift:2248: 2026-11-17 17:50:39.604236 - step 18 of 64 - 2500 active elements (0 deactivated)
13:38:16 INFO opendrift:2248: 2026-11-17 18:05:39.604236 - step 19 of 64 - 2500 active elements (0 deactivated)
13:38:33 INFO opendrift:2248: 2026-11-17 18:20:39.604236 - step 20 of 64 - 2500 active elements (0 deactivated)
13:38:35 INFO opendrift:2248: 2026-11-17 18:35:39.604236 - step 21 of 64 - 2500 active elements (0 deactivated)
13:38:37 INFO opendrift:2248: 2026-11-17 18:50:39.604236 - step 22 of 64 - 2500 active elements (0 deactivated)
13:38:39 INFO opendrift:2248: 2026-11-17 19:05:39.604236 - step 23 of 64 - 2500 active elements (0 deactivated)
13:38:53 INFO opendrift:2248: 2026-11-17 19:20:39.604236 - step 24 of 64 - 2500 active elements (0 deactivated)
13:38:54 INFO opendrift:2248: 2026-11-17 19:35:39.604236 - step 25 of 64 - 2500 active elements (0 deactivated)
13:38:56 INFO opendrift:2248: 2026-11-17 19:50:39.604236 - step 26 of 64 - 2500 active elements (0 deactivated)
13:38:58 INFO opendrift:2248: 2026-11-17 20:05:39.604236 - step 27 of 64 - 2500 active elements (0 deactivated)
13:39:14 INFO opendrift:2248: 2026-11-17 20:20:39.604236 - step 28 of 64 - 2500 active elements (0 deactivated)
13:39:16 INFO opendrift:2248: 2026-11-17 20:35:39.604236 - step 29 of 64 - 2500 active elements (0 deactivated)
13:39:18 INFO opendrift:2248: 2026-11-17 20:50:39.604236 - step 30 of 64 - 2500 active elements (0 deactivated)
13:39:20 INFO opendrift:2248: 2026-11-17 21:05:39.604236 - step 31 of 64 - 2500 active elements (0 deactivated)
13:39:34 INFO opendrift:2248: 2026-11-17 21:20:39.604236 - step 32 of 64 - 2500 active elements (0 deactivated)
13:39:36 INFO opendrift:2248: 2026-11-17 21:35:39.604236 - step 33 of 64 - 2500 active elements (0 deactivated)
13:39:38 INFO opendrift:2248: 2026-11-17 21:50:39.604236 - step 34 of 64 - 2500 active elements (0 deactivated)
13:39:40 INFO opendrift:2248: 2026-11-17 22:05:39.604236 - step 35 of 64 - 2500 active elements (0 deactivated)
13:39:54 INFO opendrift:2248: 2026-11-17 22:20:39.604236 - step 36 of 64 - 2500 active elements (0 deactivated)
13:39:57 INFO opendrift:2248: 2026-11-17 22:35:39.604236 - step 37 of 64 - 2500 active elements (0 deactivated)
13:39:59 INFO opendrift:2248: 2026-11-17 22:50:39.604236 - step 38 of 64 - 2500 active elements (0 deactivated)
13:40:01 INFO opendrift:2248: 2026-11-17 23:05:39.604236 - step 39 of 64 - 2500 active elements (0 deactivated)
13:40:21 INFO opendrift:2248: 2026-11-17 23:20:39.604236 - step 40 of 64 - 2500 active elements (0 deactivated)
13:40:23 INFO opendrift:2248: 2026-11-17 23:35:39.604236 - step 41 of 64 - 2500 active elements (0 deactivated)
13:40:26 INFO opendrift:2248: 2026-11-17 23:50:39.604236 - step 42 of 64 - 2500 active elements (0 deactivated)
13:40:28 INFO opendrift:2248: 2026-11-18 00:05:39.604236 - step 43 of 64 - 2500 active elements (0 deactivated)
13:40:47 INFO opendrift:2248: 2026-11-18 00:20:39.604236 - step 44 of 64 - 2500 active elements (0 deactivated)
13:40:49 INFO opendrift:2248: 2026-11-18 00:35:39.604236 - step 45 of 64 - 2500 active elements (0 deactivated)
13:40:51 INFO opendrift:2248: 2026-11-18 00:50:39.604236 - step 46 of 64 - 2500 active elements (0 deactivated)
13:40:54 INFO opendrift:2248: 2026-11-18 01:05:39.604236 - step 47 of 64 - 2500 active elements (0 deactivated)
13:41:24 INFO opendrift:2248: 2026-11-18 01:20:39.604236 - step 48 of 64 - 2500 active elements (0 deactivated)
13:41:27 INFO opendrift:2248: 2026-11-18 01:35:39.604236 - step 49 of 64 - 2500 active elements (0 deactivated)
13:41:29 INFO opendrift:2248: 2026-11-18 01:50:39.604236 - step 50 of 64 - 2500 active elements (0 deactivated)
13:41:30 INFO opendrift:2248: 2026-11-18 02:05:39.604236 - step 51 of 64 - 2500 active elements (0 deactivated)
13:41:46 INFO opendrift:2248: 2026-11-18 02:20:39.604236 - step 52 of 64 - 2500 active elements (0 deactivated)
13:41:48 INFO opendrift:2248: 2026-11-18 02:35:39.604236 - step 53 of 64 - 2500 active elements (0 deactivated)
13:41:50 INFO opendrift:2248: 2026-11-18 02:50:39.604236 - step 54 of 64 - 2500 active elements (0 deactivated)
13:41:52 INFO opendrift:2248: 2026-11-18 03:05:39.604236 - step 55 of 64 - 2500 active elements (0 deactivated)
13:42:10 INFO opendrift:2248: 2026-11-18 03:20:39.604236 - step 56 of 64 - 2500 active elements (0 deactivated)
13:42:12 INFO opendrift:2248: 2026-11-18 03:35:39.604236 - step 57 of 64 - 2500 active elements (0 deactivated)
13:42:16 INFO opendrift:2248: 2026-11-18 03:50:39.604236 - step 58 of 64 - 2500 active elements (0 deactivated)
13:42:19 INFO opendrift:2248: 2026-11-18 04:05:39.604236 - step 59 of 64 - 2500 active elements (0 deactivated)
13:42:35 INFO opendrift:2248: 2026-11-18 04:20:39.604236 - step 60 of 64 - 2500 active elements (0 deactivated)
13:42:37 INFO opendrift:2248: 2026-11-18 04:35:39.604236 - step 61 of 64 - 2500 active elements (0 deactivated)
13:42:39 INFO opendrift:2248: 2026-11-18 04:50:39.604236 - step 62 of 64 - 2500 active elements (0 deactivated)
13:42:41 INFO opendrift:2248: 2026-11-18 05:05:39.604236 - step 63 of 64 - 2500 active elements (0 deactivated)
13:42:54 INFO opendrift:2248: 2026-11-18 05:20:39.604236 - step 64 of 64 - 2500 active elements (0 deactivated)
Print and plot results
print(o)
o.animation(fast=True)
===========================
--------------------
Reader performance:
--------------------
https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be
0:04:34.8 total
0:00:00.0 preparing
0:04:34.4 reading
0:00:00.3 interpolation
0:00:00.0 interpolation_time
0:00:00.3 rotating vectors
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
0:02:31.6 total
0:00:00.0 preparing
0:02:31.4 reading
0:00:00.0 interpolation
0:00:00.0 interpolation_time
0:00:00.1 rotating vectors
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
--------------------
Performance:
7:37.7 total time
28.9 configuration
0.1 preparing main loop
0.0 moving elements to ocean
7:08.6 main loop
0.2 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.14.11)
2500 active Lagrangian3DArray particles (0 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
sea_floor_depth_below_sea_level
sea_surface_height
x_sea_water_velocity
y_sea_water_velocity
1) https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be
2) https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
-----
upward_sea_water_velocity
x_wind
y_wind
1) https://thredds.met.no/thredds/dodsC/fou-hi/norkystv3_800m_m00_be
-----
land_binary_mask
1) global_landmask
-----
Readers not added for the following variables:
horizontal_diffusivity
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
Discarded readers:
Time:
Start: 2026-11-17 13:35:39.604236 UTC
Present: 2026-11-18 05:35:39.604236 UTC
Calculation steps: 64 * 0:15:00 - total time: 16:00:00
Output steps: 33 * 0:30:00
===========================
13:42:56 WARNING opendrift:2624: Plotting fast. This will make your plots less accurate.
13:42:57 INFO opendrift:4899: Saving animation to /root/project/docs/source/gallery/animations/example_reader_boundary_0.gif...
13:43:10 INFO opendrift:3307: Time to make animation: 0:00:14.587673
o.plot(fast=True)

13:43:10 WARNING opendrift:2624: Plotting fast. This will make your plots less accurate.
(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2026-11-17 13:35 to 2026-11-18 05:35 UTC (33 steps)'}>, <Figure size 931.16x1100 with 1 Axes>)
Total running time of the script: (8 minutes 7.693 seconds)