Seeding from shapefile

from datetime import datetime
from opendrift.models.oceandrift import OceanDrift


o = OceanDrift(loglevel=20)  # Set loglevel to 0 for debug information

Out:

13:43:48 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.7.1 / v1.7.1-87-g074c1d2)

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())

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)

Out:

13:43:48 INFO    opendrift.models.basemodel: Seeding for layer: Torsk (8 features)
13:43:49 INFO    opendrift.models.basemodel: Total area of all polygons: 87279214797.0045 m2
13:43:49 INFO    opendrift.models.basemodel:    Seeding 1721 elements within polygon number 2
13:43:49 INFO    opendrift.models.basemodel:    Seeding 279 elements within polygon number 4

Running model

o.run(steps=50, time_step=3600)

Out:

13:43:49 INFO    opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers:
13:43:49 INFO    opendrift.models.basemodel:    x_sea_water_velocity: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    y_sea_water_velocity: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    x_wind: -4.000000
13:43:49 INFO    opendrift.models.basemodel:    y_wind: 8.000000
13:43:49 INFO    opendrift.models.basemodel:    upward_sea_water_velocity: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    ocean_vertical_diffusivity: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    sea_surface_wave_significant_height: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    surface_downward_x_stress: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    surface_downward_y_stress: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    turbulent_kinetic_energy: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    turbulent_generic_length_scale: 0.000000
13:43:49 INFO    opendrift.models.basemodel:    sea_floor_depth_below_sea_level: 10000.000000
13:43:49 INFO    opendrift.models.basemodel: Adding a dynamical landmask with max. priority based on assumed maximum speed of 1 m/s. Adding a customised landmask may be faster...
13:43:49 INFO    opendrift_landmask_data.mask: locking landmask for generation..
13:43:49 INFO    opendrift_landmask_data.mask: decompressing memmap landmask to /tmp/landmask/mask.dat..
13:43:59 INFO    opendrift_landmask_data.mask: landmask generated
13:44:02 INFO    opendrift.models.basemodel: Using existing reader for land_binary_mask
13:44:02 INFO    opendrift.models.basemodel: All points are in ocean
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 13:43:48.929738 - step 1 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 14:43:48.929738 - step 2 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 15:43:48.929738 - step 3 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 16:43:48.929738 - step 4 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 17:43:48.929738 - step 5 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 18:43:48.929738 - step 6 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 19:43:48.929738 - step 7 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 20:43:48.929738 - step 8 of 50 - 2000 active elements (0 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 21:43:48.929738 - step 9 of 50 - 1999 active elements (1 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 22:43:48.929738 - step 10 of 50 - 1997 active elements (3 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-24 23:43:48.929738 - step 11 of 50 - 1996 active elements (4 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 00:43:48.929738 - step 12 of 50 - 1996 active elements (4 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 01:43:48.929738 - step 13 of 50 - 1994 active elements (6 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 02:43:48.929738 - step 14 of 50 - 1994 active elements (6 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 03:43:48.929738 - step 15 of 50 - 1993 active elements (7 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 04:43:48.929738 - step 16 of 50 - 1991 active elements (9 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 05:43:48.929738 - step 17 of 50 - 1989 active elements (11 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 06:43:48.929738 - step 18 of 50 - 1987 active elements (13 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 07:43:48.929738 - step 19 of 50 - 1985 active elements (15 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 08:43:48.929738 - step 20 of 50 - 1983 active elements (17 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 09:43:48.929738 - step 21 of 50 - 1983 active elements (17 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 10:43:48.929738 - step 22 of 50 - 1981 active elements (19 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 11:43:48.929738 - step 23 of 50 - 1979 active elements (21 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 12:43:48.929738 - step 24 of 50 - 1976 active elements (24 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 13:43:48.929738 - step 25 of 50 - 1973 active elements (27 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 14:43:48.929738 - step 26 of 50 - 1972 active elements (28 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 15:43:48.929738 - step 27 of 50 - 1969 active elements (31 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 16:43:48.929738 - step 28 of 50 - 1968 active elements (32 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 17:43:48.929738 - step 29 of 50 - 1967 active elements (33 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 18:43:48.929738 - step 30 of 50 - 1964 active elements (36 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 19:43:48.929738 - step 31 of 50 - 1961 active elements (39 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 20:43:48.929738 - step 32 of 50 - 1960 active elements (40 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 21:43:48.929738 - step 33 of 50 - 1958 active elements (42 deactivated)
13:44:02 INFO    opendrift.models.basemodel: 2021-09-25 22:43:48.929738 - step 34 of 50 - 1957 active elements (43 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-25 23:43:48.929738 - step 35 of 50 - 1952 active elements (48 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 00:43:48.929738 - step 36 of 50 - 1952 active elements (48 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 01:43:48.929738 - step 37 of 50 - 1949 active elements (51 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 02:43:48.929738 - step 38 of 50 - 1948 active elements (52 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 03:43:48.929738 - step 39 of 50 - 1946 active elements (54 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 04:43:48.929738 - step 40 of 50 - 1943 active elements (57 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 05:43:48.929738 - step 41 of 50 - 1940 active elements (60 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 06:43:48.929738 - step 42 of 50 - 1938 active elements (62 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 07:43:48.929738 - step 43 of 50 - 1936 active elements (64 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 08:43:48.929738 - step 44 of 50 - 1930 active elements (70 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 09:43:48.929738 - step 45 of 50 - 1926 active elements (74 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 10:43:48.929738 - step 46 of 50 - 1923 active elements (77 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 11:43:48.929738 - step 47 of 50 - 1921 active elements (79 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 12:43:48.929738 - step 48 of 50 - 1920 active elements (80 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 13:43:48.929738 - step 49 of 50 - 1917 active elements (83 deactivated)
13:44:03 INFO    opendrift.models.basemodel: 2021-09-26 14:43:48.929738 - step 50 of 50 - 1916 active elements (84 deactivated)

Print and plot results

print(o)
o.plot(fast=True)
o.animation(fast=True)
OpenDrift - OceanDrift 2021-09-24 13:43 to 2021-09-26 15:43 UTC (51 steps)

Out:

===========================
--------------------
Reader performance:
--------------------
global_landmask
 0:00:00.1  total
 0:00:00.0  preparing
 0:00:00.1  reading
 0:00:00.0  masking
--------------------
Performance:
   14.5 total time
    0.4 configuration
   13.0 preparing main loop
     13.0 making dynamical landmask
      0.0 moving elements to ocean
      0.3 readers
        0.1 global_landmask
        0.1 postprocessing
    0.9 main loop
      0.1 updating elements
    0.0 cleaning up
--------------------
===========================
Model:  OceanDrift     (OpenDrift version 1.7.1)
        1912 active Lagrangian3DArray particles  (88 deactivated, 0 scheduled)
-------------------
Environment variables:
  -----
  land_binary_mask
     1) global_landmask
  -----
Readers not added for the following variables:
  ocean_vertical_diffusivity
  sea_floor_depth_below_sea_level
  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
  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

Time:
        Start: 2021-09-24 13:43:48.929738
        Present: 2021-09-26 15:43:48.929738
        Calculation steps: 50 * 1:00:00 - total time: 2 days, 2:00:00
        Output steps: 51 * 1:00:00
===========================

13:44:03 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.
13:44:08 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.
13:44:10 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_seed_from_shapefile_0.gif...
13:44:10 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
../_images/example_seed_from_shapefile_0.gif

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

Gallery generated by Sphinx-Gallery