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:19:27 INFO    opendrift:569: OpenDriftSimulation initialised (version 1.14.9 / v1.14.9-61-g2d35ef6)

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)
09:19:27 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.
09:19:27 INFO    opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
09:19:31 INFO    opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
09:19:31 INFO    opendrift.models.basemodel.environment:230:    horizontal_diffusivity: 100.000000
09:19:31 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
09:19:31 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
09:19:31 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_significant_height: 0.000000
09:19:31 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)
09:19:31 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']))
09:19:31 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']))
09:19:31 INFO    opendrift:955: Using existing reader for land_binary_mask to move elements to ocean
09:19:31 INFO    opendrift:986: All points are in ocean
09:19:31 INFO    opendrift:2211: 2026-06-05 09:19:27.108255 - step 1 of 24 - 1000 active elements (0 deactivated)
09:19:31 INFO    opendrift.readers:67: Opening file with xr.open_dataset
09:19:37 INFO    opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
09:19:37 INFO    opendrift.readers:67: Opening file with xr.open_dataset
09:19:38 INFO    opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
09:19:38 INFO    opendrift.readers:67: Opening file with xr.open_dataset
09:19:49 INFO    opendrift.readers.reader_netCDF_CF_generic:340: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
09:19:50 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:50 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:52 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:19:52 INFO    opendrift:2211: 2026-06-05 10:19:27.108255 - step 2 of 24 - 1000 active elements (0 deactivated)
09:19:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:55 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:19:55 INFO    opendrift:2211: 2026-06-05 11:19:27.108255 - step 3 of 24 - 1000 active elements (0 deactivated)
09:19:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:57 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:19:57 INFO    opendrift:2211: 2026-06-05 12:19:27.108255 - step 4 of 24 - 1000 active elements (0 deactivated)
09:19:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:19:59 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:19:59 INFO    opendrift:2211: 2026-06-05 13:19:27.108255 - step 5 of 24 - 1000 active elements (0 deactivated)
09:20:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:02 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:02 INFO    opendrift:2211: 2026-06-05 14:19:27.108255 - step 6 of 24 - 1000 active elements (0 deactivated)
09:20:03 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:03 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:04 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:04 INFO    opendrift:2211: 2026-06-05 15:19:27.108255 - step 7 of 24 - 1000 active elements (0 deactivated)
09:20:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:07 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:07 INFO    opendrift:2211: 2026-06-05 16:19:27.108255 - step 8 of 24 - 1000 active elements (0 deactivated)
09:20:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:09 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:09 INFO    opendrift:2211: 2026-06-05 17:19:27.108255 - step 9 of 24 - 1000 active elements (0 deactivated)
09:20:11 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:11 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:12 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:12 INFO    opendrift:2211: 2026-06-05 18:19:27.108255 - step 10 of 24 - 1000 active elements (0 deactivated)
09:20:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:16 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:16 INFO    opendrift:2211: 2026-06-05 19:19:27.108255 - step 11 of 24 - 1000 active elements (0 deactivated)
09:20:18 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:18 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:19 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:19 INFO    opendrift:2211: 2026-06-05 20:19:27.108255 - step 12 of 24 - 1000 active elements (0 deactivated)
09:20:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:21 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:22 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:22 INFO    opendrift:2211: 2026-06-05 21:19:27.108255 - step 13 of 24 - 1000 active elements (0 deactivated)
09:20:24 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:24 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:25 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:25 INFO    opendrift:2211: 2026-06-05 22:19:27.108255 - step 14 of 24 - 1000 active elements (0 deactivated)
09:20:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:30 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:30 INFO    opendrift:2211: 2026-06-05 23:19:27.108255 - step 15 of 24 - 1000 active elements (0 deactivated)
09:20:32 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:32 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:33 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:33 INFO    opendrift:2211: 2026-06-06 00:19:27.108255 - step 16 of 24 - 1000 active elements (0 deactivated)
09:20:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:35 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:36 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:36 INFO    opendrift:2211: 2026-06-06 01:19:27.108255 - step 17 of 24 - 1000 active elements (0 deactivated)
09:20:38 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:38 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:39 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:39 INFO    opendrift:2211: 2026-06-06 02:19:27.108255 - step 18 of 24 - 1000 active elements (0 deactivated)
09:20:41 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:41 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:43 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:43 INFO    opendrift:2211: 2026-06-06 03:19:27.108255 - step 19 of 24 - 1000 active elements (0 deactivated)
09:20:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:49 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:49 INFO    opendrift:2211: 2026-06-06 04:19:27.108255 - step 20 of 24 - 1000 active elements (0 deactivated)
09:20:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:51 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:51 INFO    opendrift:2211: 2026-06-06 05:19:27.108255 - step 21 of 24 - 1000 active elements (0 deactivated)
09:20:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:54 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:54 INFO    opendrift:2211: 2026-06-06 06:19:27.108255 - step 22 of 24 - 1000 active elements (0 deactivated)
09:20:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:57 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:20:57 INFO    opendrift:2211: 2026-06-06 07:19:27.108255 - step 23 of 24 - 1000 active elements (0 deactivated)
09:20:59 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:20:59 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:21:00 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
09:21:00 INFO    opendrift:2211: 2026-06-06 08:19:27.108255 - step 24 of 24 - 1000 active elements (0 deactivated)
09:21:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:21:02 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
09:21:03 INFO    opendrift.models.shipdrift:310: Using Stokes drift direction as wave direction
<xarray.Dataset> Size: 3MB
Dimensions:                                                                              (
                                                                                          trajectory: 1000,
                                                                                          time: 25)
Coordinates:
  * trajectory                                                                           (trajectory) int64 8kB ...
  * time                                                                                 (time) datetime64[ns] 200B ...
Data variables: (12/25)
    status                                                                               (trajectory, time) float32 100kB ...
    moving                                                                               (trajectory, time) float32 100kB ...
    age_seconds                                                                          (trajectory, time) float32 100kB ...
    origin_marker                                                                        (trajectory, time) float32 100kB ...
    lon                                                                                  (trajectory, time) float32 100kB ...
    lat                                                                                  (trajectory, time) float32 100kB ...
    ...                                                                                   ...
    y_sea_water_velocity                                                                 (trajectory, time) float32 100kB ...
    horizontal_diffusivity                                                               (trajectory, time) float32 100kB ...
    sea_surface_wave_stokes_drift_x_velocity                                             (trajectory, time) float32 100kB ...
    sea_surface_wave_stokes_drift_y_velocity                                             (trajectory, time) float32 100kB ...
    sea_surface_wave_significant_height                                                  (trajectory, time) float32 100kB ...
    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment  (trajectory, time) float32 100kB ...
Attributes: (12/98)
    Conventions:                                                             ...
    standard_name_vocabulary:                                                ...
    featureType:                                                             ...
    title:                                                                   ...
    summary:                                                                 ...
    keywords:                                                                ...
    ...                                                                                                               ...
    geospatial_lon_units:                                                    ...
    geospatial_lon_resolution:                                               ...
    runtime:                                                                 ...
    geospatial_vertical_min:                                                 ...
    geospatial_vertical_max:                                                 ...
    geospatial_vertical_positive:                                            ...


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')
OpenDrift - ShipDrift 2026-06-05 09:19 to 2026-06-06 09:19 UTC (25 steps)
===========================
--------------------
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:28.5  total
 0:00:00.0  preparing
 0:00:28.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:20.6  total
 0:00:00.0  preparing
 0:00:20.5  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:23.7  total
 0:00:00.0  preparing
 0:00:23.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:
 1:36.3 total time
    3.9 configuration
    0.0 preparing main loop
      0.0 moving elements to ocean
 1:32.4 main loop
      0.5 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  ShipDrift     (OpenDrift version 1.14.9)
        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
  -----
Readers not added for the following variables:
  horizontal_diffusivity

Discarded readers:

Time:
        Start: 2026-06-05 09:19:27.108255 UTC
        Present: 2026-06-06 09:19:27.108255 UTC
        Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
        Output steps: 25 * 1:00:00
===========================

09:21:19 INFO    opendrift:4777: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
09:21:37 INFO    opendrift:3200: Time to make animation: 0:00:19.187953
../_images/example_shipdrift_0.gif

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

Gallery generated by Sphinx-Gallery