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'
    ])
21:56:07 INFO    opendrift:509: OpenDriftSimulation initialised (version 1.13.0 / v1.13.0-61-gf300067)

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)
21:56:07 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.
21:56:07 INFO    opendrift.models.basemodel.environment:206: Adding a dynamical landmask with max. priority based on assumed maximum speed of 2.0 m/s. Adding a customised landmask may be faster...
21:56:11 INFO    opendrift.models.basemodel.environment:233: Fallback values will be used for the following variables which have no readers:
21:56:11 INFO    opendrift.models.basemodel.environment:236:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
21:56:11 INFO    opendrift.models.basemodel.environment:236:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
21:56:11 INFO    opendrift.models.basemodel.environment:236:    sea_surface_wave_significant_height: 0.000000
21:56:11 INFO    opendrift.models.basemodel.environment:236:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000

Running model

o.run(steps=24, stop_on_error=True)
21:56:11 INFO    opendrift:919: Using existing reader for land_binary_mask
21:56:11 INFO    opendrift:930: All points are in ocean
21:56:11 INFO    opendrift:2056: 2025-03-05 21:56:07.344141 - step 1 of 24 - 1000 active elements (0 deactivated)
21:56:11 INFO    opendrift.readers:58: Opening file with xr.open_dataset
21:56:14 INFO    opendrift.readers.reader_netCDF_CF_generic:338: Detected dimensions: {'x': 'x', 'y': 'y', 'time': 'time'}
21:56:14 INFO    opendrift.readers:58: Opening file with xr.open_dataset
21:56:15 INFO    opendrift.readers.reader_netCDF_CF_generic:338: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
21:56:15 INFO    opendrift.readers:58: Opening file with xr.open_dataset
21:56:16 INFO    opendrift.readers.reader_netCDF_CF_generic:338: Detected dimensions: {'y': 'rlat', 'x': 'rlon', 'time': 'time'}
21:56:18 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:18 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:19 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:19 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:21 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:21 INFO    opendrift:2056: 2025-03-05 22:56:07.344141 - step 2 of 24 - 1000 active elements (0 deactivated)
21:56:22 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:22 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:23 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:23 INFO    opendrift:2056: 2025-03-05 23:56:07.344141 - step 3 of 24 - 1000 active elements (0 deactivated)
21:56:26 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:26 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:27 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:27 INFO    opendrift:2056: 2025-03-06 00:56:07.344141 - step 4 of 24 - 1000 active elements (0 deactivated)
21:56:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:29 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:29 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:29 INFO    opendrift:2056: 2025-03-06 01:56:07.344141 - step 5 of 24 - 1000 active elements (0 deactivated)
21:56:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:31 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:32 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:32 INFO    opendrift:2056: 2025-03-06 02:56:07.344141 - step 6 of 24 - 1000 active elements (0 deactivated)
21:56:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:33 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:34 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:34 INFO    opendrift:2056: 2025-03-06 03:56:07.344141 - step 7 of 24 - 1000 active elements (0 deactivated)
21:56:36 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:36 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:37 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:37 INFO    opendrift:2056: 2025-03-06 04:56:07.344141 - step 8 of 24 - 1000 active elements (0 deactivated)
21:56:38 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:38 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:39 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:39 INFO    opendrift:2056: 2025-03-06 05:56:07.344141 - step 9 of 24 - 1000 active elements (0 deactivated)
21:56:40 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:40 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:41 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:41 INFO    opendrift:2056: 2025-03-06 06:56:07.344141 - step 10 of 24 - 1000 active elements (0 deactivated)
21:56:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:42 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:43 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:43 INFO    opendrift:2056: 2025-03-06 07:56:07.344141 - step 11 of 24 - 1000 active elements (0 deactivated)
21:56:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:44 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:45 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:45 INFO    opendrift:2056: 2025-03-06 08:56:07.344141 - step 12 of 24 - 1000 active elements (0 deactivated)
21:56:46 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:46 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:47 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:47 INFO    opendrift:2056: 2025-03-06 09:56:07.344141 - step 13 of 24 - 1000 active elements (0 deactivated)
21:56:49 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:49 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:50 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:50 INFO    opendrift:2056: 2025-03-06 10:56:07.344141 - step 14 of 24 - 1000 active elements (0 deactivated)
21:56:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:51 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:52 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:52 INFO    opendrift:2056: 2025-03-06 11:56:07.344141 - step 15 of 24 - 1000 active elements (0 deactivated)
21:56:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:54 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:55 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:55 INFO    opendrift:2056: 2025-03-06 12:56:07.344141 - step 16 of 24 - 1000 active elements (0 deactivated)
21:56:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:56 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:57 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:56:57 INFO    opendrift:2056: 2025-03-06 13:56:07.344141 - step 17 of 24 - 1000 active elements (0 deactivated)
21:56:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:56:58 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:00 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:57:00 INFO    opendrift:2056: 2025-03-06 14:56:07.344141 - step 18 of 24 - 1000 active elements (0 deactivated)
21:57:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:01 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:02 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:57:02 INFO    opendrift:2056: 2025-03-06 15:56:07.344141 - step 19 of 24 - 1000 active elements (0 deactivated)
21:57:03 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:03 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:04 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:57:04 INFO    opendrift:2056: 2025-03-06 16:56:07.344141 - step 20 of 24 - 1000 active elements (0 deactivated)
21:57:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:06 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:07 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:57:07 INFO    opendrift:2056: 2025-03-06 17:56:07.344141 - step 21 of 24 - 1000 active elements (0 deactivated)
21:57:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:08 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:09 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:57:09 INFO    opendrift:2056: 2025-03-06 18:56:07.344141 - step 22 of 24 - 1000 active elements (0 deactivated)
21:57:10 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:10 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:11 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:57:11 INFO    opendrift:2056: 2025-03-06 19:56:07.344141 - step 23 of 24 - 1000 active elements (0 deactivated)
21:57:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:12 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:13 INFO    opendrift.models.shipdrift:311: Using Stokes drift direction as wave direction
21:57:13 INFO    opendrift:2056: 2025-03-06 20:56:07.344141 - step 24 of 24 - 1000 active elements (0 deactivated)
21:57:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:15 WARNING opendrift.readers.interpolation.structured:63: Ensemble data currently not extrapolated towards seafloor
21:57:16 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-03-05 21:56 to 2025-03-06 21:56 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:16.3  total
 0:00:00.0  preparing
 0:00:16.1  reading
 0:00:00.0  interpolation
 0:00:00.0  interpolation_time
 0:00:00.2  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.8  total
 0:00:00.0  preparing
 0:00:22.6  reading
 0:00:00.3  interpolation
 0:00:00.0  interpolation_time
 0:00:00.2  rotating vectors
 0:00:00.0  masking
--------------------
https://thredds.met.no/thredds/dodsC/cmems/mywavewam3km/dataset-wam-arctic-1hr3km-be.ncml
 0:00:18.7  total
 0:00:00.0  preparing
 0:00:18.4  reading
 0:00:00.0  interpolation
 0:00:00.0  interpolation_time
 0:00:00.2  rotating vectors
 0:00:00.0  masking
--------------------
Performance:
 1:08.7 total time
    4.3 configuration
    0.0 preparing main loop
      0.0 moving elements to ocean
 1:04.3 main loop
      0.6 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  ShipDrift     (OpenDrift version 1.13.0)
        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-03-05 21:56:07.344141 UTC
        Present: 2025-03-06 21:56:07.344141 UTC
        Calculation steps: 24 * 1:00:00 - total time: 1 day, 0:00:00
        Output steps: 25 * 1:00:00
===========================

21:57:49 INFO    opendrift:4600: Saving animation to /root/project/docs/source/gallery/animations/example_shipdrift_0.gif...
21:58:04 INFO    opendrift:3036: Time to make animation: 0:00:15.837047
../_images/example_shipdrift_0.gif

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

Gallery generated by Sphinx-Gallery