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)
14:15:32 INFO opendrift:576: OpenDriftSimulation initialised (version 1.14.8 / v1.14.8-22-ged2e201)
14:15:32 INFO opendrift.models.basemodel.environment:203: Adding a global landmask from GSHHG
14:15:38 INFO opendrift.models.basemodel.environment:227: Fallback values will be used for the following variables which have no readers:
14:15:38 INFO opendrift.models.basemodel.environment:230: sea_surface_height: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: x_wind: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: y_wind: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: upward_sea_water_velocity: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: ocean_vertical_diffusivity: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: horizontal_diffusivity: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_significant_height: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_x_velocity: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: sea_surface_wave_stokes_drift_y_velocity: 0.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: ocean_mixed_layer_thickness: 50.000000
14:15:38 INFO opendrift.models.basemodel.environment:230: sea_floor_depth_below_sea_level: 10000.000000
14:15:38 INFO opendrift:1836: Skipping environment variable ocean_vertical_diffusivity because of condition ['drift:vertical_mixing', 'is', False]
14:15:38 INFO opendrift:1836: Skipping environment variable ocean_mixed_layer_thickness because of condition ['drift:vertical_mixing', 'is', False]
14:15:38 INFO opendrift:1847: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:15:38 INFO opendrift:1847: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
14:15:38 INFO opendrift:1855: Storing previous values of environment variable sea_surface_height because of condition ['drift:vertical_advection', 'is', True]
14:15:38 INFO opendrift:955: Using existing reader for land_binary_mask to move elements to ocean
14:15:38 INFO opendrift:986: All points are in ocean
14:15:38 INFO opendrift:2144: 2026-03-03 14:15:32.596956 - step 1 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 15:15:32.596956 - step 2 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 16:15:32.596956 - step 3 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 17:15:32.596956 - step 4 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 18:15:32.596956 - step 5 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 19:15:32.596956 - step 6 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 20:15:32.596956 - step 7 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 21:15:32.596956 - step 8 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 22:15:32.596956 - step 9 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-03 23:15:32.596956 - step 10 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 00:15:32.596956 - step 11 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 01:15:32.596956 - step 12 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 02:15:32.596956 - step 13 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 03:15:32.596956 - step 14 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 04:15:32.596956 - step 15 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 05:15:32.596956 - step 16 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 06:15:32.596956 - step 17 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 07:15:32.596956 - step 18 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 08:15:32.596956 - step 19 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 09:15:32.596956 - step 20 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 10:15:32.596956 - step 21 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 11:15:32.596956 - step 22 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 12:15:32.596956 - step 23 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 13:15:32.596956 - step 24 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 14:15:32.596956 - step 25 of 72 - 1000 active elements (0 deactivated)
14:15:38 INFO opendrift:2144: 2026-03-04 15:15:32.596956 - step 26 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 16:15:32.596956 - step 27 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 17:15:32.596956 - step 28 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 18:15:32.596956 - step 29 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 19:15:32.596956 - step 30 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 20:15:32.596956 - step 31 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 21:15:32.596956 - step 32 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 22:15:32.596956 - step 33 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-04 23:15:32.596956 - step 34 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 00:15:32.596956 - step 35 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 01:15:32.596956 - step 36 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 02:15:32.596956 - step 37 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 03:15:32.596956 - step 38 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 04:15:32.596956 - step 39 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 05:15:32.596956 - step 40 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 06:15:32.596956 - step 41 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 07:15:32.596956 - step 42 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 08:15:32.596956 - step 43 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 09:15:32.596956 - step 44 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 10:15:32.596956 - step 45 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 11:15:32.596956 - step 46 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 12:15:32.596956 - step 47 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 13:15:32.596956 - step 48 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 14:15:32.596956 - step 49 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 15:15:32.596956 - step 50 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 16:15:32.596956 - step 51 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 17:15:32.596956 - step 52 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 18:15:32.596956 - step 53 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 19:15:32.596956 - step 54 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 20:15:32.596956 - step 55 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 21:15:32.596956 - step 56 of 72 - 1000 active elements (0 deactivated)
14:15:39 INFO opendrift:2144: 2026-03-05 22:15:32.596956 - step 57 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-05 23:15:32.596956 - step 58 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 00:15:32.596956 - step 59 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 01:15:32.596956 - step 60 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 02:15:32.596956 - step 61 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 03:15:32.596956 - step 62 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 04:15:32.596956 - step 63 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 05:15:32.596956 - step 64 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 06:15:32.596956 - step 65 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 07:15:32.596956 - step 66 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 08:15:32.596956 - step 67 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 09:15:32.596956 - step 68 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 10:15:32.596956 - step 69 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 11:15:32.596956 - step 70 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 12:15:32.596956 - step 71 of 72 - 1000 active elements (0 deactivated)
14:15:40 INFO opendrift:2144: 2026-03-06 13:15:32.596956 - step 72 of 72 - 1000 active elements (0 deactivated)
14:15:40 WARNING opendrift:2507: Plotting fast. This will make your plots less accurate.
14:15:42 INFO opendrift:4705: Saving animation to /root/project/docs/source/gallery/animations/example_static_2d_current_0.gif...
14:16:36 INFO opendrift:3128: Time to make animation: 0:00:55.940027
Total running time of the script: (1 minutes 10.512 seconds)