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'
])
11:28:51 INFO opendrift:507: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-23-g09d0c2d)
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(),
11:28:51 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.
11:28:51 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
11:28:55 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
11:28:55 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000
11:28:55 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
11:28:55 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000
11:28:55 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)
11:28:55 INFO opendrift:911: Using existing reader for land_binary_mask
11:28:55 INFO opendrift:940: All points are in ocean
11:28:55 INFO opendrift:2102: 2025-05-28 11:28:51.618985 - step 1 of 24 - 1000 active elements (0 deactivated)
11:28:55 INFO opendrift.readers:61: Opening file with xr.open_dataset
11:28:57 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
11:28:57 INFO opendrift.readers:61: Opening file with xr.open_dataset
11:28:58 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
11:28:58 INFO opendrift.readers:61: Opening file with xr.open_dataset
11:28:59 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
11:29:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:01 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:01 INFO opendrift:2102: 2025-05-28 12:28:51.618985 - step 2 of 24 - 1000 active elements (0 deactivated)
11:29:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:05 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:05 INFO opendrift:2102: 2025-05-28 13:28:51.618985 - step 3 of 24 - 1000 active elements (0 deactivated)
11:29:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:06 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:06 INFO opendrift:2102: 2025-05-28 14:28:51.618985 - step 4 of 24 - 1000 active elements (0 deactivated)
11:29:13 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:13 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:14 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:14 INFO opendrift:2102: 2025-05-28 15:28:51.618985 - step 5 of 24 - 1000 active elements (0 deactivated)
11:29:14 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:14 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:15 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:15 INFO opendrift:2102: 2025-05-28 16:28:51.618985 - step 6 of 24 - 1000 active elements (0 deactivated)
11:29:16 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:16 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:17 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:17 INFO opendrift:2102: 2025-05-28 17:28:51.618985 - step 7 of 24 - 1000 active elements (0 deactivated)
11:29:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:18 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:18 INFO opendrift:2102: 2025-05-28 18:28:51.618985 - step 8 of 24 - 1000 active elements (0 deactivated)
11:29:19 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:19 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:20 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:20 INFO opendrift:2102: 2025-05-28 19:28:51.618985 - step 9 of 24 - 1000 active elements (0 deactivated)
11:29:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:21 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:21 INFO opendrift:2102: 2025-05-28 20:28:51.618985 - step 10 of 24 - 1000 active elements (0 deactivated)
11:29:22 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:22 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:23 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:23 INFO opendrift:2102: 2025-05-28 21:28:51.618985 - step 11 of 24 - 1000 active elements (0 deactivated)
11:29:24 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:24 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:24 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:24 INFO opendrift:2102: 2025-05-28 22:28:51.618985 - step 12 of 24 - 1000 active elements (0 deactivated)
11:29:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:26 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:26 INFO opendrift:2102: 2025-05-28 23:28:51.618985 - step 13 of 24 - 1000 active elements (0 deactivated)
11:29:28 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:28 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:29 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:29 INFO opendrift:2102: 2025-05-29 00:28:51.618985 - step 14 of 24 - 1000 active elements (0 deactivated)
11:29:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:32 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:32 INFO opendrift:2102: 2025-05-29 01:28:51.618985 - step 15 of 24 - 1000 active elements (0 deactivated)
11:29:34 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:34 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:35 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:35 INFO opendrift:2102: 2025-05-29 02:28:51.618985 - step 16 of 24 - 1000 active elements (0 deactivated)
11:29:37 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:37 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:38 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:38 INFO opendrift:2102: 2025-05-29 03:28:51.618985 - step 17 of 24 - 1000 active elements (0 deactivated)
11:29:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:40 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:40 INFO opendrift:2102: 2025-05-29 04:28:51.618985 - step 18 of 24 - 1000 active elements (0 deactivated)
11:29:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:43 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:43 INFO opendrift:2102: 2025-05-29 05:28:51.618985 - step 19 of 24 - 1000 active elements (0 deactivated)
11:29:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:45 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:46 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:46 INFO opendrift:2102: 2025-05-29 06:28:51.618985 - step 20 of 24 - 1000 active elements (0 deactivated)
11:29:48 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:48 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:49 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:49 INFO opendrift:2102: 2025-05-29 07:28:51.618985 - step 21 of 24 - 1000 active elements (0 deactivated)
11:29:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:52 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:52 INFO opendrift:2102: 2025-05-29 08:28:51.618985 - step 22 of 24 - 1000 active elements (0 deactivated)
11:29:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:55 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:55 INFO opendrift:2102: 2025-05-29 09:28:51.618985 - step 23 of 24 - 1000 active elements (0 deactivated)
11:29:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:29:57 INFO opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
11:29:57 INFO opendrift:2102: 2025-05-29 10:28:51.618985 - step 24 of 24 - 1000 active elements (0 deactivated)
11:30:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:30:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
11:30:00 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:19.0 total
0:00:00.0 preparing
0:00:18.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:22.4 total
0:00:00.0 preparing
0:00:22.3 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:18.8 total
0:00:00.0 preparing
0:00:18.7 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:09.3 total time
3.9 configuration
0.0 preparing main loop
0.0 moving elements to ocean
1:05.3 main loop
0.4 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 11:28:51.618985 UTC
Present: 2025-05-29 11:28:51.618985 UTC
Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
Output steps: 25 * 1:00:00
===========================
11:30:39 INFO opendrift:4609: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
11:31:01 INFO opendrift:3062: Time to make animation: 0:00:23.459856

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