Seed demonstration

from datetime import datetime, timedelta
import numpy as np
from opendrift.models.oceandrift import OceanDrift
from opendrift.models.openoil import OpenOil

o = OceanDrift(loglevel=50)

We do not care about landmask or current for this seeding demonstration, so we simple specify fallback_values instead of adding any readers

o.set_config('environment:fallback:land_binary_mask', 0)
o.set_config('environment:fallback:x_sea_water_velocity', 0)
o.set_config('environment:fallback:y_sea_water_velocity', 0)
o.set_config('drift:wind_uncertainty', 0)
o.set_config('drift:current_uncertainty', 0)

time=datetime(2016, 1, 20, 12, 30, 0)

Seeding a single element at a point

print('\n' + '='*70)
print('Seeding a single element at a point:')
print('o.seed_elements(lon=4, lat=60, time=time)')
print('='*70)
o.seed_elements(lon=4, lat=60, time=time)
#o.run(steps=1)
o.plot(buffer=.7, fast=True)
OpenDrift - OceanDrift 1 elements seeded at 2016-01-20 12:30 UTC

Out:

======================================================================
Seeding a single element at a point:
o.seed_elements(lon=4, lat=60, time=time)
======================================================================

(<GeoAxesSubplot:title={'center':'OpenDrift - OceanDrift\n1 elements seeded at 2016-01-20 12:30 UTC'}>, <module 'matplotlib.pyplot' from '/opt/conda/envs/opendrift/lib/python3.9/site-packages/matplotlib/pyplot.py'>)

Seeding 100 elements within a radius of 1000 m

print('\n' + '='*70)
print('Seeding 100 elements within a radius of 1000 m:')
print('o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time)')
print('='*70)
o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time)
#o.run(steps=1)
o.plot(buffer=.7, fast=True)
OpenDrift - OceanDrift 101 elements seeded at 2016-01-20 12:30 UTC

Out:

======================================================================
Seeding 100 elements within a radius of 1000 m:
o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time)
======================================================================

(<GeoAxesSubplot:title={'center':'OpenDrift - OceanDrift\n101 elements seeded at 2016-01-20 12:30 UTC'}>, <module 'matplotlib.pyplot' from '/opt/conda/envs/opendrift/lib/python3.9/site-packages/matplotlib/pyplot.py'>)

Seeding 100 elements within a radius of 1000 m and specifying a property (here z/depth) as an array

print('\n' + '='*70)
print('Seeding 100 elements within a radius of 1000 m\n and specifying a property (here z/depth) as an array:')
print('o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z)')
print('='*70)
z = np.linspace(0, -50, 100)  # Linearly increasing depth
o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z)
o.set_config('environment:fallback:y_sea_water_velocity', 3)  # Adding some current to be able to visualise depth as color of trajectories
o.run(steps=1)
o.plot(linecolor='z', buffer=.7, fast=True)
o.set_config('environment:fallback:y_sea_water_velocity', 0)
OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps)

Out:

======================================================================
Seeding 100 elements within a radius of 1000 m
 and specifying a property (here z/depth) as an array:
o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z)
======================================================================

Seeding 100 elements at user defined locations (here along line between two points)

print('\n' + '='*70)
print('Seeding 100 elements at user defined locations\n (here along line between two points):')
print('lats = np.linspace(60, 61, 100)\n' \
      'lons = np.linspace(4, 4.8, 100)\n' \
      'o.seed_elements(lon=lons, lat=lats, time=time)')
print('='*70)
lats = np.linspace(60, 61, 100)
lons = np.linspace(4, 4.8, 100)
o.seed_elements(lon=lons, lat=lats, time=time)
o.run(steps=1)
o.plot(buffer=.2, fast=True)
OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps)

Out:

======================================================================
Seeding 100 elements at user defined locations
 (here along line between two points):
lats = np.linspace(60, 61, 100)
lons = np.linspace(4, 4.8, 100)
o.seed_elements(lon=lons, lat=lats, time=time)
======================================================================

(<GeoAxesSubplot:title={'center':'OpenDrift - OceanDrift\n2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps)'}>, <module 'matplotlib.pyplot' from '/opt/conda/envs/opendrift/lib/python3.9/site-packages/matplotlib/pyplot.py'>)

Seeding 100 elements between two points with seed_cone() (achieving the same as previous example)

print('\n' + '='*70)
print('Seeding 100 elements between two points with seed_cone() (achieving the same as previous example):')
print('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time)')
print('='*70)
o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time)
o.run(steps=1)
o.plot(buffer=.2, fast=True)
OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps)

Out:

======================================================================
Seeding 100 elements between two points with seed_cone() (achieving the same as previous example):
o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time)
======================================================================

(<GeoAxesSubplot:title={'center':'OpenDrift - OceanDrift\n2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps)'}>, <module 'matplotlib.pyplot' from '/opt/conda/envs/opendrift/lib/python3.9/site-packages/matplotlib/pyplot.py'>)

Seeding 1000 elements along cone with radius/uncertainty increasing linearly from 0 to 5000 m

print('\n' + '='*70)
print('Seeding 1000 elements along cone with radius/uncertainty\n increasing linearly from 0 to 5000 m:')
print('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time)')
print('='*70)
o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time)
o.run(steps=1)
o.plot(buffer=.2, fast=True)
OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps)

Out:

======================================================================
Seeding 1000 elements along cone with radius/uncertainty
 increasing linearly from 0 to 5000 m:
o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time)
======================================================================

(<GeoAxesSubplot:title={'center':'OpenDrift - OceanDrift\n2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps)'}>, <module 'matplotlib.pyplot' from '/opt/conda/envs/opendrift/lib/python3.9/site-packages/matplotlib/pyplot.py'>)

If specifying time as a two element list (start and end, here +5 hours), elements are seeded linearly in time

print('\n' + '='*70)
print('If specifying time as a two element list (start and end,\n here +5 hours), elements are seeded linearly in time:')
print('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)])')
print('='*70)
o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)])
o.run(steps=5*4, time_step=900)
o.animation(fast=True)

Out:

======================================================================
If specifying time as a two element list (start and end,
 here +5 hours), elements are seeded linearly in time:
o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)])
======================================================================
MovieWriter imagemagick unavailable; using Pillow instead.
../_images/example_seed_demonstration_0.gif
print('\n' + '='*70)
print('Any model/module may provide specialised seeding-functions, such as \n seeding oil within contours read from a GML file:')
print('o.seed_from_gml(o.test_data_folder() + "radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml", num_elements=2000)')
print('='*70)
o = OpenOil(loglevel=50)
o.set_config('environment:fallback:x_wind', 0)
o.set_config('environment:fallback:y_wind', 0)
o.set_config('environment:fallback:x_sea_water_velocity', 0)
o.set_config('environment:fallback:y_sea_water_velocity', 0)
o.seed_from_gml(o.test_data_folder() + 'radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml', num_elements=2000)
o.run(steps=1, time_step=1800, time_step_output=1800)
o.plot(buffer=.03, fast=True)
OpenDrift - OpenOil (AASGARD A 2003) 2015-11-16 00:26 to 2015-11-16 00:56 UTC (2 steps)

Out:

======================================================================
Any model/module may provide specialised seeding-functions, such as
 seeding oil within contours read from a GML file:
o.seed_from_gml(o.test_data_folder() + "radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml", num_elements=2000)
======================================================================
querying DB:
Oil.name ==  'AASGARD A 2003'

(<GeoAxesSubplot:title={'center':'OpenDrift - OpenOil (AASGARD A 2003)\n2015-11-16 00:26 to 2015-11-16 00:56 UTC (2 steps)'}>, <module 'matplotlib.pyplot' from '/opt/conda/envs/opendrift/lib/python3.9/site-packages/matplotlib/pyplot.py'>)

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

Gallery generated by Sphinx-Gallery