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:22:32 INFO opendrift:568: OpenDriftSimulation initialised (version 1.14.3 / v1.14.3-2-g7a367c6)
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:22:32 WARNING opendrift.models.shipdrift:181: 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:22:32 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
13:22:35 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
13:22:35 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:22:35 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:22:35 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000
13:22:35 INFO opendrift.models.basemodel.environment:232: 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:22:35 INFO opendrift:1789: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:22:35 INFO opendrift:1789: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
13:22:36 INFO opendrift:944: Using existing reader for land_binary_mask to move elements to ocean
13:22:36 INFO opendrift:974: All points are in ocean
13:22:36 INFO opendrift:2085: 2025-09-01 13:22:32.009523 - step 1 of 24 - 1000 active elements (0 deactivated)
13:22:36 INFO opendrift.readers:61: Opening file with xr.open_dataset
13:22:37 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
13:22:37 INFO opendrift.readers:61: Opening file with xr.open_dataset
13:22:38 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
13:22:38 INFO opendrift.readers:61: Opening file with xr.open_dataset
13:22:41 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
13:22:43 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:43 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:47 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:22:47 INFO opendrift:2085: 2025-09-01 14:22:32.009523 - step 2 of 24 - 1000 active elements (0 deactivated)
13:22:49 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:49 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:49 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:22:49 INFO opendrift:2085: 2025-09-01 15:22:32.009523 - step 3 of 24 - 1000 active elements (0 deactivated)
13:22:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:52 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:22:52 INFO opendrift:2085: 2025-09-01 16:22:32.009523 - step 4 of 24 - 1000 active elements (0 deactivated)
13:22:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:54 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:22:54 INFO opendrift:2085: 2025-09-01 17:22:32.009523 - step 5 of 24 - 1000 active elements (0 deactivated)
13:22:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:57 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:22:57 INFO opendrift:2085: 2025-09-01 18:22:32.009523 - step 6 of 24 - 1000 active elements (0 deactivated)
13:22:59 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:22:59 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:00 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:00 INFO opendrift:2085: 2025-09-01 19:22:32.009523 - step 7 of 24 - 1000 active elements (0 deactivated)
13:23:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:02 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:02 INFO opendrift:2085: 2025-09-01 20:22:32.009523 - step 8 of 24 - 1000 active elements (0 deactivated)
13:23:04 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:04 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:05 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:05 INFO opendrift:2085: 2025-09-01 21:22:32.009523 - step 9 of 24 - 1000 active elements (0 deactivated)
13:23:07 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:07 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:07 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:07 INFO opendrift:2085: 2025-09-01 22:22:32.009523 - step 10 of 24 - 1000 active elements (0 deactivated)
13:23:09 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:09 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:10 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:10 INFO opendrift:2085: 2025-09-01 23:22:32.009523 - step 11 of 24 - 1000 active elements (0 deactivated)
13:23:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:13 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:13 INFO opendrift:2085: 2025-09-02 00:22:32.009523 - step 12 of 24 - 1000 active elements (0 deactivated)
13:23:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:15 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:15 INFO opendrift:2085: 2025-09-02 01:22:32.009523 - step 13 of 24 - 1000 active elements (0 deactivated)
13:23:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:18 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:18 INFO opendrift:2085: 2025-09-02 02:22:32.009523 - step 14 of 24 - 1000 active elements (0 deactivated)
13:23:20 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:20 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:21 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:21 INFO opendrift:2085: 2025-09-02 03:22:32.009523 - step 15 of 24 - 1000 active elements (0 deactivated)
13:23:22 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:22 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:23 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:23 INFO opendrift:2085: 2025-09-02 04:22:32.009523 - step 16 of 24 - 1000 active elements (0 deactivated)
13:23:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:25 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:25 INFO opendrift:2085: 2025-09-02 05:22:32.009523 - step 17 of 24 - 1000 active elements (0 deactivated)
13:23:27 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:27 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:28 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:28 INFO opendrift:2085: 2025-09-02 06:22:32.009523 - step 18 of 24 - 1000 active elements (0 deactivated)
13:23:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:30 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:30 INFO opendrift:2085: 2025-09-02 07:22:32.009523 - step 19 of 24 - 1000 active elements (0 deactivated)
13:23:32 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:32 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:33 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:33 INFO opendrift:2085: 2025-09-02 08:22:32.009523 - step 20 of 24 - 1000 active elements (0 deactivated)
13:23:34 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:34 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:35 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:35 INFO opendrift:2085: 2025-09-02 09:22:32.009523 - step 21 of 24 - 1000 active elements (0 deactivated)
13:23:37 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:37 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:38 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:38 INFO opendrift:2085: 2025-09-02 10:22:32.009523 - step 22 of 24 - 1000 active elements (0 deactivated)
13:23:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:40 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:40 INFO opendrift:2085: 2025-09-02 11:22:32.009523 - step 23 of 24 - 1000 active elements (0 deactivated)
13:23:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:43 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
13:23:43 INFO opendrift:2085: 2025-09-02 12:22:32.009523 - step 24 of 24 - 1000 active elements (0 deactivated)
13:23:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
13:23:46 INFO opendrift.models.shipdrift:311: 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.6 total
0:00:00.0 preparing
0:00:16.5 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:28.3 total
0:00:00.0 preparing
0:00:28.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:19.4 total
0:00:00.0 preparing
0:00:19.4 reading
0:00:00.0 interpolation
0:00:00.0 interpolation_time
0:00:00.0 rotating vectors
0:00:00.0 masking
--------------------
Performance:
1:14.4 total time
3.9 configuration
0.0 preparing main loop
0.0 moving elements to ocean
1:10.4 main loop
0.3 updating elements
0.0 cleaning up
--------------------
===========================
Model: ShipDrift (OpenDrift version 1.14.3)
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
2) https://thredds.met.no/thredds/dodsC/cmems/mywavewam3km/dataset-wam-arctic-1hr3km-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
Discarded readers:
Time:
Start: 2025-09-01 13:22:32.009523 UTC
Present: 2025-09-02 13:22:32.009523 UTC
Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
Output steps: 25 * 1:00:00
===========================
13:23:59 INFO opendrift:4609: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
13:24:13 INFO opendrift:3050: Time to make animation: 0:00:14.447529

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