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)
15:23:26 INFO opendrift:509: OpenDriftSimulation initialised (version 1.13.1 / v1.13.1-12-gca7f755)
15:23:26 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
15:23:30 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_height: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: x_wind: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: y_wind: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_swell_wave_to_direction: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_swell_wave_significant_height: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wind_wave_to_direction: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wind_wave_mean_period: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_surface_wind_wave_significant_height: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: surface_downward_x_stress: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: surface_downward_y_stress: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: turbulent_kinetic_energy: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: turbulent_generic_length_scale: 0.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000
15:23:30 INFO opendrift.models.basemodel.environment:232: sea_floor_depth_below_sea_level: 10000.000000
15:23:30 INFO opendrift:919: Using existing reader for land_binary_mask
15:23:30 INFO opendrift:930: All points are in ocean
15:23:30 INFO opendrift:2056: 2025-04-03 15:23:26.358813 - step 1 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 16:23:26.358813 - step 2 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 17:23:26.358813 - step 3 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 18:23:26.358813 - step 4 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 19:23:26.358813 - step 5 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 20:23:26.358813 - step 6 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 21:23:26.358813 - step 7 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 22:23:26.358813 - step 8 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-03 23:23:26.358813 - step 9 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 00:23:26.358813 - step 10 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 01:23:26.358813 - step 11 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 02:23:26.358813 - step 12 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 03:23:26.358813 - step 13 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 04:23:26.358813 - step 14 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 05:23:26.358813 - step 15 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 06:23:26.358813 - step 16 of 72 - 1000 active elements (0 deactivated)
15:23:30 INFO opendrift:2056: 2025-04-04 07:23:26.358813 - step 17 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 08:23:26.358813 - step 18 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 09:23:26.358813 - step 19 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 10:23:26.358813 - step 20 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 11:23:26.358813 - step 21 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 12:23:26.358813 - step 22 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 13:23:26.358813 - step 23 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 14:23:26.358813 - step 24 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 15:23:26.358813 - step 25 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 16:23:26.358813 - step 26 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 17:23:26.358813 - step 27 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 18:23:26.358813 - step 28 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 19:23:26.358813 - step 29 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 20:23:26.358813 - step 30 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 21:23:26.358813 - step 31 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 22:23:26.358813 - step 32 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-04 23:23:26.358813 - step 33 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 00:23:26.358813 - step 34 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 01:23:26.358813 - step 35 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 02:23:26.358813 - step 36 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 03:23:26.358813 - step 37 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 04:23:26.358813 - step 38 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 05:23:26.358813 - step 39 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 06:23:26.358813 - step 40 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 07:23:26.358813 - step 41 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 08:23:26.358813 - step 42 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 09:23:26.358813 - step 43 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 10:23:26.358813 - step 44 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 11:23:26.358813 - step 45 of 72 - 1000 active elements (0 deactivated)
15:23:31 INFO opendrift:2056: 2025-04-05 12:23:26.358813 - step 46 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 13:23:26.358813 - step 47 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 14:23:26.358813 - step 48 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 15:23:26.358813 - step 49 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 16:23:26.358813 - step 50 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 17:23:26.358813 - step 51 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 18:23:26.358813 - step 52 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 19:23:26.358813 - step 53 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 20:23:26.358813 - step 54 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 21:23:26.358813 - step 55 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 22:23:26.358813 - step 56 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-05 23:23:26.358813 - step 57 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 00:23:26.358813 - step 58 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 01:23:26.358813 - step 59 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 02:23:26.358813 - step 60 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 03:23:26.358813 - step 61 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 04:23:26.358813 - step 62 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 05:23:26.358813 - step 63 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 06:23:26.358813 - step 64 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 07:23:26.358813 - step 65 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 08:23:26.358813 - step 66 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 09:23:26.358813 - step 67 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 10:23:26.358813 - step 68 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 11:23:26.358813 - step 69 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 12:23:26.358813 - step 70 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 13:23:26.358813 - step 71 of 72 - 1000 active elements (0 deactivated)
15:23:32 INFO opendrift:2056: 2025-04-06 14:23:26.358813 - step 72 of 72 - 1000 active elements (0 deactivated)
15:23:32 WARNING opendrift:2429: Plotting fast. This will make your plots less accurate.
15:23:34 INFO opendrift:4600: Saving animation to /root/project/docs/source/gallery/animations/example_static_2d_current_0.gif...
15:24:16 INFO opendrift:3036: Time to make animation: 0:00:43.709551

Total running time of the script: (0 minutes 55.119 seconds)