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