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:33:56 INFO    opendrift.models.basemodel:533: OpenDriftSimulation initialised (version 1.11.2 / v1.11.2-45-g6369924)
08:33:56 INFO    opendrift.models.basemodel.environment:218: Adding a dynamical landmask with max. priority based on assumed maximum speed of 2.0 m/s. Adding a customised landmask may be faster...
08:34:03 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_height: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    x_wind: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    y_wind: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    upward_sea_water_velocity: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_to_direction: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_significant_height: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_to_direction: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_mean_period: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_significant_height: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    surface_downward_x_stress: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    surface_downward_y_stress: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    turbulent_kinetic_energy: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    turbulent_generic_length_scale: 0.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000
08:34:03 INFO    opendrift.models.basemodel.environment:248:    sea_floor_depth_below_sea_level: 10000.000000
08:34:03 INFO    opendrift.models.basemodel:911: Using existing reader for land_binary_mask
08:34:03 INFO    opendrift.models.basemodel:922: All points are in ocean
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 08:33:56.592536 - step 1 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 09:33:56.592536 - step 2 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 10:33:56.592536 - step 3 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 11:33:56.592536 - step 4 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 12:33:56.592536 - step 5 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 13:33:56.592536 - step 6 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 14:33:56.592536 - step 7 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 15:33:56.592536 - step 8 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 16:33:56.592536 - step 9 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 17:33:56.592536 - step 10 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 18:33:56.592536 - step 11 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 19:33:56.592536 - step 12 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 20:33:56.592536 - step 13 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 21:33:56.592536 - step 14 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 22:33:56.592536 - step 15 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-23 23:33:56.592536 - step 16 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 00:33:56.592536 - step 17 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 01:33:56.592536 - step 18 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 02:33:56.592536 - step 19 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 03:33:56.592536 - step 20 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 04:33:56.592536 - step 21 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 05:33:56.592536 - step 22 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 06:33:56.592536 - step 23 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 07:33:56.592536 - step 24 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 08:33:56.592536 - step 25 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 09:33:56.592536 - step 26 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 10:33:56.592536 - step 27 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 11:33:56.592536 - step 28 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 12:33:56.592536 - step 29 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 13:33:56.592536 - step 30 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 14:33:56.592536 - step 31 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 15:33:56.592536 - step 32 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 16:33:56.592536 - step 33 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 17:33:56.592536 - step 34 of 72 - 1000 active elements (0 deactivated)
08:34:03 INFO    opendrift.models.basemodel:2011: 2024-05-24 18:33:56.592536 - step 35 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-24 19:33:56.592536 - step 36 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-24 20:33:56.592536 - step 37 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-24 21:33:56.592536 - step 38 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-24 22:33:56.592536 - step 39 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-24 23:33:56.592536 - step 40 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 00:33:56.592536 - step 41 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 01:33:56.592536 - step 42 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 02:33:56.592536 - step 43 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 03:33:56.592536 - step 44 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 04:33:56.592536 - step 45 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 05:33:56.592536 - step 46 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 06:33:56.592536 - step 47 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 07:33:56.592536 - step 48 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 08:33:56.592536 - step 49 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 09:33:56.592536 - step 50 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 10:33:56.592536 - step 51 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 11:33:56.592536 - step 52 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 12:33:56.592536 - step 53 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 13:33:56.592536 - step 54 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 14:33:56.592536 - step 55 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 15:33:56.592536 - step 56 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 16:33:56.592536 - step 57 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 17:33:56.592536 - step 58 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 18:33:56.592536 - step 59 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 19:33:56.592536 - step 60 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 20:33:56.592536 - step 61 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 21:33:56.592536 - step 62 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 22:33:56.592536 - step 63 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-25 23:33:56.592536 - step 64 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 00:33:56.592536 - step 65 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 01:33:56.592536 - step 66 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 02:33:56.592536 - step 67 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 03:33:56.592536 - step 68 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 04:33:56.592536 - step 69 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 05:33:56.592536 - step 70 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 06:33:56.592536 - step 71 of 72 - 1000 active elements (0 deactivated)
08:34:04 INFO    opendrift.models.basemodel:2011: 2024-05-26 07:33:56.592536 - step 72 of 72 - 1000 active elements (0 deactivated)
08:34:04 WARNING opendrift.models.basemodel:2379: Plotting fast. This will make your plots less accurate.
/opt/conda/envs/opendrift/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1683: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  result = super().scatter(*args, **kwargs)
08:34:07 INFO    opendrift.models.basemodel:4570: Saving animation to /root/project/docs/source/gallery/animations/example_static_2d_current_0.gif...
08:34:49 INFO    opendrift.models.basemodel:3003: Time to make animation: 0:00:44.187517
../_images/example_static_2d_current_0.gif

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

Gallery generated by Sphinx-Gallery