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'
])
13:24:51 INFO opendrift:569: OpenDriftSimulation initialised (version 1.14.10 / v1.14.10-27-gff3ada1)
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)
13:24:51 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.
13:24:51 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
13:24:55 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
13:24:55 INFO opendrift.models.basemodel.environment:230: horizontal_diffusivity: 100.000000
13:24:55 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:24:55 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:24:55 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000
13:24:55 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)
13:24:55 INFO opendrift:1914: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:24:55 INFO opendrift:1914: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:24:56 INFO opendrift:955: Using existing reader for land_binary_mask to move elements to ocean
13:24:56 INFO opendrift:986: All points are in ocean
13:24:56 INFO opendrift:2211: 2026-07-14 13:24:51.860577 - step 1 of 24 - 1000 active elements (0 deactivated)
13:24:56 INFO opendrift.readers:67: Opening file with xr.open_dataset
13:24:58 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
13:24:58 INFO opendrift.readers:67: Opening file with xr.open_dataset
13:24:59 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
13:24:59 INFO opendrift.readers:67: Opening file with xr.open_dataset
13:25:00 INFO opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
13:25:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:03 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:03 INFO opendrift:2211: 2026-07-14 14:24:51.860577 - step 2 of 24 - 1000 active elements (0 deactivated)
13:25:04 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:04 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:05 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:05 INFO opendrift:2211: 2026-07-14 15:24:51.860577 - step 3 of 24 - 1000 active elements (0 deactivated)
13:25:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:07 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:07 INFO opendrift:2211: 2026-07-14 16:24:51.860577 - step 4 of 24 - 1000 active elements (0 deactivated)
13:25:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:09 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:09 INFO opendrift:2211: 2026-07-14 17:24:51.860577 - step 5 of 24 - 1000 active elements (0 deactivated)
13:25:10 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:10 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:10 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:10 INFO opendrift:2211: 2026-07-14 18:24:51.860577 - step 6 of 24 - 1000 active elements (0 deactivated)
13:25:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:12 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:12 INFO opendrift:2211: 2026-07-14 19:24:51.860577 - step 7 of 24 - 1000 active elements (0 deactivated)
13:25:13 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:13 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:14 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:14 INFO opendrift:2211: 2026-07-14 20:24:51.860577 - step 8 of 24 - 1000 active elements (0 deactivated)
13:25:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:16 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:16 INFO opendrift:2211: 2026-07-14 21:24:51.860577 - step 9 of 24 - 1000 active elements (0 deactivated)
13:25:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:18 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:18 INFO opendrift:2211: 2026-07-14 22:24:51.860577 - step 10 of 24 - 1000 active elements (0 deactivated)
13:25:19 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:19 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:20 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:20 INFO opendrift:2211: 2026-07-14 23:24:51.860577 - step 11 of 24 - 1000 active elements (0 deactivated)
13:25:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:22 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:22 INFO opendrift:2211: 2026-07-15 00:24:51.860577 - step 12 of 24 - 1000 active elements (0 deactivated)
13:25:23 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:23 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:24 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:24 INFO opendrift:2211: 2026-07-15 01:24:51.860577 - step 13 of 24 - 1000 active elements (0 deactivated)
13:25:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:26 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:26 INFO opendrift:2211: 2026-07-15 02:24:51.860577 - step 14 of 24 - 1000 active elements (0 deactivated)
13:25:27 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:27 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:27 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:27 INFO opendrift:2211: 2026-07-15 03:24:51.860577 - step 15 of 24 - 1000 active elements (0 deactivated)
13:25:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:29 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:29 INFO opendrift:2211: 2026-07-15 04:24:51.860577 - step 16 of 24 - 1000 active elements (0 deactivated)
13:25:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:31 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:31 INFO opendrift:2211: 2026-07-15 05:24:51.860577 - step 17 of 24 - 1000 active elements (0 deactivated)
13:25:32 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:32 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:33 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:33 INFO opendrift:2211: 2026-07-15 06:24:51.860577 - step 18 of 24 - 1000 active elements (0 deactivated)
13:25:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:36 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:36 INFO opendrift:2211: 2026-07-15 07:24:51.860577 - step 19 of 24 - 1000 active elements (0 deactivated)
13:25:37 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:37 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:38 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:38 INFO opendrift:2211: 2026-07-15 08:24:51.860577 - step 20 of 24 - 1000 active elements (0 deactivated)
13:25:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:40 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:40 INFO opendrift:2211: 2026-07-15 09:24:51.860577 - step 21 of 24 - 1000 active elements (0 deactivated)
13:25:41 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:41 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:42 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:42 INFO opendrift:2211: 2026-07-15 10:24:51.860577 - step 22 of 24 - 1000 active elements (0 deactivated)
13:25:43 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:43 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:44 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:44 INFO opendrift:2211: 2026-07-15 11:24:51.860577 - step 23 of 24 - 1000 active elements (0 deactivated)
13:25:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:46 INFO opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
13:25:46 INFO opendrift:2211: 2026-07-15 12:24:51.860577 - step 24 of 24 - 1000 active elements (0 deactivated)
13:25:47 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:47 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:25:48 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:16.4 total
0:00:00.0 preparing
0:00:16.4 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:14.2 total
0:00:00.0 preparing
0:00:14.2 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:15.9 total
0:00:00.0 preparing
0:00:15.9 reading
0:00:00.0 interpolation
0:00:00.0 interpolation_time
0:00:00.0 rotating vectors
0:00:00.0 masking
--------------------
Performance:
56.5 total time
4.1 configuration
0.1 preparing main loop
0.0 moving elements to ocean
52.2 main loop
0.4 updating elements
0.0 cleaning up
--------------------
===========================
Model: ShipDrift (OpenDrift version 1.14.10)
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-07-14 13:24:51.860577 UTC
Present: 2026-07-15 13:24:51.860577 UTC
Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
Output steps: 25 * 1:00:00
===========================
13:26:01 INFO opendrift:4795: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
13:26:08 INFO opendrift:3215: Time to make animation: 0:00:08.273554
Total running time of the script: (1 minutes 24.351 seconds)