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'
    ])
14:40:38 INFO    opendrift:576: OpenDriftSimulation initialised (version 1.14.6 / v1.14.6-9-geaa6ee2)

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)
14:40:38 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.
14:40:38 INFO    opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
14:40:42 INFO    opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
14:40:42 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
14:40:42 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
14:40:42 INFO    opendrift.models.basemodel.environment:230:    sea_surface_wave_significant_height: 0.000000
14:40:42 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)
14:40:42 INFO    opendrift:1805: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:40:42 INFO    opendrift:1805: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:40:42 INFO    opendrift:952: Using existing reader for land_binary_mask to move elements to ocean
14:40:42 INFO    opendrift:982: All points are in ocean
14:40:42 INFO    opendrift:2101: 2025-11-10 14:40:38.020039 - step 1 of 24 - 1000 active elements (0 deactivated)
14:40:42 INFO    opendrift.readers:63: Opening file with xr.open_dataset
14:40:44 INFO    opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
14:40:44 INFO    opendrift.readers:63: Opening file with xr.open_dataset
14:40:45 INFO    opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
14:40:45 INFO    opendrift.readers:63: Opening file with xr.open_dataset
14:40:47 INFO    opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
14:40:47 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:47 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:48 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:48 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:49 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:49 INFO    opendrift:2101: 2025-11-10 15:40:38.020039 - step 2 of 24 - 1000 active elements (0 deactivated)
14:40:50 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:50 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:50 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:50 INFO    opendrift:2101: 2025-11-10 16:40:38.020039 - step 3 of 24 - 1000 active elements (0 deactivated)
14:40:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:52 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:52 INFO    opendrift:2101: 2025-11-10 17:40:38.020039 - step 4 of 24 - 1000 active elements (0 deactivated)
14:40:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:53 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:53 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:53 INFO    opendrift:2101: 2025-11-10 18:40:38.020039 - step 5 of 24 - 1000 active elements (0 deactivated)
14:40:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:55 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:55 INFO    opendrift:2101: 2025-11-10 19:40:38.020039 - step 6 of 24 - 1000 active elements (0 deactivated)
14:40:55 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:55 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:56 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:56 INFO    opendrift:2101: 2025-11-10 20:40:38.020039 - step 7 of 24 - 1000 active elements (0 deactivated)
14:40:57 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:57 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:58 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:58 INFO    opendrift:2101: 2025-11-10 21:40:38.020039 - step 8 of 24 - 1000 active elements (0 deactivated)
14:40:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:40:59 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:40:59 INFO    opendrift:2101: 2025-11-10 22:40:38.020039 - step 9 of 24 - 1000 active elements (0 deactivated)
14:41:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:00 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:01 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:01 INFO    opendrift:2101: 2025-11-10 23:40:38.020039 - step 10 of 24 - 1000 active elements (0 deactivated)
14:41:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:02 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:02 INFO    opendrift:2101: 2025-11-11 00:40:38.020039 - step 11 of 24 - 1000 active elements (0 deactivated)
14:41:03 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:03 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:04 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:04 INFO    opendrift:2101: 2025-11-11 01:40:38.020039 - step 12 of 24 - 1000 active elements (0 deactivated)
14:41:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:07 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:07 INFO    opendrift:2101: 2025-11-11 02:40:38.020039 - step 13 of 24 - 1000 active elements (0 deactivated)
14:41:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:09 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:09 INFO    opendrift:2101: 2025-11-11 03:40:38.020039 - step 14 of 24 - 1000 active elements (0 deactivated)
14:41:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:12 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:12 INFO    opendrift:2101: 2025-11-11 04:40:38.020039 - step 15 of 24 - 1000 active elements (0 deactivated)
14:41:14 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:14 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:15 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:15 INFO    opendrift:2101: 2025-11-11 05:40:38.020039 - step 16 of 24 - 1000 active elements (0 deactivated)
14:41:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:17 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:18 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:18 INFO    opendrift:2101: 2025-11-11 06:40:38.020039 - step 17 of 24 - 1000 active elements (0 deactivated)
14:41:20 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:20 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:21 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:21 INFO    opendrift:2101: 2025-11-11 07:40:38.020039 - step 18 of 24 - 1000 active elements (0 deactivated)
14:41:23 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:23 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:23 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:23 INFO    opendrift:2101: 2025-11-11 08:40:38.020039 - step 19 of 24 - 1000 active elements (0 deactivated)
14:41:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:25 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:26 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:26 INFO    opendrift:2101: 2025-11-11 09:40:38.020039 - step 20 of 24 - 1000 active elements (0 deactivated)
14:41:28 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:28 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:29 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:29 INFO    opendrift:2101: 2025-11-11 10:40:38.020039 - step 21 of 24 - 1000 active elements (0 deactivated)
14:41:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:32 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:32 INFO    opendrift:2101: 2025-11-11 11:40:38.020039 - step 22 of 24 - 1000 active elements (0 deactivated)
14:41:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:34 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:34 INFO    opendrift:2101: 2025-11-11 12:40:38.020039 - step 23 of 24 - 1000 active elements (0 deactivated)
14:41:36 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:36 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:37 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
14:41:37 INFO    opendrift:2101: 2025-11-11 13:40:38.020039 - step 24 of 24 - 1000 active elements (0 deactivated)
14:41:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:39 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
14:41:40 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
<xarray.Dataset> Size: 2MB
Dimensions:                                                                              (
                                                                                          trajectory: 1000,
                                                                                          time: 25)
Coordinates:
  * trajectory                                                                           (trajectory) int64 8kB ...
  * time                                                                                 (time) datetime64[ns] 200B ...
Data variables: (12/24)
    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 ...
    ...                                                                                   ...
    x_sea_water_velocity                                                                 (trajectory, time) float32 100kB ...
    y_sea_water_velocity                                                                 (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/96)
    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 2025-11-10 14:40 to 2025-11-11 14:40 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:14.7  total
 0:00:00.0  preparing
 0:00:14.6  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:21.0  total
 0:00:00.0  preparing
 0:00:21.0  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:16.4  total
 0:00:00.0  preparing
 0:00:16.3  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:02.5 total time
    4.3 configuration
    0.0 preparing main loop
      0.0 moving elements to ocean
   58.1 main loop
      0.4 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  ShipDrift     (OpenDrift version 1.14.6)
        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-11-10 14:40:38.020039 UTC
        Present: 2025-11-11 14:40:38.020039 UTC
        Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
        Output steps: 25 * 1:00:00
===========================

14:42:05 INFO    opendrift:4636: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
14:42:22 INFO    opendrift:3071: Time to make animation: 0:00:17.867209
../_images/example_shipdrift_0.gif

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

Gallery generated by Sphinx-Gallery