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).

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)
08:57:58 INFO    opendrift:513: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-108-gbbc988b)
08:57:58 INFO    opendrift.readers:61: Opening file with xr.open_dataset
08:57:59 INFO    opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
08:57:59 INFO    opendrift.readers.basereader:176: Variable x_sea_water_velocity will be rotated from eastward_sea_water_velocity
08:57:59 INFO    opendrift.readers.basereader:176: Variable y_sea_water_velocity will be rotated from northward_sea_water_velocity
08:57:59 INFO    opendrift.readers.basereader:176: Variable x_wind will be rotated from eastward_wind
08:57:59 INFO    opendrift.readers.basereader:176: Variable y_wind will be rotated from northward_wind
08:57:59 INFO    opendrift.readers:61: Opening file with xr.open_dataset
08:58:01 INFO    opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}

Seeding some particles

lons = np.linspace(10.2, 12.2, 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=reader_topaz.start_time)
08:58:01 INFO    opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
08:58:06 INFO    opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
08:58:06 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_significant_height: 0.000000
08:58:06 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
08:58:06 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
08:58:06 INFO    opendrift.models.basemodel.environment:232:    ocean_mixed_layer_thickness: 50.000000

Running model

o.run(steps=16*4, time_step=900, time_step_output=1800)
08:58:06 INFO    opendrift:1733: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
08:58:06 INFO    opendrift:1733: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
08:58:06 INFO    opendrift:1744: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
08:58:06 INFO    opendrift:1744: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
08:58:06 INFO    opendrift:1752: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
08:58:06 INFO    opendrift:899: Using existing reader for land_binary_mask to move elements to ocean
08:58:06 INFO    opendrift:929: All points are in ocean
08:58:06 INFO    opendrift:2036: 2023-01-01 00:00:00 - step 1 of 64 - 2500 active elements (0 deactivated)
08:58:06 INFO    opendrift:2036: 2023-01-01 00:15:00 - step 2 of 64 - 2500 active elements (0 deactivated)
08:58:07 INFO    opendrift:2036: 2023-01-01 00:30:00 - step 3 of 64 - 2500 active elements (0 deactivated)
08:58:08 INFO    opendrift:2036: 2023-01-01 00:45:00 - step 4 of 64 - 2500 active elements (0 deactivated)
08:58:08 INFO    opendrift:2036: 2023-01-01 01:00:00 - step 5 of 64 - 2500 active elements (0 deactivated)
08:58:09 INFO    opendrift:2036: 2023-01-01 01:15:00 - step 6 of 64 - 2500 active elements (0 deactivated)
08:58:10 INFO    opendrift:2036: 2023-01-01 01:30:00 - step 7 of 64 - 2500 active elements (0 deactivated)
08:58:10 INFO    opendrift:2036: 2023-01-01 01:45:00 - step 8 of 64 - 2500 active elements (0 deactivated)
08:58:11 INFO    opendrift:2036: 2023-01-01 02:00:00 - step 9 of 64 - 2500 active elements (0 deactivated)
08:58:12 INFO    opendrift:2036: 2023-01-01 02:15:00 - step 10 of 64 - 2500 active elements (0 deactivated)
08:58:12 INFO    opendrift:2036: 2023-01-01 02:30:00 - step 11 of 64 - 2500 active elements (0 deactivated)
08:58:13 INFO    opendrift:2036: 2023-01-01 02:45:00 - step 12 of 64 - 2500 active elements (0 deactivated)
08:58:14 INFO    opendrift:2036: 2023-01-01 03:00:00 - step 13 of 64 - 2500 active elements (0 deactivated)
08:58:14 INFO    opendrift:2036: 2023-01-01 03:15:00 - step 14 of 64 - 2500 active elements (0 deactivated)
08:58:15 INFO    opendrift:2036: 2023-01-01 03:30:00 - step 15 of 64 - 2500 active elements (0 deactivated)
08:58:16 INFO    opendrift:2036: 2023-01-01 03:45:00 - step 16 of 64 - 2500 active elements (0 deactivated)
08:58:16 INFO    opendrift:2036: 2023-01-01 04:00:00 - step 17 of 64 - 2500 active elements (0 deactivated)
08:58:17 INFO    opendrift:2036: 2023-01-01 04:15:00 - step 18 of 64 - 2500 active elements (0 deactivated)
08:58:18 INFO    opendrift:2036: 2023-01-01 04:30:00 - step 19 of 64 - 2500 active elements (0 deactivated)
08:58:18 INFO    opendrift:2036: 2023-01-01 04:45:00 - step 20 of 64 - 2500 active elements (0 deactivated)
08:58:19 INFO    opendrift:2036: 2023-01-01 05:00:00 - step 21 of 64 - 2500 active elements (0 deactivated)
08:58:20 INFO    opendrift:2036: 2023-01-01 05:15:00 - step 22 of 64 - 2500 active elements (0 deactivated)
08:58:20 INFO    opendrift:2036: 2023-01-01 05:30:00 - step 23 of 64 - 2500 active elements (0 deactivated)
08:58:21 INFO    opendrift:2036: 2023-01-01 05:45:00 - step 24 of 64 - 2500 active elements (0 deactivated)
08:58:22 INFO    opendrift:2036: 2023-01-01 06:00:00 - step 25 of 64 - 2500 active elements (0 deactivated)
08:58:23 INFO    opendrift:2036: 2023-01-01 06:15:00 - step 26 of 64 - 2500 active elements (0 deactivated)
08:58:23 INFO    opendrift:2036: 2023-01-01 06:30:00 - step 27 of 64 - 2500 active elements (0 deactivated)
08:58:24 INFO    opendrift:2036: 2023-01-01 06:45:00 - step 28 of 64 - 2500 active elements (0 deactivated)
08:58:24 INFO    opendrift:2036: 2023-01-01 07:00:00 - step 29 of 64 - 2500 active elements (0 deactivated)
08:58:25 INFO    opendrift:2036: 2023-01-01 07:15:00 - step 30 of 64 - 2500 active elements (0 deactivated)
08:58:26 INFO    opendrift:2036: 2023-01-01 07:30:00 - step 31 of 64 - 2500 active elements (0 deactivated)
08:58:26 INFO    opendrift:2036: 2023-01-01 07:45:00 - step 32 of 64 - 2500 active elements (0 deactivated)
08:58:27 INFO    opendrift:2036: 2023-01-01 08:00:00 - step 33 of 64 - 2500 active elements (0 deactivated)
08:58:27 INFO    opendrift:2036: 2023-01-01 08:15:00 - step 34 of 64 - 2500 active elements (0 deactivated)
08:58:28 INFO    opendrift:2036: 2023-01-01 08:30:00 - step 35 of 64 - 2500 active elements (0 deactivated)
08:58:28 INFO    opendrift:2036: 2023-01-01 08:45:00 - step 36 of 64 - 2500 active elements (0 deactivated)
08:58:29 INFO    opendrift:2036: 2023-01-01 09:00:00 - step 37 of 64 - 2500 active elements (0 deactivated)
08:58:30 INFO    opendrift:2036: 2023-01-01 09:15:00 - step 38 of 64 - 2500 active elements (0 deactivated)
08:58:31 INFO    opendrift:2036: 2023-01-01 09:30:00 - step 39 of 64 - 2500 active elements (0 deactivated)
08:58:31 INFO    opendrift:2036: 2023-01-01 09:45:00 - step 40 of 64 - 2500 active elements (0 deactivated)
08:58:32 INFO    opendrift:2036: 2023-01-01 10:00:00 - step 41 of 64 - 2500 active elements (0 deactivated)
08:58:32 INFO    opendrift:2036: 2023-01-01 10:15:00 - step 42 of 64 - 2500 active elements (0 deactivated)
08:58:33 INFO    opendrift:2036: 2023-01-01 10:30:00 - step 43 of 64 - 2500 active elements (0 deactivated)
08:58:34 INFO    opendrift:2036: 2023-01-01 10:45:00 - step 44 of 64 - 2500 active elements (0 deactivated)
08:58:35 INFO    opendrift:2036: 2023-01-01 11:00:00 - step 45 of 64 - 2500 active elements (0 deactivated)
08:58:35 INFO    opendrift:2036: 2023-01-01 11:15:00 - step 46 of 64 - 2500 active elements (0 deactivated)
08:58:36 INFO    opendrift:2036: 2023-01-01 11:30:00 - step 47 of 64 - 2500 active elements (0 deactivated)
08:58:36 INFO    opendrift:2036: 2023-01-01 11:45:00 - step 48 of 64 - 2500 active elements (0 deactivated)
08:58:37 INFO    opendrift:2036: 2023-01-01 12:00:00 - step 49 of 64 - 2500 active elements (0 deactivated)
08:58:38 INFO    opendrift:2036: 2023-01-01 12:15:00 - step 50 of 64 - 2500 active elements (0 deactivated)
08:58:38 INFO    opendrift:2036: 2023-01-01 12:30:00 - step 51 of 64 - 2500 active elements (0 deactivated)
08:58:39 INFO    opendrift:2036: 2023-01-01 12:45:00 - step 52 of 64 - 2500 active elements (0 deactivated)
08:58:39 INFO    opendrift:2036: 2023-01-01 13:00:00 - step 53 of 64 - 2500 active elements (0 deactivated)
08:58:40 INFO    opendrift:2036: 2023-01-01 13:15:00 - step 54 of 64 - 2500 active elements (0 deactivated)
08:58:40 INFO    opendrift:2036: 2023-01-01 13:30:00 - step 55 of 64 - 2500 active elements (0 deactivated)
08:58:41 INFO    opendrift:2036: 2023-01-01 13:45:00 - step 56 of 64 - 2500 active elements (0 deactivated)
08:58:42 INFO    opendrift:2036: 2023-01-01 14:00:00 - step 57 of 64 - 2500 active elements (0 deactivated)
08:58:42 INFO    opendrift:2036: 2023-01-01 14:15:00 - step 58 of 64 - 2500 active elements (0 deactivated)
08:58:43 INFO    opendrift:2036: 2023-01-01 14:30:00 - step 59 of 64 - 2500 active elements (0 deactivated)
08:58:43 INFO    opendrift:2036: 2023-01-01 14:45:00 - step 60 of 64 - 2500 active elements (0 deactivated)
08:58:44 INFO    opendrift:2036: 2023-01-01 15:00:00 - step 61 of 64 - 2500 active elements (0 deactivated)
08:58:44 INFO    opendrift:2036: 2023-01-01 15:15:00 - step 62 of 64 - 2500 active elements (0 deactivated)
08:58:45 INFO    opendrift:2036: 2023-01-01 15:30:00 - step 63 of 64 - 2500 active elements (0 deactivated)
08:58:46 INFO    opendrift:2036: 2023-01-01 15:45:00 - 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 2023...
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
--------------------
https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
 0:00:39.0  total
 0:00:00.0  preparing
 0:00:38.7  reading
 0:00:00.0  interpolation
 0:00:00.0  interpolation_time
 0:00:00.2  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:
   48.4 total time
    7.9 configuration
    0.0 preparing main loop
      0.0 moving elements to ocean
   40.5 main loop
      0.1 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.14.2)
        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: 2023-01-01 00:00:00 UTC
        Present: 2023-01-01 16:00:00 UTC
        Calculation steps: 64 * 0:15:00 - total time: 16:00:00
        Output steps: 33 * 0:30:00
===========================

08:58:46 WARNING opendrift:2392: Plotting fast. This will make your plots less accurate.
08:58:48 INFO    opendrift:4560: Saving animation to /root/project/docs/source/gallery/animations/example_reader_boundary_0.gif...
08:59:13 INFO    opendrift:3001: Time to make animation: 0:00:26.466387
../_images/example_reader_boundary_0.gif
o.plot(fast=True)
OpenDrift - OceanDrift 2023-01-01 00:00 to 2023-01-01 16:00 UTC (33 steps)
08:59:13 WARNING opendrift:2392: Plotting fast. This will make your plots less accurate.

(<GeoAxes: title={'center': 'OpenDrift - OceanDrift\n2023-01-01 00:00 to 2023-01-01 16:00 UTC (33 steps)'}>, <Figure size 765.013x1100 with 1 Axes>)

Total running time of the script: (1 minutes 28.711 seconds)

Gallery generated by Sphinx-Gallery