Note
Go to the end to download the full example code.
Static 2D current field
from datetime import datetime, timedelta
import numpy as np
from opendrift.readers.reader_constant_2d import Reader
from opendrift.models.oceandrift import OceanDrift
Constructing a static, rotating ocean current field,
lon, lat = np.meshgrid(np.linspace(2,6,30), np.linspace(59,62,30))
lon0 = 4
lat0 = 60.5
u = -(lat-lat0)/np.sqrt((lon-lon0)**2 + (lat-lat0)**2)
v = (lon-lon0)/np.sqrt((lon-lon0)**2 + (lat-lat0)**2)
lon = np.linspace(0,5,30)
lat = np.linspace(59,62,30)
r = Reader(x=lon, y=lat, proj4='+proj=latlong',
array_dict = {'x_sea_water_velocity': u, 'y_sea_water_velocity': v})
o = OceanDrift(loglevel=20)
o.set_config('environment:fallback:land_binary_mask', 0)
o.add_reader(r)
o.seed_elements(lon=3, lat=60.5, number=1000, radius=30000, time=datetime.now())
o.run(duration=timedelta(hours=72))
o.animation(fast=True)
08:25:04 INFO opendrift:568: OpenDriftSimulation initialised (version 1.14.9 / v1.14.9-9-gcde0dcf)
08:25:04 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
08:25:08 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
08:25:08 INFO opendrift.models.basemodel.environment:230: sea_surface_height: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: upward_sea_water_velocity: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: ocean_vertical_diffusivity: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: horizontal_diffusivity: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: ocean_mixed_layer_thickness: 50.000000
08:25:08 INFO opendrift.models.basemodel.environment:230: sea_floor_depth_below_sea_level: 10000.000000
08:25:08 INFO opendrift:1828: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
08:25:08 INFO opendrift:1828: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
08:25:08 INFO opendrift:1839: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
08:25:08 INFO opendrift:1839: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
08:25:08 INFO opendrift:1847: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
08:25:08 INFO opendrift:947: Using existing reader for land_binary_mask to move elements to ocean
08:25:08 INFO opendrift:978: All points are in ocean
08:25:08 INFO opendrift:2136: 2026-03-25 08:25:04.452654 - step 1 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 09:25:04.452654 - step 2 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 10:25:04.452654 - step 3 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 11:25:04.452654 - step 4 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 12:25:04.452654 - step 5 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 13:25:04.452654 - step 6 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 14:25:04.452654 - step 7 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 15:25:04.452654 - step 8 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 16:25:04.452654 - step 9 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 17:25:04.452654 - step 10 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 18:25:04.452654 - step 11 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 19:25:04.452654 - step 12 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 20:25:04.452654 - step 13 of 72 - 1000 active elements (0 deactivated)
08:25:08 INFO opendrift:2136: 2026-03-25 21:25:04.452654 - step 14 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-25 22:25:04.452654 - step 15 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-25 23:25:04.452654 - step 16 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 00:25:04.452654 - step 17 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 01:25:04.452654 - step 18 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 02:25:04.452654 - step 19 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 03:25:04.452654 - step 20 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 04:25:04.452654 - step 21 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 05:25:04.452654 - step 22 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 06:25:04.452654 - step 23 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 07:25:04.452654 - step 24 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 08:25:04.452654 - step 25 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 09:25:04.452654 - step 26 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 10:25:04.452654 - step 27 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 11:25:04.452654 - step 28 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 12:25:04.452654 - step 29 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 13:25:04.452654 - step 30 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 14:25:04.452654 - step 31 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 15:25:04.452654 - step 32 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 16:25:04.452654 - step 33 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 17:25:04.452654 - step 34 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 18:25:04.452654 - step 35 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 19:25:04.452654 - step 36 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 20:25:04.452654 - step 37 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 21:25:04.452654 - step 38 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 22:25:04.452654 - step 39 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-26 23:25:04.452654 - step 40 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-27 00:25:04.452654 - step 41 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-27 01:25:04.452654 - step 42 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-27 02:25:04.452654 - step 43 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-27 03:25:04.452654 - step 44 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-27 04:25:04.452654 - step 45 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-27 05:25:04.452654 - step 46 of 72 - 1000 active elements (0 deactivated)
08:25:09 INFO opendrift:2136: 2026-03-27 06:25:04.452654 - step 47 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 07:25:04.452654 - step 48 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 08:25:04.452654 - step 49 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 09:25:04.452654 - step 50 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 10:25:04.452654 - step 51 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 11:25:04.452654 - step 52 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 12:25:04.452654 - step 53 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 13:25:04.452654 - step 54 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 14:25:04.452654 - step 55 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 15:25:04.452654 - step 56 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 16:25:04.452654 - step 57 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 17:25:04.452654 - step 58 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 18:25:04.452654 - step 59 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 19:25:04.452654 - step 60 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 20:25:04.452654 - step 61 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 21:25:04.452654 - step 62 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 22:25:04.452654 - step 63 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-27 23:25:04.452654 - step 64 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 00:25:04.452654 - step 65 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 01:25:04.452654 - step 66 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 02:25:04.452654 - step 67 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 03:25:04.452654 - step 68 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 04:25:04.452654 - step 69 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 05:25:04.452654 - step 70 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 06:25:04.452654 - step 71 of 72 - 1000 active elements (0 deactivated)
08:25:10 INFO opendrift:2136: 2026-03-28 07:25:04.452654 - step 72 of 72 - 1000 active elements (0 deactivated)
08:25:10 WARNING opendrift:2499: Plotting fast. This will make your plots less accurate.
08:25:11 INFO opendrift:4697: Saving animation to /root/project/docs/source/gallery/animations/example_static_2d_current_0.gif...
08:26:07 INFO opendrift:3120: Time to make animation: 0:00:56.982437
Total running time of the script: (1 minutes 9.705 seconds)