Note
Go to the end to download the full example code.
Seeding from shapefile
from datetime import datetime
from opendrift.models.oceandrift import OceanDrift
o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
o.set_config('environment:fallback:x_wind', -4) # Constant wind drift
o.set_config('environment:fallback:y_wind', 8)
o.set_config('drift:wind_uncertainty', 4) # Adding some diffusion
o.set_config('drift:vertical_mixing', False)
17:22:37 INFO opendrift.models.basemodel:512: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-55-g4faa301)
Seed particles within contours from shapefile
o.seed_from_shapefile(o.test_data_folder() +
'shapefile_spawning_areas/Torsk.shp',
number=2000, layername=None,
featurenum=[2, 4], time=datetime.utcnow())
17:22:37 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...
17:22:40 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
17:22:40 INFO opendrift.models.basemodel.environment:248: x_sea_water_velocity: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: y_sea_water_velocity: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_height: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: x_wind: -4.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: y_wind: 8.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: upward_sea_water_velocity: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_to_direction: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_significant_height: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_to_direction: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_mean_period: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_significant_height: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: surface_downward_x_stress: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: surface_downward_y_stress: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: turbulent_kinetic_energy: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: turbulent_generic_length_scale: 0.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000
17:22:40 INFO opendrift.models.basemodel.environment:248: sea_floor_depth_below_sea_level: 10000.000000
17:22:40 INFO opendrift.models.basemodel:1541: Seeding for layer: Torsk (8 features)
17:22:40 INFO opendrift.models.basemodel:1572: Total area of all polygons: 87279214796.95839 m2
17:22:40 INFO opendrift.models.basemodel:1583: Seeding 1721 elements within polygon number 2
17:22:40 INFO opendrift.models.basemodel:1583: Seeding 279 elements within polygon number 4
Running model
o.run(steps=50, time_step=3600)
17:22:41 INFO opendrift.models.basemodel:932: Using existing reader for land_binary_mask
17:22:41 INFO opendrift.models.basemodel:943: All points are in ocean
17:22:41 INFO opendrift.models.basemodel:2032: 2025-01-14 17:22:37.419544 - step 1 of 50 - 2000 active elements (0 deactivated)
17:22:41 INFO opendrift.models.basemodel:2032: 2025-01-14 18:22:37.419544 - step 2 of 50 - 2000 active elements (0 deactivated)
17:22:41 INFO opendrift.models.basemodel:2032: 2025-01-14 19:22:37.419544 - step 3 of 50 - 2000 active elements (0 deactivated)
17:22:41 INFO opendrift.models.basemodel:2032: 2025-01-14 20:22:37.419544 - step 4 of 50 - 2000 active elements (0 deactivated)
17:22:41 INFO opendrift.models.basemodel:2032: 2025-01-14 21:22:37.419544 - step 5 of 50 - 2000 active elements (0 deactivated)
17:22:41 INFO opendrift.models.basemodel:2032: 2025-01-14 22:22:37.419544 - step 6 of 50 - 2000 active elements (0 deactivated)
17:22:41 INFO opendrift.models.basemodel:2032: 2025-01-14 23:22:37.419544 - step 7 of 50 - 2000 active elements (0 deactivated)
17:22:43 INFO opendrift.models.basemodel:2032: 2025-01-15 00:22:37.419544 - step 8 of 50 - 2000 active elements (0 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 01:22:37.419544 - step 9 of 50 - 1999 active elements (1 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 02:22:37.419544 - step 10 of 50 - 1997 active elements (3 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 03:22:37.419544 - step 11 of 50 - 1996 active elements (4 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 04:22:37.419544 - step 12 of 50 - 1996 active elements (4 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 05:22:37.419544 - step 13 of 50 - 1994 active elements (6 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 06:22:37.419544 - step 14 of 50 - 1994 active elements (6 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 07:22:37.419544 - step 15 of 50 - 1993 active elements (7 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 08:22:37.419544 - step 16 of 50 - 1991 active elements (9 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 09:22:37.419544 - step 17 of 50 - 1989 active elements (11 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 10:22:37.419544 - step 18 of 50 - 1987 active elements (13 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 11:22:37.419544 - step 19 of 50 - 1985 active elements (15 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 12:22:37.419544 - step 20 of 50 - 1983 active elements (17 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 13:22:37.419544 - step 21 of 50 - 1983 active elements (17 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 14:22:37.419544 - step 22 of 50 - 1981 active elements (19 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 15:22:37.419544 - step 23 of 50 - 1979 active elements (21 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 16:22:37.419544 - step 24 of 50 - 1976 active elements (24 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 17:22:37.419544 - step 25 of 50 - 1973 active elements (27 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 18:22:37.419544 - step 26 of 50 - 1972 active elements (28 deactivated)
17:22:44 INFO opendrift.models.basemodel:2032: 2025-01-15 19:22:37.419544 - step 27 of 50 - 1969 active elements (31 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-15 20:22:37.419544 - step 28 of 50 - 1968 active elements (32 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-15 21:22:37.419544 - step 29 of 50 - 1967 active elements (33 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-15 22:22:37.419544 - step 30 of 50 - 1964 active elements (36 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-15 23:22:37.419544 - step 31 of 50 - 1961 active elements (39 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 00:22:37.419544 - step 32 of 50 - 1960 active elements (40 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 01:22:37.419544 - step 33 of 50 - 1958 active elements (42 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 02:22:37.419544 - step 34 of 50 - 1957 active elements (43 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 03:22:37.419544 - step 35 of 50 - 1952 active elements (48 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 04:22:37.419544 - step 36 of 50 - 1952 active elements (48 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 05:22:37.419544 - step 37 of 50 - 1949 active elements (51 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 06:22:37.419544 - step 38 of 50 - 1948 active elements (52 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 07:22:37.419544 - step 39 of 50 - 1946 active elements (54 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 08:22:37.419544 - step 40 of 50 - 1943 active elements (57 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 09:22:37.419544 - step 41 of 50 - 1940 active elements (60 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 10:22:37.419544 - step 42 of 50 - 1938 active elements (62 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 11:22:37.419544 - step 43 of 50 - 1936 active elements (64 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 12:22:37.419544 - step 44 of 50 - 1930 active elements (70 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 13:22:37.419544 - step 45 of 50 - 1926 active elements (74 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 14:22:37.419544 - step 46 of 50 - 1923 active elements (77 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 15:22:37.419544 - step 47 of 50 - 1921 active elements (79 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 16:22:37.419544 - step 48 of 50 - 1920 active elements (80 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 17:22:37.419544 - step 49 of 50 - 1917 active elements (83 deactivated)
17:22:45 INFO opendrift.models.basemodel:2032: 2025-01-16 18:22:37.419544 - step 50 of 50 - 1916 active elements (84 deactivated)
Print and plot results
print(o)
o.plot(fast=True)
o.animation(fast=True)
===========================
--------------------
Reader performance:
--------------------
global_landmask
0:00:01.5 total
0:00:00.0 preparing
0:00:01.5 reading
0:00:00.0 masking
--------------------
Performance:
8.3 total time
3.9 configuration
0.0 preparing main loop
0.0 moving elements to ocean
4.2 main loop
0.1 updating elements
0.0 cleaning up
--------------------
===========================
Model: OceanDrift (OpenDrift version 1.12.0)
1911 active Lagrangian3DArray particles (89 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
land_binary_mask
1) global_landmask
-----
Readers not added for the following variables:
ocean_mixed_layer_thickness
ocean_vertical_diffusivity
sea_floor_depth_below_sea_level
sea_surface_height
sea_surface_swell_wave_peak_period_from_variance_spectral_density
sea_surface_swell_wave_significant_height
sea_surface_swell_wave_to_direction
sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment
sea_surface_wave_period_at_variance_spectral_density_maximum
sea_surface_wave_significant_height
sea_surface_wave_stokes_drift_x_velocity
sea_surface_wave_stokes_drift_y_velocity
sea_surface_wind_wave_mean_period
sea_surface_wind_wave_significant_height
sea_surface_wind_wave_to_direction
surface_downward_x_stress
surface_downward_y_stress
turbulent_generic_length_scale
turbulent_kinetic_energy
upward_sea_water_velocity
x_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
Discarded readers:
Time:
Start: 2025-01-14 17:22:37.419544 UTC
Present: 2025-01-16 19:22:37.419544 UTC
Calculation steps: 50 * 1:00:00 - total time: 2 days, 2:00:00
Output steps: 51 * 1:00:00
===========================
17:22:45 WARNING opendrift.models.basemodel:2407: Plotting fast. This will make your plots less accurate.
17:22:53 WARNING opendrift.models.basemodel:2407: 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)
17:22:54 INFO opendrift.models.basemodel:4606: Saving animation to /root/project/docs/source/gallery/animations/example_seed_from_shapefile_0.gif...
17:23:23 INFO opendrift.models.basemodel:3034: Time to make animation: 0:00:29.812586
Total running time of the script: (0 minutes 51.333 seconds)