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'
])
09:38:11 INFO opendrift:507: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-21-g950aeec)
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.utcnow(),
length=80.0, beam=20.0, height=9.0, draft=4.0)
/root/project/examples/example_shipdrift.py:22: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
time=datetime.utcnow(),
09:38:11 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.
09:38:11 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
09:38:17 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
09:38:17 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000
09:38:17 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
09:38:17 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000
09:38:17 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)
09:38:17 INFO opendrift:911: Using existing reader for land_binary_mask
09:38:17 INFO opendrift:940: All points are in ocean
09:38:17 INFO opendrift:2102: 2025-05-28 09:38:11.820217 - step 1 of 24 - 1000 active elements (0 deactivated)
09:38:17 INFO opendrift.readers:61: Opening file with xr.open_dataset
09:38:22 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
09:38:22 INFO opendrift.readers:61: Opening file with xr.open_dataset
09:38:23 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
09:38:23 INFO opendrift.readers:61: Opening file with xr.open_dataset
09:38:28 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
09:38:30 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:30 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:30 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:30 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:32 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:32 INFO opendrift:2102: 2025-05-28 10:38:11.820217 - step 2 of 24 - 1000 active elements (0 deactivated)
09:38:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:34 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:34 INFO opendrift:2102: 2025-05-28 11:38:11.820217 - step 3 of 24 - 1000 active elements (0 deactivated)
09:38:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:36 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:36 INFO opendrift:2102: 2025-05-28 12:38:11.820217 - step 4 of 24 - 1000 active elements (0 deactivated)
09:38:38 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:38 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:38 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:38 INFO opendrift:2102: 2025-05-28 13:38:11.820217 - step 5 of 24 - 1000 active elements (0 deactivated)
09:38:40 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:40 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:40 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:40 INFO opendrift:2102: 2025-05-28 14:38:11.820217 - step 6 of 24 - 1000 active elements (0 deactivated)
09:38:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:43 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:43 INFO opendrift:2102: 2025-05-28 15:38:11.820217 - step 7 of 24 - 1000 active elements (0 deactivated)
09:38:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:45 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:45 INFO opendrift:2102: 2025-05-28 16:38:11.820217 - step 8 of 24 - 1000 active elements (0 deactivated)
09:38:46 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:46 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:47 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:47 INFO opendrift:2102: 2025-05-28 17:38:11.820217 - step 9 of 24 - 1000 active elements (0 deactivated)
09:38:49 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:49 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:49 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:49 INFO opendrift:2102: 2025-05-28 18:38:11.820217 - step 10 of 24 - 1000 active elements (0 deactivated)
09:38:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:51 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:51 INFO opendrift:2102: 2025-05-28 19:38:11.820217 - step 11 of 24 - 1000 active elements (0 deactivated)
09:38:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:53 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:53 INFO opendrift:2102: 2025-05-28 20:38:11.820217 - step 12 of 24 - 1000 active elements (0 deactivated)
09:38:55 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:55 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:56 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:56 INFO opendrift:2102: 2025-05-28 21:38:11.820217 - step 13 of 24 - 1000 active elements (0 deactivated)
09:38:57 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:57 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:58 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:38:58 INFO opendrift:2102: 2025-05-28 22:38:11.820217 - step 14 of 24 - 1000 active elements (0 deactivated)
09:38:59 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:38:59 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:00 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:00 INFO opendrift:2102: 2025-05-28 23:38:11.820217 - step 15 of 24 - 1000 active elements (0 deactivated)
09:39:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:03 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:03 INFO opendrift:2102: 2025-05-29 00:38:11.820217 - step 16 of 24 - 1000 active elements (0 deactivated)
09:39:04 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:04 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:07 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:07 INFO opendrift:2102: 2025-05-29 01:38:11.820217 - step 17 of 24 - 1000 active elements (0 deactivated)
09:39:09 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:09 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:10 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:10 INFO opendrift:2102: 2025-05-29 02:38:11.820217 - step 18 of 24 - 1000 active elements (0 deactivated)
09:39:11 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:11 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:12 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:12 INFO opendrift:2102: 2025-05-29 03:38:11.820217 - step 19 of 24 - 1000 active elements (0 deactivated)
09:39:14 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:14 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:14 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:14 INFO opendrift:2102: 2025-05-29 04:38:11.820217 - step 20 of 24 - 1000 active elements (0 deactivated)
09:39:16 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:16 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:17 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:17 INFO opendrift:2102: 2025-05-29 05:38:11.820217 - step 21 of 24 - 1000 active elements (0 deactivated)
09:39:18 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:18 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:19 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:19 INFO opendrift:2102: 2025-05-29 06:38:11.820217 - step 22 of 24 - 1000 active elements (0 deactivated)
09:39:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:21 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:21 INFO opendrift:2102: 2025-05-29 07:38:11.820217 - step 23 of 24 - 1000 active elements (0 deactivated)
09:39:23 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:23 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:24 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
09:39:24 INFO opendrift:2102: 2025-05-29 08:38:11.820217 - step 24 of 24 - 1000 active elements (0 deactivated)
09:39:26 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:26 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:39:26 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.2 total
0:00:00.0 preparing
0:00:16.2 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:23.1 total
0:00:00.0 preparing
0:00:23.1 reading
0:00:00.3 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:17.6 total
0:00:00.0 preparing
0:00:17.5 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:15.1 total time
5.4 configuration
0.1 preparing main loop
0.0 moving elements to ocean
1:09.5 main loop
0.5 updating elements
0.0 cleaning up
--------------------
===========================
Model: ShipDrift (OpenDrift version 1.14.2)
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-05-28 09:38:11.820217 UTC
Present: 2025-05-29 09:38:11.820217 UTC
Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
Output steps: 25 * 1:00:00
===========================
09:40:21 INFO opendrift:4609: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
09:40:42 INFO opendrift:3062: Time to make animation: 0:00:22.676582

Total running time of the script: (2 minutes 39.260 seconds)