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

16:06:16 WARNING opendrift:2470: Plotting fast. This will make your plots less accurate.
(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2025-11-25 16:04 to 2025-11-26 08:04 UTC (33 steps)'}>, <Figure size 1027.13x1100 with 1 Axes>)
Total running time of the script: (2 minutes 6.066 seconds)