Note
Go to the end to download the full example code.
Cone seeding
from datetime import datetime, timedelta
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.models.openoil import OpenOil
o = OpenOil(loglevel=20) # Set loglevel to 0 for debug information
15:48:56 INFO opendrift:513: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-82-g86a40e4)
Using live data from Thredds
o.add_readers_from_list([
'https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be'])
Adjusting some configuration
o.set_config('processes:dispersion', True)
o.set_config('processes:evaporation', False)
o.set_config('processes:emulsification', True)
Seed elements along cone, e.g. ship track with increasing uncertainty in position
latstart = 68.988911
lonstart = 16.040701
latend = 69.991446
lonend = 17.760061
time = [datetime.utcnow(), datetime.utcnow() + timedelta(hours=12)]
o.seed_cone(lon=[lonstart, lonend], lat=[latstart, latend],
oil_type='EKOFISK', radius=[100, 800], number=10000, time=[time])
print(o)
/root/project/examples/example_cone.py:31: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
time = [datetime.utcnow(), datetime.utcnow() + timedelta(hours=12)]
15:48:56 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
15:49:00 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_surface_height: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_ice_area_fraction: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_ice_x_velocity: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_ice_y_velocity: 0.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_water_temperature: 10.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_water_salinity: 34.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: sea_floor_depth_below_sea_level: 10000.000000
15:49:00 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.020000
15:49:00 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000
15:49:00 INFO opendrift.models.openoil.adios.dirjs:86: Querying ADIOS database for oil: EKOFISK
15:49:00 WARNING opendrift.models.openoil.adios.dirjs:90: Several oils found with name: EKOFISK: ['AD00328', 'AD00329', 'AD00332', 'AD00333', 'AD01944', 'AD02094', 'AD02463', 'AD02558', 'NO00013', 'NO00014', 'NO00015', 'NO00016'], using first.
15:49:00 INFO opendrift.models.openoil.openoil:1717: Using density 809.002835 and viscosity 3.3498550728972226e-06 of oiltype EKOFISK
===========================
Model: OpenOil (OpenDrift version 1.14.2)
0 active Oil particles (0 deactivated, 10000 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_ice_area_fraction
sea_ice_x_velocity
sea_ice_y_velocity
sea_surface_height
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_water_salinity
sea_water_temperature
upward_sea_water_velocity
x_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
---
Lazy readers:
LazyReader: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
Discarded readers:
===========================
Running model for 24 hours
o.run(steps=24*2, time_step=1800, time_step_output=3600)
15:49:00 INFO opendrift:1722: Skipping environment variable upward_sea_water_velocity because of condition ['drift:vertical_advection', 'is', False]
15:49:00 INFO opendrift:1732: Storing previous values of element property lon because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
15:49:00 INFO opendrift:1732: Storing previous values of element property lat because of condition (('general:coastline_action', 'in', ['stranding', 'previous']), 'or', ('general:seafloor_action', 'in', ['previous']))
15:49:01 INFO opendrift:889: Using existing reader for land_binary_mask
15:49:01 INFO opendrift:918: All points are in ocean
15:49:01 INFO opendrift.models.openoil.openoil:692: Oil-water surface tension is 0.027884 Nm
15:49:01 INFO opendrift.models.openoil.openoil:705: Max water fraction not available for EKOFISK, using default
15:49:01 INFO opendrift:2015: 2025-07-02 15:48:56.905681 - step 1 of 48 - 417 active elements (0 deactivated)
15:49:01 INFO opendrift.readers:61: Opening file with xr.open_dataset
15:49:03 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
15:49:06 INFO opendrift:2015: 2025-07-02 16:18:56.905681 - step 2 of 48 - 834 active elements (0 deactivated)
15:49:08 INFO opendrift:2015: 2025-07-02 16:48:56.905681 - step 3 of 48 - 1250 active elements (0 deactivated)
15:49:08 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:08 INFO opendrift:2015: 2025-07-02 17:18:56.905681 - step 4 of 48 - 1667 active elements (0 deactivated)
15:49:10 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:10 INFO opendrift:2015: 2025-07-02 17:48:56.905681 - step 5 of 48 - 2084 active elements (0 deactivated)
15:49:10 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:10 INFO opendrift:2015: 2025-07-02 18:18:56.905681 - step 6 of 48 - 2500 active elements (0 deactivated)
15:49:12 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:12 INFO opendrift:2015: 2025-07-02 18:48:56.905681 - step 7 of 48 - 2917 active elements (0 deactivated)
15:49:12 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:12 INFO opendrift:2015: 2025-07-02 19:18:56.905681 - step 8 of 48 - 3334 active elements (0 deactivated)
15:49:14 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:14 INFO opendrift:2015: 2025-07-02 19:48:56.905681 - step 9 of 48 - 3750 active elements (0 deactivated)
15:49:14 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:14 INFO opendrift:2015: 2025-07-02 20:18:56.905681 - step 10 of 48 - 4167 active elements (0 deactivated)
15:49:16 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:16 INFO opendrift:2015: 2025-07-02 20:48:56.905681 - step 11 of 48 - 4583 active elements (0 deactivated)
15:49:16 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:16 INFO opendrift:2015: 2025-07-02 21:18:56.905681 - step 12 of 48 - 5000 active elements (0 deactivated)
15:49:18 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:18 INFO opendrift:2015: 2025-07-02 21:48:56.905681 - step 13 of 48 - 5417 active elements (0 deactivated)
15:49:18 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:19 INFO opendrift:2015: 2025-07-02 22:18:56.905681 - step 14 of 48 - 5833 active elements (0 deactivated)
15:49:20 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:21 INFO opendrift:2015: 2025-07-02 22:48:56.905681 - step 15 of 48 - 6250 active elements (0 deactivated)
15:49:21 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:21 INFO opendrift:2015: 2025-07-02 23:18:56.905681 - step 16 of 48 - 6667 active elements (0 deactivated)
15:49:23 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:23 INFO opendrift:2015: 2025-07-02 23:48:56.905681 - step 17 of 48 - 7083 active elements (0 deactivated)
15:49:25 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:25 INFO opendrift:2015: 2025-07-03 00:18:56.905681 - step 18 of 48 - 7500 active elements (0 deactivated)
15:49:27 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:29 INFO opendrift:2015: 2025-07-03 00:48:56.905681 - step 19 of 48 - 7915 active elements (1 deactivated)
15:49:29 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:29 INFO opendrift:2015: 2025-07-03 01:18:56.905681 - step 20 of 48 - 8331 active elements (2 deactivated)
15:49:32 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:32 INFO opendrift:2015: 2025-07-03 01:48:56.905681 - step 21 of 48 - 8747 active elements (3 deactivated)
15:49:32 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:32 INFO opendrift:2015: 2025-07-03 02:18:56.905681 - step 22 of 48 - 9163 active elements (3 deactivated)
15:49:35 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:35 INFO opendrift:2015: 2025-07-03 02:48:56.905681 - step 23 of 48 - 9580 active elements (3 deactivated)
15:49:35 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:36 INFO opendrift:2015: 2025-07-03 03:18:56.905681 - step 24 of 48 - 9997 active elements (3 deactivated)
15:49:38 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:38 INFO opendrift:2015: 2025-07-03 03:48:56.905681 - step 25 of 48 - 9992 active elements (8 deactivated)
15:49:38 WARNING opendrift.readers.basereader.structured:326: Data block from https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be not large enough to cover element positions within timestep. Buffer size (8) must be increased. See `Variables.set_buffer_size`.
15:49:39 INFO opendrift:2015: 2025-07-03 04:18:56.905681 - step 26 of 48 - 9991 active elements (9 deactivated)
15:49:41 INFO opendrift:2015: 2025-07-03 04:48:56.905681 - step 27 of 48 - 9991 active elements (9 deactivated)
15:49:41 INFO opendrift:2015: 2025-07-03 05:18:56.905681 - step 28 of 48 - 9986 active elements (14 deactivated)
15:49:44 INFO opendrift:2015: 2025-07-03 05:48:56.905681 - step 29 of 48 - 9985 active elements (15 deactivated)
15:49:44 INFO opendrift:2015: 2025-07-03 06:18:56.905681 - step 30 of 48 - 9984 active elements (16 deactivated)
15:49:46 INFO opendrift:2015: 2025-07-03 06:48:56.905681 - step 31 of 48 - 9984 active elements (16 deactivated)
15:49:47 INFO opendrift:2015: 2025-07-03 07:18:56.905681 - step 32 of 48 - 9984 active elements (16 deactivated)
15:49:49 INFO opendrift:2015: 2025-07-03 07:48:56.905681 - step 33 of 48 - 9984 active elements (16 deactivated)
15:49:49 INFO opendrift:2015: 2025-07-03 08:18:56.905681 - step 34 of 48 - 9984 active elements (16 deactivated)
15:49:52 INFO opendrift:2015: 2025-07-03 08:48:56.905681 - step 35 of 48 - 9984 active elements (16 deactivated)
15:49:52 INFO opendrift:2015: 2025-07-03 09:18:56.905681 - step 36 of 48 - 9981 active elements (19 deactivated)
15:49:55 INFO opendrift:2015: 2025-07-03 09:48:56.905681 - step 37 of 48 - 9975 active elements (25 deactivated)
15:49:55 INFO opendrift:2015: 2025-07-03 10:18:56.905681 - step 38 of 48 - 9964 active elements (36 deactivated)
15:49:58 INFO opendrift:2015: 2025-07-03 10:48:56.905681 - step 39 of 48 - 9934 active elements (66 deactivated)
15:49:58 INFO opendrift:2015: 2025-07-03 11:18:56.905681 - step 40 of 48 - 9899 active elements (101 deactivated)
15:50:01 INFO opendrift:2015: 2025-07-03 11:48:56.905681 - step 41 of 48 - 9880 active elements (120 deactivated)
15:50:01 INFO opendrift:2015: 2025-07-03 12:18:56.905681 - step 42 of 48 - 9873 active elements (127 deactivated)
15:50:04 INFO opendrift:2015: 2025-07-03 12:48:56.905681 - step 43 of 48 - 9863 active elements (137 deactivated)
15:50:04 INFO opendrift:2015: 2025-07-03 13:18:56.905681 - step 44 of 48 - 9856 active elements (144 deactivated)
15:50:06 INFO opendrift:2015: 2025-07-03 13:48:56.905681 - step 45 of 48 - 9852 active elements (148 deactivated)
15:50:07 INFO opendrift:2015: 2025-07-03 14:18:56.905681 - step 46 of 48 - 9846 active elements (154 deactivated)
15:50:10 INFO opendrift:2015: 2025-07-03 14:48:56.905681 - step 47 of 48 - 9841 active elements (159 deactivated)
15:50:10 INFO opendrift:2015: 2025-07-03 15:18:56.905681 - step 48 of 48 - 9828 active elements (172 deactivated)
Print and plot results
print(o)
===========================
--------------------
Reader performance:
--------------------
global_landmask
0:00:01.5 total
0:00:00.0 preparing
0:00:01.5 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
0:00:56.0 total
0:00:00.0 preparing
0:00:54.7 reading
0:00:02.4 interpolation
0:00:00.0 interpolation_time
0:00:01.2 rotating vectors
0:00:00.0 masking
--------------------
Performance:
1:16.0 total time
4.0 configuration
0.1 preparing main loop
0.0 moving elements to ocean
1:11.8 main loop
7.2 updating elements
0.0 oil weathering
0.0 updating viscosities
0.0 updating densities
0.0 emulsification
0.0 dispersion
6.5 vertical mixing
0.0 cleaning up
--------------------
===========================
Model: OpenOil (OpenDrift version 1.14.2)
9811 active Oil particles (189 deactivated, 0 scheduled)
-------------------
Environment variables:
-----
land_binary_mask
1) global_landmask
-----
sea_floor_depth_below_sea_level
sea_surface_height
sea_water_salinity
sea_water_temperature
x_sea_water_velocity
x_wind
y_sea_water_velocity
y_wind
1) https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
-----
Readers not added for the following variables:
ocean_mixed_layer_thickness
ocean_vertical_diffusivity
sea_ice_area_fraction
sea_ice_x_velocity
sea_ice_y_velocity
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
Discarded readers:
Time:
Start: 2025-07-02 15:48:56.905681 UTC
Present: 2025-07-03 15:48:56.905681 UTC
Calculation steps: 48 * 0:30:00 - total time: 1 day, 0:00:00
Output steps: 25 * 1:00:00
===========================
Add text label on the map
text = [{'s': 'Senja', 'x': 17.3, 'y': 69.3, 'fontsize': 20, 'color': 'g',
'backgroundcolor': 'white', 'bbox': dict(facecolor='white', alpha=0.8), 'zorder': 1000}]
o.animation(fast=False, ocean_color='skyblue', land_color='burlywood', text=text)
15:50:24 INFO opendrift:4533: Saving animation to /root/project/docs/source/gallery/animations/example_cone_0.gif...
15:50:43 INFO opendrift:2974: Time to make animation: 0:00:30.397468

o.plot(fast=True, ocean_color='skyblue', land_color='dimgray', text=text)

15:50:43 WARNING opendrift:2371: Plotting fast. This will make your plots less accurate.
(<GeoAxes: title={'center': 'OpenDrift - OpenOil (EKOFISK)\n2025-07-02 15:48 to 2025-07-03 15:48 UTC (25 steps)'}>, <Figure size 741.741x1100 with 1 Axes>)
Total running time of the script: (2 minutes 12.613 seconds)