No stranding

import numpy as np
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.readers import reader_ROMS_native
from opendrift.models.oceandrift import OceanDrift

o = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information
o.max_speed = 3

# This example works better using hourly input from Thredds than the daily data from test folder
reader_current = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml')
#reader_current = reader_ROMS_native.Reader(o.test_data_folder() +
#    '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')

o.add_reader([reader_current])
o.set_config('general:coastline_action', 'previous')

Out:

13:45:22 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.7.1 / v1.7.1-87-g074c1d2)
13:45:22 INFO    opendrift.readers.reader_netCDF_CF_generic: Opening dataset: https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml

Seeding elements on a grid

lons = np.linspace(12, 14.5, 30)
lats = np.linspace(67.5, 68.5, 30)
lons, lats = np.meshgrid(lons, lats)
lon = lons.ravel()
lat = lats.ravel()

time = reader_current.start_time
o.seed_elements(lon, lat, radius=0, number=30*30, time=time)

o.run(steps=24*2, time_step=3600)

Out:

13:45:26 INFO    opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers:
13:45:26 INFO    opendrift.models.basemodel:    x_wind: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    y_wind: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    upward_sea_water_velocity: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    ocean_vertical_diffusivity: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    sea_surface_wave_significant_height: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    surface_downward_x_stress: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    surface_downward_y_stress: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    turbulent_kinetic_energy: 0.000000
13:45:26 INFO    opendrift.models.basemodel:    turbulent_generic_length_scale: 0.000000
13:45:26 INFO    opendrift.models.basemodel: Adding a dynamical landmask with max. priority based on assumed maximum speed of 3 m/s. Adding a customised landmask may be faster...
13:45:28 INFO    opendrift.models.basemodel: Using existing reader for land_binary_mask
13:45:28 INFO    opendrift.models.basemodel: Moving 81 out of 900 points from land to water
13:45:29 INFO    opendrift.models.basemodel: 2018-01-01 00:00:00 - step 1 of 48 - 900 active elements (0 deactivated)
13:45:29 INFO    opendrift.models.basemodel: 2018-01-01 01:00:00 - step 2 of 48 - 900 active elements (0 deactivated)
13:45:30 INFO    opendrift.models.basemodel: 2018-01-01 02:00:00 - step 3 of 48 - 900 active elements (0 deactivated)
13:45:31 INFO    opendrift.models.basemodel: 2018-01-01 03:00:00 - step 4 of 48 - 900 active elements (0 deactivated)
13:45:31 INFO    opendrift.models.basemodel: 2018-01-01 04:00:00 - step 5 of 48 - 900 active elements (0 deactivated)
13:45:32 INFO    opendrift.models.basemodel: 2018-01-01 05:00:00 - step 6 of 48 - 900 active elements (0 deactivated)
13:45:32 INFO    opendrift.models.basemodel: 2018-01-01 06:00:00 - step 7 of 48 - 900 active elements (0 deactivated)
13:45:33 INFO    opendrift.models.basemodel: 2018-01-01 07:00:00 - step 8 of 48 - 900 active elements (0 deactivated)
13:45:33 INFO    opendrift.models.basemodel: 2018-01-01 08:00:00 - step 9 of 48 - 900 active elements (0 deactivated)
13:45:34 INFO    opendrift.models.basemodel: 2018-01-01 09:00:00 - step 10 of 48 - 900 active elements (0 deactivated)
13:45:34 INFO    opendrift.models.basemodel: 2018-01-01 10:00:00 - step 11 of 48 - 900 active elements (0 deactivated)
13:45:35 INFO    opendrift.models.basemodel: 2018-01-01 11:00:00 - step 12 of 48 - 900 active elements (0 deactivated)
13:45:36 INFO    opendrift.models.basemodel: 2018-01-01 12:00:00 - step 13 of 48 - 900 active elements (0 deactivated)
13:45:36 INFO    opendrift.models.basemodel: 2018-01-01 13:00:00 - step 14 of 48 - 900 active elements (0 deactivated)
13:45:37 INFO    opendrift.models.basemodel: 2018-01-01 14:00:00 - step 15 of 48 - 900 active elements (0 deactivated)
13:45:37 INFO    opendrift.models.basemodel: 2018-01-01 15:00:00 - step 16 of 48 - 900 active elements (0 deactivated)
13:45:38 INFO    opendrift.models.basemodel: 2018-01-01 16:00:00 - step 17 of 48 - 900 active elements (0 deactivated)
13:45:38 INFO    opendrift.models.basemodel: 2018-01-01 17:00:00 - step 18 of 48 - 900 active elements (0 deactivated)
13:45:39 INFO    opendrift.models.basemodel: 2018-01-01 18:00:00 - step 19 of 48 - 900 active elements (0 deactivated)
13:45:40 INFO    opendrift.models.basemodel: 2018-01-01 19:00:00 - step 20 of 48 - 900 active elements (0 deactivated)
13:45:40 INFO    opendrift.models.basemodel: 2018-01-01 20:00:00 - step 21 of 48 - 900 active elements (0 deactivated)
13:45:41 INFO    opendrift.models.basemodel: 2018-01-01 21:00:00 - step 22 of 48 - 900 active elements (0 deactivated)
13:45:41 INFO    opendrift.models.basemodel: 2018-01-01 22:00:00 - step 23 of 48 - 900 active elements (0 deactivated)
13:45:42 INFO    opendrift.models.basemodel: 2018-01-01 23:00:00 - step 24 of 48 - 900 active elements (0 deactivated)
13:45:42 INFO    opendrift.models.basemodel: 2018-01-02 00:00:00 - step 25 of 48 - 900 active elements (0 deactivated)
13:45:43 INFO    opendrift.models.basemodel: 2018-01-02 01:00:00 - step 26 of 48 - 900 active elements (0 deactivated)
13:45:44 INFO    opendrift.models.basemodel: 2018-01-02 02:00:00 - step 27 of 48 - 900 active elements (0 deactivated)
13:45:44 INFO    opendrift.models.basemodel: 2018-01-02 03:00:00 - step 28 of 48 - 900 active elements (0 deactivated)
13:45:45 INFO    opendrift.models.basemodel: 2018-01-02 04:00:00 - step 29 of 48 - 900 active elements (0 deactivated)
13:45:45 INFO    opendrift.models.basemodel: 2018-01-02 05:00:00 - step 30 of 48 - 900 active elements (0 deactivated)
13:45:46 INFO    opendrift.models.basemodel: 2018-01-02 06:00:00 - step 31 of 48 - 900 active elements (0 deactivated)
13:45:46 INFO    opendrift.models.basemodel: 2018-01-02 07:00:00 - step 32 of 48 - 900 active elements (0 deactivated)
13:45:47 INFO    opendrift.models.basemodel: 2018-01-02 08:00:00 - step 33 of 48 - 900 active elements (0 deactivated)
13:45:48 INFO    opendrift.models.basemodel: 2018-01-02 09:00:00 - step 34 of 48 - 900 active elements (0 deactivated)
13:45:48 INFO    opendrift.models.basemodel: 2018-01-02 10:00:00 - step 35 of 48 - 900 active elements (0 deactivated)
13:45:49 INFO    opendrift.models.basemodel: 2018-01-02 11:00:00 - step 36 of 48 - 900 active elements (0 deactivated)
13:45:49 INFO    opendrift.models.basemodel: 2018-01-02 12:00:00 - step 37 of 48 - 900 active elements (0 deactivated)
13:45:50 INFO    opendrift.models.basemodel: 2018-01-02 13:00:00 - step 38 of 48 - 900 active elements (0 deactivated)
13:45:50 INFO    opendrift.models.basemodel: 2018-01-02 14:00:00 - step 39 of 48 - 900 active elements (0 deactivated)
13:45:51 INFO    opendrift.models.basemodel: 2018-01-02 15:00:00 - step 40 of 48 - 900 active elements (0 deactivated)
13:45:51 INFO    opendrift.models.basemodel: 2018-01-02 16:00:00 - step 41 of 48 - 900 active elements (0 deactivated)
13:45:52 INFO    opendrift.models.basemodel: 2018-01-02 17:00:00 - step 42 of 48 - 900 active elements (0 deactivated)
13:45:52 INFO    opendrift.models.basemodel: 2018-01-02 18:00:00 - step 43 of 48 - 900 active elements (0 deactivated)
13:45:53 INFO    opendrift.models.basemodel: 2018-01-02 19:00:00 - step 44 of 48 - 900 active elements (0 deactivated)
13:45:53 INFO    opendrift.models.basemodel: 2018-01-02 20:00:00 - step 45 of 48 - 900 active elements (0 deactivated)
13:45:54 INFO    opendrift.models.basemodel: 2018-01-02 21:00:00 - step 46 of 48 - 900 active elements (0 deactivated)
13:45:54 INFO    opendrift.models.basemodel: 2018-01-02 22:00:00 - step 47 of 48 - 900 active elements (0 deactivated)
13:45:55 INFO    opendrift.models.basemodel: 2018-01-02 23:00:00 - step 48 of 48 - 900 active elements (0 deactivated)

Print and plot results

print(o)
o.plot()
#o.plot(background=['x_sea_water_velocity', 'y_sea_water_velocity'])
o.animation()
OpenDrift - OceanDrift 2018-01-01 00:00 to 2018-01-03 00:00 UTC (49 steps)

Out:

===========================
--------------------
Reader performance:
--------------------
https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
 0:00:26.2  total
 0:00:00.0  preparing
 0:00:25.5  reading
 0:00:00.0  interpolation
 0:00:00.0  interpolation_time
 0:00:00.0  masking
 0:00:00.7  rotating vectors
--------------------
global_landmask
 0:00:00.2  total
 0:00:00.0  preparing
 0:00:00.2  reading
 0:00:00.0  masking
--------------------
Performance:
   34.0 total time
    4.2 configuration
    2.7 preparing main loop
      2.5 making dynamical landmask
      0.1 moving elements to ocean
     26.7 readers
        0.2 global_landmask
        0.1 postprocessing
   27.0 main loop
       26.3 https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
      0.0 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.7.1)
        900 active Lagrangian3DArray particles  (0 deactivated, 0 scheduled)
-------------------
Environment variables:
  -----
  sea_floor_depth_below_sea_level
  x_sea_water_velocity
  y_sea_water_velocity
     1) https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
  -----
  land_binary_mask
     1) global_landmask
  -----
Readers not added for the following variables:
  ocean_vertical_diffusivity
  sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment
  sea_surface_wave_period_at_variance_spectral_density_maximum
  sea_surface_wave_significant_height
  sea_surface_wave_stokes_drift_x_velocity
  sea_surface_wave_stokes_drift_y_velocity
  surface_downward_x_stress
  surface_downward_y_stress
  turbulent_generic_length_scale
  turbulent_kinetic_energy
  upward_sea_water_velocity
  x_wind
  y_wind

Time:
        Start: 2018-01-01 00:00:00
        Present: 2018-01-03 00:00:00
        Calculation steps: 48 * 1:00:00 - total time: 2 days, 0:00:00
        Output steps: 49 * 1:00:00
===========================

13:46:34 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_coastline_0.gif...
13:46:34 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
../_images/example_coastline_0.gif

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

Gallery generated by Sphinx-Gallery