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