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:17:45 INFO    opendrift:576: OpenDriftSimulation initialised (version 1.14.8 / v1.14.8-4-g48afd36)
13:17:45 INFO    opendrift.readers:63: Opening file with xr.open_dataset
13:17:47 INFO    opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
13:17:47 INFO    opendrift.readers.basereader:176: Variable x_sea_water_velocity will be rotated from eastward_sea_water_velocity
13:17:47 INFO    opendrift.readers.basereader:176: Variable y_sea_water_velocity will be rotated from northward_sea_water_velocity
13:17:47 INFO    opendrift.readers.basereader:176: Variable x_wind will be rotated from eastward_wind
13:17:47 INFO    opendrift.readers.basereader:176: Variable y_wind will be rotated from northward_wind
13:17:47 INFO    opendrift.readers:63: Opening file with xr.open_dataset
13:17:51 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())
13:17:51 INFO    opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
13:17:55 INFO    opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
13:17:55 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_significant_height: 0.000000
13:17:55 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:17:55 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:17:55 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)
13:17:55 INFO    opendrift:1810: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
13:17:55 INFO    opendrift:1810: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
13:17:55 INFO    opendrift:1821: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:17:55 INFO    opendrift:1821: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:17:55 INFO    opendrift:1829: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
13:17:55 INFO    opendrift:952: Using existing reader for land_binary_mask to move elements to ocean
13:17:55 INFO    opendrift:982: All points are in ocean
13:17:55 INFO    opendrift:2118: 2026-01-28 13:17:51.367284 - step 1 of 64 - 2500 active elements (0 deactivated)
13:17:59 INFO    opendrift:2118: 2026-01-28 13:32:51.367284 - step 2 of 64 - 2500 active elements (0 deactivated)
13:18:00 INFO    opendrift:2118: 2026-01-28 13:47:51.367284 - step 3 of 64 - 2500 active elements (0 deactivated)
13:18:01 INFO    opendrift:2118: 2026-01-28 14:02:51.367284 - step 4 of 64 - 2500 active elements (0 deactivated)
13:18:03 INFO    opendrift:2118: 2026-01-28 14:17:51.367284 - step 5 of 64 - 2500 active elements (0 deactivated)
13:18:03 INFO    opendrift:2118: 2026-01-28 14:32:51.367284 - step 6 of 64 - 2500 active elements (0 deactivated)
13:18:04 INFO    opendrift:2118: 2026-01-28 14:47:51.367284 - step 7 of 64 - 2500 active elements (0 deactivated)
13:18:05 INFO    opendrift:2118: 2026-01-28 15:02:51.367284 - step 8 of 64 - 2500 active elements (0 deactivated)
13:18:07 INFO    opendrift:2118: 2026-01-28 15:17:51.367284 - step 9 of 64 - 2500 active elements (0 deactivated)
13:18:08 INFO    opendrift:2118: 2026-01-28 15:32:51.367284 - step 10 of 64 - 2500 active elements (0 deactivated)
13:18:08 INFO    opendrift:2118: 2026-01-28 15:47:51.367284 - step 11 of 64 - 2500 active elements (0 deactivated)
13:18:09 INFO    opendrift:2118: 2026-01-28 16:02:51.367284 - step 12 of 64 - 2500 active elements (0 deactivated)
13:18:11 INFO    opendrift:2118: 2026-01-28 16:17:51.367284 - step 13 of 64 - 2500 active elements (0 deactivated)
13:18:12 INFO    opendrift:2118: 2026-01-28 16:32:51.367284 - step 14 of 64 - 2500 active elements (0 deactivated)
13:18:12 INFO    opendrift:2118: 2026-01-28 16:47:51.367284 - step 15 of 64 - 2500 active elements (0 deactivated)
13:18:13 INFO    opendrift:2118: 2026-01-28 17:02:51.367284 - step 16 of 64 - 2500 active elements (0 deactivated)
13:18:15 INFO    opendrift:2118: 2026-01-28 17:17:51.367284 - step 17 of 64 - 2500 active elements (0 deactivated)
13:18:16 INFO    opendrift:2118: 2026-01-28 17:32:51.367284 - step 18 of 64 - 2500 active elements (0 deactivated)
13:18:17 INFO    opendrift:2118: 2026-01-28 17:47:51.367284 - step 19 of 64 - 2500 active elements (0 deactivated)
13:18:17 INFO    opendrift:2118: 2026-01-28 18:02:51.367284 - step 20 of 64 - 2500 active elements (0 deactivated)
13:18:20 INFO    opendrift:2118: 2026-01-28 18:17:51.367284 - step 21 of 64 - 2500 active elements (0 deactivated)
13:18:20 INFO    opendrift:2118: 2026-01-28 18:32:51.367284 - step 22 of 64 - 2500 active elements (0 deactivated)
13:18:21 INFO    opendrift:2118: 2026-01-28 18:47:51.367284 - step 23 of 64 - 2500 active elements (0 deactivated)
13:18:22 INFO    opendrift:2118: 2026-01-28 19:02:51.367284 - step 24 of 64 - 2500 active elements (0 deactivated)
13:18:24 INFO    opendrift:2118: 2026-01-28 19:17:51.367284 - step 25 of 64 - 2500 active elements (0 deactivated)
13:18:25 INFO    opendrift:2118: 2026-01-28 19:32:51.367284 - step 26 of 64 - 2500 active elements (0 deactivated)
13:18:25 INFO    opendrift:2118: 2026-01-28 19:47:51.367284 - step 27 of 64 - 2500 active elements (0 deactivated)
13:18:26 INFO    opendrift:2118: 2026-01-28 20:02:51.367284 - step 28 of 64 - 2500 active elements (0 deactivated)
13:18:28 INFO    opendrift:2118: 2026-01-28 20:17:51.367284 - step 29 of 64 - 2500 active elements (0 deactivated)
13:18:29 INFO    opendrift:2118: 2026-01-28 20:32:51.367284 - step 30 of 64 - 2500 active elements (0 deactivated)
13:18:30 INFO    opendrift:2118: 2026-01-28 20:47:51.367284 - step 31 of 64 - 2500 active elements (0 deactivated)
13:18:30 INFO    opendrift:2118: 2026-01-28 21:02:51.367284 - step 32 of 64 - 2500 active elements (0 deactivated)
13:18:33 INFO    opendrift:2118: 2026-01-28 21:17:51.367284 - step 33 of 64 - 2500 active elements (0 deactivated)
13:18:33 INFO    opendrift:2118: 2026-01-28 21:32:51.367284 - step 34 of 64 - 2500 active elements (0 deactivated)
13:18:34 INFO    opendrift:2118: 2026-01-28 21:47:51.367284 - step 35 of 64 - 2500 active elements (0 deactivated)
13:18:35 INFO    opendrift:2118: 2026-01-28 22:02:51.367284 - step 36 of 64 - 2500 active elements (0 deactivated)
13:18:37 INFO    opendrift:2118: 2026-01-28 22:17:51.367284 - step 37 of 64 - 2500 active elements (0 deactivated)
13:18:37 INFO    opendrift:2118: 2026-01-28 22:32:51.367284 - step 38 of 64 - 2500 active elements (0 deactivated)
13:18:38 INFO    opendrift:2118: 2026-01-28 22:47:51.367284 - step 39 of 64 - 2500 active elements (0 deactivated)
13:18:39 INFO    opendrift:2118: 2026-01-28 23:02:51.367284 - step 40 of 64 - 2500 active elements (0 deactivated)
13:18:41 INFO    opendrift:2118: 2026-01-28 23:17:51.367284 - step 41 of 64 - 2500 active elements (0 deactivated)
13:18:42 INFO    opendrift:2118: 2026-01-28 23:32:51.367284 - step 42 of 64 - 2500 active elements (0 deactivated)
13:18:42 INFO    opendrift:2118: 2026-01-28 23:47:51.367284 - step 43 of 64 - 2500 active elements (0 deactivated)
13:18:43 INFO    opendrift:2118: 2026-01-29 00:02:51.367284 - step 44 of 64 - 2500 active elements (0 deactivated)
13:18:45 INFO    opendrift:2118: 2026-01-29 00:17:51.367284 - step 45 of 64 - 2500 active elements (0 deactivated)
13:18:46 INFO    opendrift:2118: 2026-01-29 00:32:51.367284 - step 46 of 64 - 2500 active elements (0 deactivated)
13:18:46 INFO    opendrift:2118: 2026-01-29 00:47:51.367284 - step 47 of 64 - 2500 active elements (0 deactivated)
13:18:47 INFO    opendrift:2118: 2026-01-29 01:02:51.367284 - step 48 of 64 - 2500 active elements (0 deactivated)
13:18:50 INFO    opendrift:2118: 2026-01-29 01:17:51.367284 - step 49 of 64 - 2500 active elements (0 deactivated)
13:18:50 INFO    opendrift:2118: 2026-01-29 01:32:51.367284 - step 50 of 64 - 2500 active elements (0 deactivated)
13:18:51 INFO    opendrift:2118: 2026-01-29 01:47:51.367284 - step 51 of 64 - 2500 active elements (0 deactivated)
13:18:52 INFO    opendrift:2118: 2026-01-29 02:02:51.367284 - step 52 of 64 - 2500 active elements (0 deactivated)
13:18:54 INFO    opendrift:2118: 2026-01-29 02:17:51.367284 - step 53 of 64 - 2500 active elements (0 deactivated)
13:18:54 INFO    opendrift:2118: 2026-01-29 02:32:51.367284 - step 54 of 64 - 2500 active elements (0 deactivated)
13:18:55 INFO    opendrift:2118: 2026-01-29 02:47:51.367284 - step 55 of 64 - 2500 active elements (0 deactivated)
13:18:56 INFO    opendrift:2118: 2026-01-29 03:02:51.367284 - step 56 of 64 - 2500 active elements (0 deactivated)
13:18:58 INFO    opendrift:2118: 2026-01-29 03:17:51.367284 - step 57 of 64 - 2500 active elements (0 deactivated)
13:18:59 INFO    opendrift:2118: 2026-01-29 03:32:51.367284 - step 58 of 64 - 2500 active elements (0 deactivated)
13:18:59 INFO    opendrift:2118: 2026-01-29 03:47:51.367284 - step 59 of 64 - 2500 active elements (0 deactivated)
13:19:00 INFO    opendrift:2118: 2026-01-29 04:02:51.367284 - step 60 of 64 - 2500 active elements (0 deactivated)
13:19:02 INFO    opendrift:2118: 2026-01-29 04:17:51.367284 - step 61 of 64 - 2500 active elements (0 deactivated)
13:19:03 INFO    opendrift:2118: 2026-01-29 04:32:51.367284 - step 62 of 64 - 2500 active elements (0 deactivated)
13:19:03 INFO    opendrift:2118: 2026-01-29 04:47:51.367284 - step 63 of 64 - 2500 active elements (0 deactivated)
13:19:04 INFO    opendrift:2118: 2026-01-29 05:02:51.367284 - step 64 of 64 - 2500 active elements (0 deactivated)
<xarray.Dataset> Size: 7MB
Dimensions:                                   (trajectory: 2500, time: 33)
Coordinates:
  * trajectory                                (trajectory) int64 20kB 0 ... 2499
  * time                                      (time) datetime64[ns] 264B 2026...
Data variables: (12/21)
    status                                    (trajectory, time) float32 330kB ...
    moving                                    (trajectory, time) float32 330kB ...
    age_seconds                               (trajectory, time) float32 330kB ...
    origin_marker                             (trajectory, time) float32 330kB ...
    lon                                       (trajectory, time) float32 330kB ...
    lat                                       (trajectory, time) float32 330kB ...
    ...                                        ...
    upward_sea_water_velocity                 (trajectory, time) float32 330kB ...
    sea_surface_wave_significant_height       (trajectory, time) float32 330kB ...
    sea_surface_wave_stokes_drift_x_velocity  (trajectory, time) float32 330kB ...
    sea_surface_wave_stokes_drift_y_velocity  (trajectory, time) float32 330kB ...
    sea_floor_depth_below_sea_level           (trajectory, time) float32 330kB ...
    land_binary_mask                          (trajectory, time) float32 330kB ...
Attributes: (12/119)
    Conventions:                                                           CF...
    standard_name_vocabulary:                                              CF...
    featureType:                                                           tr...
    title:                                                                 Op...
    summary:                                                               Ou...
    keywords:                                                              tr...
    ...                                                                    ...
    geospatial_lon_units:                                                  de...
    geospatial_lon_resolution:                                             point
    runtime:                                                               0:...
    geospatial_vertical_min:                                               0.0
    geospatial_vertical_max:                                               0.0
    geospatial_vertical_positive:                                          up


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:30.2  total
 0:00:00.0  preparing
 0:00:29.7  reading
 0:00:00.4  interpolation
 0:00:00.0  interpolation_time
 0:00:00.4  rotating vectors
 0:00:00.0  masking
--------------------
https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
 0:00:39.2  total
 0:00:00.0  preparing
 0:00:39.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:21.2 total time
    9.8 configuration
    0.0 preparing main loop
      0.0 moving elements to ocean
 1:11.4 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:
  sea_surface_wave_significant_height
  sea_surface_wave_stokes_drift_x_velocity
  sea_surface_wave_stokes_drift_y_velocity

Discarded readers:

Time:
        Start: 2026-01-28 13:17:51.367284 UTC
        Present: 2026-01-29 05:17:51.367284 UTC
        Calculation steps: 64 * 0:15:00 - total time: 16:00:00
        Output steps: 33 * 0:30:00
===========================

13:19:07 WARNING opendrift:2480: Plotting fast. This will make your plots less accurate.
13:19:08 INFO    opendrift:4675: Saving animation to /root/project/docs/source/gallery/animations/example_reader_boundary_0.gif...
13:19:32 INFO    opendrift:3101: Time to make animation: 0:00:25.047416
../_images/example_reader_boundary_0.gif
o.plot(fast=True)
OpenDrift - OceanDrift 2026-01-28 13:17 to 2026-01-29 05:17 UTC (33 steps)
13:19:32 WARNING opendrift:2480: Plotting fast. This will make your plots less accurate.

(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2026-01-28 13:17 to 2026-01-29 05:17 UTC (33 steps)'}>, <Figure size 896.531x1100 with 1 Axes>)

Total running time of the script: (2 minutes 0.709 seconds)

Gallery generated by Sphinx-Gallery