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)
16:22:24 INFO opendrift:576: OpenDriftSimulation initialised (version 1.14.8 / v1.14.8-15-ge839285)
16:22:24 INFO opendrift.readers:63: Opening file with xr.open_dataset
16:22:25 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
16:22:25 INFO opendrift.readers.basereader:178: Variable x_sea_water_velocity will be rotated from eastward_sea_water_velocity
16:22:25 INFO opendrift.readers.basereader:178: Variable y_sea_water_velocity will be rotated from northward_sea_water_velocity
16:22:25 INFO opendrift.readers.basereader:178: Variable x_wind will be rotated from eastward_wind
16:22:25 INFO opendrift.readers.basereader:178: Variable y_wind will be rotated from northward_wind
16:22:25 INFO opendrift.readers:63: Opening file with xr.open_dataset
16:22:28 INFO opendrift.readers.reader_netCDF_CF_generic:332: 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())
16:22:28 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
16:22:33 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
16:22:33 INFO opendrift.models.basemodel.environment:230: horizontal_diffusivity: 0.000000
16:22:33 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000
16:22:33 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000
16:22:33 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000
16:22:33 INFO opendrift.models.basemodel.environment:230: ocean_mixed_layer_thickness: 50.000000
Running model
o.run(steps=16*4, time_step=900, time_step_output=1800)
16:22:33 INFO opendrift:1836: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
16:22:33 INFO opendrift:1836: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
16:22:33 INFO opendrift:1847: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
16:22:33 INFO opendrift:1847: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
16:22:33 INFO opendrift:1855: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
16:22:33 INFO opendrift:955: Using existing reader for land_binary_mask to move elements to ocean
16:22:33 INFO opendrift:986: All points are in ocean
16:22:33 INFO opendrift:2144: 2026-02-16 16:22:28.744700 - step 1 of 64 - 2500 active elements (0 deactivated)
16:22:37 INFO opendrift:2144: 2026-02-16 16:37:28.744700 - step 2 of 64 - 2500 active elements (0 deactivated)
16:22:38 INFO opendrift:2144: 2026-02-16 16:52:28.744700 - step 3 of 64 - 2500 active elements (0 deactivated)
16:22:38 INFO opendrift:2144: 2026-02-16 17:07:28.744700 - step 4 of 64 - 2500 active elements (0 deactivated)
16:22:41 INFO opendrift:2144: 2026-02-16 17:22:28.744700 - step 5 of 64 - 2500 active elements (0 deactivated)
16:22:41 INFO opendrift:2144: 2026-02-16 17:37:28.744700 - step 6 of 64 - 2500 active elements (0 deactivated)
16:22:42 INFO opendrift:2144: 2026-02-16 17:52:28.744700 - step 7 of 64 - 2500 active elements (0 deactivated)
16:22:43 INFO opendrift:2144: 2026-02-16 18:07:28.744700 - step 8 of 64 - 2500 active elements (0 deactivated)
16:22:45 INFO opendrift:2144: 2026-02-16 18:22:28.744700 - step 9 of 64 - 2500 active elements (0 deactivated)
16:22:46 INFO opendrift:2144: 2026-02-16 18:37:28.744700 - step 10 of 64 - 2500 active elements (0 deactivated)
16:22:47 INFO opendrift:2144: 2026-02-16 18:52:28.744700 - step 11 of 64 - 2500 active elements (0 deactivated)
16:22:48 INFO opendrift:2144: 2026-02-16 19:07:28.744700 - step 12 of 64 - 2500 active elements (0 deactivated)
16:22:50 INFO opendrift:2144: 2026-02-16 19:22:28.744700 - step 13 of 64 - 2500 active elements (0 deactivated)
16:22:51 INFO opendrift:2144: 2026-02-16 19:37:28.744700 - step 14 of 64 - 2500 active elements (0 deactivated)
16:22:51 INFO opendrift:2144: 2026-02-16 19:52:28.744700 - step 15 of 64 - 2500 active elements (0 deactivated)
16:22:52 INFO opendrift:2144: 2026-02-16 20:07:28.744700 - step 16 of 64 - 2500 active elements (0 deactivated)
16:22:54 INFO opendrift:2144: 2026-02-16 20:22:28.744700 - step 17 of 64 - 2500 active elements (0 deactivated)
16:22:55 INFO opendrift:2144: 2026-02-16 20:37:28.744700 - step 18 of 64 - 2500 active elements (0 deactivated)
16:22:56 INFO opendrift:2144: 2026-02-16 20:52:28.744700 - step 19 of 64 - 2500 active elements (0 deactivated)
16:22:56 INFO opendrift:2144: 2026-02-16 21:07:28.744700 - step 20 of 64 - 2500 active elements (0 deactivated)
16:22:59 INFO opendrift:2144: 2026-02-16 21:22:28.744700 - step 21 of 64 - 2500 active elements (0 deactivated)
16:22:59 INFO opendrift:2144: 2026-02-16 21:37:28.744700 - step 22 of 64 - 2500 active elements (0 deactivated)
16:23:00 INFO opendrift:2144: 2026-02-16 21:52:28.744700 - step 23 of 64 - 2500 active elements (0 deactivated)
16:23:01 INFO opendrift:2144: 2026-02-16 22:07:28.744700 - step 24 of 64 - 2500 active elements (0 deactivated)
16:23:03 INFO opendrift:2144: 2026-02-16 22:22:28.744700 - step 25 of 64 - 2500 active elements (0 deactivated)
16:23:04 INFO opendrift:2144: 2026-02-16 22:37:28.744700 - step 26 of 64 - 2500 active elements (0 deactivated)
16:23:04 INFO opendrift:2144: 2026-02-16 22:52:28.744700 - step 27 of 64 - 2500 active elements (0 deactivated)
16:23:05 INFO opendrift:2144: 2026-02-16 23:07:28.744700 - step 28 of 64 - 2500 active elements (0 deactivated)
16:23:08 INFO opendrift:2144: 2026-02-16 23:22:28.744700 - step 29 of 64 - 2500 active elements (0 deactivated)
16:23:09 INFO opendrift:2144: 2026-02-16 23:37:28.744700 - step 30 of 64 - 2500 active elements (0 deactivated)
16:23:10 INFO opendrift:2144: 2026-02-16 23:52:28.744700 - step 31 of 64 - 2500 active elements (0 deactivated)
16:23:10 INFO opendrift:2144: 2026-02-17 00:07:28.744700 - step 32 of 64 - 2500 active elements (0 deactivated)
16:23:13 INFO opendrift:2144: 2026-02-17 00:22:28.744700 - step 33 of 64 - 2500 active elements (0 deactivated)
16:23:13 INFO opendrift:2144: 2026-02-17 00:37:28.744700 - step 34 of 64 - 2500 active elements (0 deactivated)
16:23:14 INFO opendrift:2144: 2026-02-17 00:52:28.744700 - step 35 of 64 - 2500 active elements (0 deactivated)
16:23:14 INFO opendrift:2144: 2026-02-17 01:07:28.744700 - step 36 of 64 - 2500 active elements (0 deactivated)
16:23:17 INFO opendrift:2144: 2026-02-17 01:22:28.744700 - step 37 of 64 - 2500 active elements (0 deactivated)
16:23:18 INFO opendrift:2144: 2026-02-17 01:37:28.744700 - step 38 of 64 - 2500 active elements (0 deactivated)
16:23:18 INFO opendrift:2144: 2026-02-17 01:52:28.744700 - step 39 of 64 - 2500 active elements (0 deactivated)
16:23:19 INFO opendrift:2144: 2026-02-17 02:07:28.744700 - step 40 of 64 - 2500 active elements (0 deactivated)
16:23:21 INFO opendrift:2144: 2026-02-17 02:22:28.744700 - step 41 of 64 - 2500 active elements (0 deactivated)
16:23:22 INFO opendrift:2144: 2026-02-17 02:37:28.744700 - step 42 of 64 - 2500 active elements (0 deactivated)
16:23:23 INFO opendrift:2144: 2026-02-17 02:52:28.744700 - step 43 of 64 - 2500 active elements (0 deactivated)
16:23:23 INFO opendrift:2144: 2026-02-17 03:07:28.744700 - step 44 of 64 - 2500 active elements (0 deactivated)
16:23:26 INFO opendrift:2144: 2026-02-17 03:22:28.744700 - step 45 of 64 - 2500 active elements (0 deactivated)
16:23:26 INFO opendrift:2144: 2026-02-17 03:37:28.744700 - step 46 of 64 - 2500 active elements (0 deactivated)
16:23:27 INFO opendrift:2144: 2026-02-17 03:52:28.744700 - step 47 of 64 - 2500 active elements (0 deactivated)
16:23:28 INFO opendrift:2144: 2026-02-17 04:07:28.744700 - step 48 of 64 - 2500 active elements (0 deactivated)
16:23:31 INFO opendrift:2144: 2026-02-17 04:22:28.744700 - step 49 of 64 - 2500 active elements (0 deactivated)
16:23:31 INFO opendrift:2144: 2026-02-17 04:37:28.744700 - step 50 of 64 - 2500 active elements (0 deactivated)
16:23:32 INFO opendrift:2144: 2026-02-17 04:52:28.744700 - step 51 of 64 - 2500 active elements (0 deactivated)
16:23:33 INFO opendrift:2144: 2026-02-17 05:07:28.744700 - step 52 of 64 - 2500 active elements (0 deactivated)
16:23:35 INFO opendrift:2144: 2026-02-17 05:22:28.744700 - step 53 of 64 - 2500 active elements (0 deactivated)
16:23:35 INFO opendrift:2144: 2026-02-17 05:37:28.744700 - step 54 of 64 - 2500 active elements (0 deactivated)
16:23:36 INFO opendrift:2144: 2026-02-17 05:52:28.744700 - step 55 of 64 - 2500 active elements (0 deactivated)
16:23:37 INFO opendrift:2144: 2026-02-17 06:07:28.744700 - step 56 of 64 - 2500 active elements (0 deactivated)
16:23:39 INFO opendrift:2144: 2026-02-17 06:22:28.744700 - step 57 of 64 - 2500 active elements (0 deactivated)
16:23:39 INFO opendrift:2144: 2026-02-17 06:37:28.744700 - step 58 of 64 - 2500 active elements (0 deactivated)
16:23:40 INFO opendrift:2144: 2026-02-17 06:52:28.744700 - step 59 of 64 - 2500 active elements (0 deactivated)
16:23:41 INFO opendrift:2144: 2026-02-17 07:07:28.744700 - step 60 of 64 - 2500 active elements (0 deactivated)
16:23:43 INFO opendrift:2144: 2026-02-17 07:22:28.744700 - step 61 of 64 - 2500 active elements (0 deactivated)
16:23:43 INFO opendrift:2144: 2026-02-17 07:37:28.744700 - step 62 of 64 - 2500 active elements (0 deactivated)
16:23:44 INFO opendrift:2144: 2026-02-17 07:52:28.744700 - step 63 of 64 - 2500 active elements (0 deactivated)
16:23:45 INFO opendrift:2144: 2026-02-17 08:07:28.744700 - 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:00:31.3 total
0:00:00.0 preparing
0:00:30.8 reading
0:00:00.4 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:00:40.7 total
0:00:00.0 preparing
0:00:40.5 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:
1:23.3 total time
9.1 configuration
0.0 preparing main loop
0.0 moving elements to ocean
1:14.1 main loop
0.2 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.14.8)
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-02-16 16:22:28.744700 UTC
Present: 2026-02-17 08:22:28.744700 UTC
Calculation steps: 64 * 0:15:00 - total time: 16:00:00
Output steps: 33 * 0:30:00
===========================
16:23:47 WARNING opendrift:2507: Plotting fast. This will make your plots less accurate.
16:23:48 INFO opendrift:4702: Saving animation to /root/project/docs/source/gallery/animations/example_reader_boundary_0.gif...
16:24:08 INFO opendrift:3128: Time to make animation: 0:00:20.565133
o.plot(fast=True)

16:24:08 WARNING opendrift:2507: Plotting fast. This will make your plots less accurate.
(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2026-02-16 16:22 to 2026-02-17 08:22 UTC (33 steps)'}>, <Figure size 897.819x1100 with 1 Axes>)
Total running time of the script: (1 minutes 57.944 seconds)