Note
Go to the end to download the full example code.
Ship drift
from datetime import datetime
from opendrift.models.shipdrift import ShipDrift
o = ShipDrift(loglevel=20)
o.add_readers_from_list([
'https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml',
'https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc',
'https://thredds.met.no/thredds/dodsC/cmems/mywavewam3km/dataset-wam-arctic-1hr3km-be.ncml'
])
16:09:01 INFO opendrift:579: OpenDriftSimulation initialised (version 1.14.11 / v1.14.12-75-gf9e7122)
Seed ship elements at defined position and time Note: beam/length ratio is larger than allowed, but is then clipped internally
o.seed_elements(lon=5.0, lat=63.0, radius=1000, number=1000,
time=datetime.now(),
length=80.0, beam=20.0, height=9.0, draft=4.0)
16:09:01 WARNING opendrift.models.shipdrift:180: Ratio of beam to length should be in range 0.12 to 0.18, given range is 0.25-0.25. Using border value.
16:09:01 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
16:09:07 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
16:09:07 INFO opendrift.models.basemodel.environment:230: horizontal_diffusivity: 100.000000
16:09:07 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000
16:09:07 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000
16:09:07 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000
16:09:07 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
Running model
o.run(steps=24, stop_on_error=True)
16:09:07 INFO opendrift:1932: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
16:09:07 INFO opendrift:1932: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
16:09:07 INFO opendrift:968: Using existing reader for land_binary_mask to move elements to ocean
16:09:07 INFO opendrift:1000: All points are in ocean
16:09:07 INFO opendrift:2248: 2026-11-12 16:09:01.041743 - step 1 of 24 - 1000 active elements (0 deactivated)
16:09:07 INFO opendrift.readers:67: Opening file with xr.open_dataset
16:09:14 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
16:09:14 INFO opendrift.readers:67: Opening file with xr.open_dataset
16:09:15 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
16:09:15 INFO opendrift.readers:67: Opening file with xr.open_dataset
16:10:02 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
16:10:05 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:05 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:07 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:07 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:11 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:11 INFO opendrift:2248: 2026-11-12 17:09:01.041743 - step 2 of 24 - 1000 active elements (0 deactivated)
16:10:16 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:16 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:18 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:18 INFO opendrift:2248: 2026-11-12 18:09:01.041743 - step 3 of 24 - 1000 active elements (0 deactivated)
16:10:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:23 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:23 INFO opendrift:2248: 2026-11-12 19:09:01.041743 - step 4 of 24 - 1000 active elements (0 deactivated)
16:10:26 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:26 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:28 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:28 INFO opendrift:2248: 2026-11-12 20:09:01.041743 - step 5 of 24 - 1000 active elements (0 deactivated)
16:10:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:32 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:32 INFO opendrift:2248: 2026-11-12 21:09:01.041743 - step 6 of 24 - 1000 active elements (0 deactivated)
16:10:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:36 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:36 INFO opendrift:2248: 2026-11-12 22:09:01.041743 - step 7 of 24 - 1000 active elements (0 deactivated)
16:10:40 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:40 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:41 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:41 INFO opendrift:2248: 2026-11-12 23:09:01.041743 - step 8 of 24 - 1000 active elements (0 deactivated)
16:10:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:47 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:47 INFO opendrift:2248: 2026-11-13 00:09:01.041743 - step 9 of 24 - 1000 active elements (0 deactivated)
16:10:50 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:50 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:51 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:51 INFO opendrift:2248: 2026-11-13 01:09:01.041743 - step 10 of 24 - 1000 active elements (0 deactivated)
16:10:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:55 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:55 INFO opendrift:2248: 2026-11-13 02:09:01.041743 - step 11 of 24 - 1000 active elements (0 deactivated)
16:10:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:10:59 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:10:59 INFO opendrift:2248: 2026-11-13 03:09:01.041743 - step 12 of 24 - 1000 active elements (0 deactivated)
16:11:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:04 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:04 INFO opendrift:2248: 2026-11-13 04:09:01.041743 - step 13 of 24 - 1000 active elements (0 deactivated)
16:11:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:08 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:08 INFO opendrift:2248: 2026-11-13 05:09:01.041743 - step 14 of 24 - 1000 active elements (0 deactivated)
16:11:11 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:11 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:12 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:12 INFO opendrift:2248: 2026-11-13 06:09:01.041743 - step 15 of 24 - 1000 active elements (0 deactivated)
16:11:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:17 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:17 INFO opendrift:2248: 2026-11-13 07:09:01.041743 - step 16 of 24 - 1000 active elements (0 deactivated)
16:11:20 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:20 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:22 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:22 INFO opendrift:2248: 2026-11-13 08:09:01.041743 - step 17 of 24 - 1000 active elements (0 deactivated)
16:11:24 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:24 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:26 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:26 INFO opendrift:2248: 2026-11-13 09:09:01.041743 - step 18 of 24 - 1000 active elements (0 deactivated)
16:11:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:30 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:30 INFO opendrift:2248: 2026-11-13 10:09:01.041743 - step 19 of 24 - 1000 active elements (0 deactivated)
16:11:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:36 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:36 INFO opendrift:2248: 2026-11-13 11:09:01.041743 - step 20 of 24 - 1000 active elements (0 deactivated)
16:11:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:40 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:40 INFO opendrift:2248: 2026-11-13 12:09:01.041743 - step 21 of 24 - 1000 active elements (0 deactivated)
16:11:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:45 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:45 INFO opendrift:2248: 2026-11-13 13:09:01.041743 - step 22 of 24 - 1000 active elements (0 deactivated)
16:11:48 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:48 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:50 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:50 INFO opendrift:2248: 2026-11-13 14:09:01.041743 - step 23 of 24 - 1000 active elements (0 deactivated)
16:11:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:54 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
16:11:54 INFO opendrift:2248: 2026-11-13 15:09:01.041743 - step 24 of 24 - 1000 active elements (0 deactivated)
16:11:57 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:57 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
16:11:59 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
Print and plot results
print(o)
o.plot(linecolor='orientation')
#o.animation(color='orientation', markersize=20, filename="orientation.gif", legend=['left','right'],colorbar=False,cmap='bwr')
o.animation(color='orientation', legend=['left','right'], markersize=20, colorbar=False, cmap='bwr')

===========================
--------------------
Reader performance:
--------------------
global_landmask
0:00:00.0 total
0:00:00.0 preparing
0:00:00.0 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
0:00:54.9 total
0:00:00.0 preparing
0:00:54.9 reading
0:00:00.0 interpolation
0:00:00.0 interpolation_time
0:00:00.0 rotating vectors
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc
0:00:18.4 total
0:00:00.0 preparing
0:00:18.4 reading
0:00:00.2 interpolation
0:00:00.0 interpolation_time
0:00:00.0 rotating vectors
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/cmems/mywavewam3km/dataset-wam-arctic-1hr3km-be.ncml
0:00:42.6 total
0:00:00.0 preparing
0:00:42.6 reading
0:00:00.0 interpolation
0:00:00.0 interpolation_time
0:00:00.0 rotating vectors
0:00:00.0 masking
--------------------
Performance:
2:58.6 total time
6.5 configuration
0.1 preparing main loop
0.0 moving elements to ocean
2:51.8 main loop
0.5 updating elements
0.0 cleaning up
--------------------
===========================
Model: ShipDrift (OpenDrift version 1.14.11)
1000 active ShipObject particles (0 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
land_binary_mask
1) global_landmask
-----
x_sea_water_velocity
y_sea_water_velocity
1) https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml
-----
x_wind
y_wind
1) https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc
-----
sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
1) https://thredds.met.no/thredds/dodsC/cmems/mywavewam3km/dataset-wam-arctic-1hr3km-be.ncml
-----
Readers not added for the following variables:
horizontal_diffusivity
Discarded readers:
Time:
Start: 2026-11-12 16:09:01.041743 UTC
Present: 2026-11-13 16:09:01.041743 UTC
Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
Output steps: 25 * 1:00:00
===========================
16:12:13 INFO opendrift:4899: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
16:12:22 INFO opendrift:3307: Time to make animation: 0:00:11.246553
Total running time of the script: (3 minutes 33.286 seconds)