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)
09:40:24 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-48-g5bea84b)
09:40:24 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...
09:40:30 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_height: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    x_wind: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    y_wind: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    upward_sea_water_velocity: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_to_direction: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_swell_wave_significant_height: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_to_direction: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_mean_period: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wind_wave_significant_height: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    surface_downward_x_stress: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    surface_downward_y_stress: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    turbulent_kinetic_energy: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    turbulent_generic_length_scale: 0.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000
09:40:30 INFO    opendrift.models.basemodel.environment:248:    sea_floor_depth_below_sea_level: 10000.000000
09:40:30 INFO    opendrift.models.basemodel:936: Using existing reader for land_binary_mask
09:40:30 INFO    opendrift.models.basemodel:947: All points are in ocean
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 09:40:24.955331 - step 1 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 10:40:24.955331 - step 2 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 11:40:24.955331 - step 3 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 12:40:24.955331 - step 4 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 13:40:24.955331 - step 5 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 14:40:24.955331 - step 6 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 15:40:24.955331 - step 7 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 16:40:24.955331 - step 8 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 17:40:24.955331 - step 9 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 18:40:24.955331 - step 10 of 72 - 1000 active elements (0 deactivated)
09:40:30 INFO    opendrift.models.basemodel:2038: 2024-10-01 19:40:24.955331 - step 11 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-01 20:40:24.955331 - step 12 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-01 21:40:24.955331 - step 13 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-01 22:40:24.955331 - step 14 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-01 23:40:24.955331 - step 15 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 00:40:24.955331 - step 16 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 01:40:24.955331 - step 17 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 02:40:24.955331 - step 18 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 03:40:24.955331 - step 19 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 04:40:24.955331 - step 20 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 05:40:24.955331 - step 21 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 06:40:24.955331 - step 22 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 07:40:24.955331 - step 23 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 08:40:24.955331 - step 24 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 09:40:24.955331 - step 25 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 10:40:24.955331 - step 26 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 11:40:24.955331 - step 27 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 12:40:24.955331 - step 28 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 13:40:24.955331 - step 29 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 14:40:24.955331 - step 30 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 15:40:24.955331 - step 31 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 16:40:24.955331 - step 32 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 17:40:24.955331 - step 33 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 18:40:24.955331 - step 34 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 19:40:24.955331 - step 35 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 20:40:24.955331 - step 36 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 21:40:24.955331 - step 37 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 22:40:24.955331 - step 38 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-02 23:40:24.955331 - step 39 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 00:40:24.955331 - step 40 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 01:40:24.955331 - step 41 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 02:40:24.955331 - step 42 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 03:40:24.955331 - step 43 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 04:40:24.955331 - step 44 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 05:40:24.955331 - step 45 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 06:40:24.955331 - step 46 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 07:40:24.955331 - step 47 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 08:40:24.955331 - step 48 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 09:40:24.955331 - step 49 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 10:40:24.955331 - step 50 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 11:40:24.955331 - step 51 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 12:40:24.955331 - step 52 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 13:40:24.955331 - step 53 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 14:40:24.955331 - step 54 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 15:40:24.955331 - step 55 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 16:40:24.955331 - step 56 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 17:40:24.955331 - step 57 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 18:40:24.955331 - step 58 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 19:40:24.955331 - step 59 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 20:40:24.955331 - step 60 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 21:40:24.955331 - step 61 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 22:40:24.955331 - step 62 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-03 23:40:24.955331 - step 63 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 00:40:24.955331 - step 64 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 01:40:24.955331 - step 65 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 02:40:24.955331 - step 66 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 03:40:24.955331 - step 67 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 04:40:24.955331 - step 68 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 05:40:24.955331 - step 69 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 06:40:24.955331 - step 70 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 07:40:24.955331 - step 71 of 72 - 1000 active elements (0 deactivated)
09:40:31 INFO    opendrift.models.basemodel:2038: 2024-10-04 08:40:24.955331 - step 72 of 72 - 1000 active elements (0 deactivated)
09:40:32 WARNING opendrift.models.basemodel:2411: 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)
09:40:33 INFO    opendrift.models.basemodel:4608: Saving animation to /root/project/docs/source/gallery/animations/example_static_2d_current_0.gif...
09:41:07 INFO    opendrift.models.basemodel:3037: Time to make animation: 0:00:35.252390
../_images/example_static_2d_current_0.gif

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

Gallery generated by Sphinx-Gallery