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:26:32 INFO opendrift:509: OpenDriftSimulation initialised (version 1.13.1 / v1.13.1-12-gca7f755)
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)
15:26:32 INFO opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
15:26:36 INFO opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_surface_height: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: upward_sea_water_velocity: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_significant_height: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_x_velocity: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_stokes_drift_y_velocity: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_ice_area_fraction: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_ice_x_velocity: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_ice_y_velocity: 0.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_water_temperature: 10.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_water_salinity: 34.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: sea_floor_depth_below_sea_level: 10000.000000
15:26:36 INFO opendrift.models.basemodel.environment:232: ocean_vertical_diffusivity: 0.020000
15:26:36 INFO opendrift.models.basemodel.environment:232: ocean_mixed_layer_thickness: 50.000000
15:26:36 INFO opendrift.models.openoil.adios.dirjs:86: Querying ADIOS database for oil: EKOFISK
15:26:36 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:26:36 INFO opendrift.models.openoil.openoil:1710: Using density 809.002835 and viscosity 3.3498550728972226e-06 of oiltype EKOFISK
===========================
Model: OpenOil (OpenDrift version 1.13.1)
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:26:36 INFO opendrift:919: Using existing reader for land_binary_mask
15:26:36 INFO opendrift:930: All points are in ocean
15:26:36 INFO opendrift.models.openoil.openoil:685: Oil-water surface tension is 0.027884 Nm
15:26:36 INFO opendrift.models.openoil.openoil:698: Max water fraction not available for EKOFISK, using default
15:26:36 INFO opendrift:2056: 2025-04-03 15:26:32.063333 - step 1 of 48 - 417 active elements (0 deactivated)
15:26:36 INFO opendrift.readers:61: Opening file with xr.open_dataset
15:26:38 INFO opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
15:26:42 INFO opendrift:2056: 2025-04-03 15:56:32.063333 - step 2 of 48 - 834 active elements (0 deactivated)
15:26:44 INFO opendrift:2056: 2025-04-03 16:26:32.063333 - step 3 of 48 - 1250 active elements (0 deactivated)
15:26:44 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:26:45 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:26:45 INFO opendrift:2056: 2025-04-03 16:56:32.063333 - step 4 of 48 - 1667 active elements (0 deactivated)
15:26:45 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:26:47 INFO opendrift:2056: 2025-04-03 17:26:32.063333 - step 5 of 48 - 2084 active elements (0 deactivated)
15:26:47 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:26:48 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:26:48 INFO opendrift:2056: 2025-04-03 17:56:32.063333 - step 6 of 48 - 2500 active elements (0 deactivated)
15:26:48 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:26:49 INFO opendrift:2056: 2025-04-03 18:26:32.063333 - step 7 of 48 - 2917 active elements (0 deactivated)
15:26:50 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:26:51 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:26:51 INFO opendrift:2056: 2025-04-03 18:56:32.063333 - step 8 of 48 - 3334 active elements (0 deactivated)
15:26:51 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:26:52 INFO opendrift:2056: 2025-04-03 19:26:32.063333 - step 9 of 48 - 3750 active elements (0 deactivated)
15:26:52 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:26:54 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:26:54 INFO opendrift:2056: 2025-04-03 19:56:32.063333 - step 10 of 48 - 4167 active elements (0 deactivated)
15:26:54 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:26:56 INFO opendrift:2056: 2025-04-03 20:26:32.063333 - step 11 of 48 - 4583 active elements (0 deactivated)
15:26:56 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:26:57 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:26:57 INFO opendrift:2056: 2025-04-03 20:56:32.063333 - step 12 of 48 - 5000 active elements (0 deactivated)
15:26:57 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:26:59 INFO opendrift:2056: 2025-04-03 21:26:32.063333 - step 13 of 48 - 5417 active elements (0 deactivated)
15:26:59 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:27:00 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:27:00 INFO opendrift:2056: 2025-04-03 21:56:32.063333 - step 14 of 48 - 5833 active elements (0 deactivated)
15:27:00 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:27:02 INFO opendrift:2056: 2025-04-03 22:26:32.063333 - step 15 of 48 - 6250 active elements (0 deactivated)
15:27:03 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:27:04 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:27:04 INFO opendrift:2056: 2025-04-03 22:56:32.063333 - step 16 of 48 - 6667 active elements (0 deactivated)
15:27:04 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:27:06 INFO opendrift:2056: 2025-04-03 23:26:32.063333 - step 17 of 48 - 7083 active elements (0 deactivated)
15:27:06 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:27:07 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:27:08 INFO opendrift:2056: 2025-04-03 23:56:32.063333 - step 18 of 48 - 7500 active elements (0 deactivated)
15:27: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:27:10 INFO opendrift:2056: 2025-04-04 00:26:32.063333 - step 19 of 48 - 7916 active elements (0 deactivated)
15:27: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:27:11 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:27:11 INFO opendrift:2056: 2025-04-04 00:56:32.063333 - step 20 of 48 - 8333 active elements (0 deactivated)
15:27:11 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:27:14 INFO opendrift:2056: 2025-04-04 01:26:32.063333 - step 21 of 48 - 8750 active elements (0 deactivated)
15:27:17 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:27: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:27:18 INFO opendrift:2056: 2025-04-04 01:56:32.063333 - step 22 of 48 - 9165 active elements (1 deactivated)
15:27: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:27:20 INFO opendrift:2056: 2025-04-04 02:26:32.063333 - step 23 of 48 - 9581 active elements (2 deactivated)
15:27: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:27:22 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:27:22 INFO opendrift:2056: 2025-04-04 02:56:32.063333 - step 24 of 48 - 9997 active elements (3 deactivated)
15:27:22 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:27:22 INFO opendrift:2056: 2025-04-04 03:26:32.063333 - step 25 of 48 - 9996 active elements (4 deactivated)
15:27:25 INFO opendrift:2056: 2025-04-04 03:56:32.063333 - step 26 of 48 - 9996 active elements (4 deactivated)
15:27:26 INFO opendrift:2056: 2025-04-04 04:26:32.063333 - step 27 of 48 - 9989 active elements (11 deactivated)
15:27:29 INFO opendrift:2056: 2025-04-04 04:56:32.063333 - step 28 of 48 - 9984 active elements (16 deactivated)
15:27:29 INFO opendrift:2056: 2025-04-04 05:26:32.063333 - step 29 of 48 - 9982 active elements (18 deactivated)
15:27:32 INFO opendrift:2056: 2025-04-04 05:56:32.063333 - step 30 of 48 - 9980 active elements (20 deactivated)
15:27:32 INFO opendrift:2056: 2025-04-04 06:26:32.063333 - step 31 of 48 - 9978 active elements (22 deactivated)
15:27:35 INFO opendrift:2056: 2025-04-04 06:56:32.063333 - step 32 of 48 - 9971 active elements (29 deactivated)
15:27:35 INFO opendrift:2056: 2025-04-04 07:26:32.063333 - step 33 of 48 - 9969 active elements (31 deactivated)
15:27:39 INFO opendrift:2056: 2025-04-04 07:56:32.063333 - step 34 of 48 - 9968 active elements (32 deactivated)
15:27:39 INFO opendrift:2056: 2025-04-04 08:26:32.063333 - step 35 of 48 - 9968 active elements (32 deactivated)
15:27:42 INFO opendrift:2056: 2025-04-04 08:56:32.063333 - step 36 of 48 - 9965 active elements (35 deactivated)
15:27:42 INFO opendrift:2056: 2025-04-04 09:26:32.063333 - step 37 of 48 - 9965 active elements (35 deactivated)
15:27:45 INFO opendrift:2056: 2025-04-04 09:56:32.063333 - step 38 of 48 - 9963 active elements (37 deactivated)
15:27:45 INFO opendrift:2056: 2025-04-04 10:26:32.063333 - step 39 of 48 - 9961 active elements (39 deactivated)
15:27:49 INFO opendrift:2056: 2025-04-04 10:56:32.063333 - step 40 of 48 - 9957 active elements (43 deactivated)
15:27:49 INFO opendrift:2056: 2025-04-04 11:26:32.063333 - step 41 of 48 - 9955 active elements (45 deactivated)
15:27:52 INFO opendrift:2056: 2025-04-04 11:56:32.063333 - step 42 of 48 - 9955 active elements (45 deactivated)
15:27:52 INFO opendrift:2056: 2025-04-04 12:26:32.063333 - step 43 of 48 - 9954 active elements (46 deactivated)
15:27:55 INFO opendrift:2056: 2025-04-04 12:56:32.063333 - step 44 of 48 - 9950 active elements (50 deactivated)
15:27:55 INFO opendrift:2056: 2025-04-04 13:26:32.063333 - step 45 of 48 - 9948 active elements (52 deactivated)
15:27:58 INFO opendrift:2056: 2025-04-04 13:56:32.063333 - step 46 of 48 - 9946 active elements (54 deactivated)
15:27:58 INFO opendrift:2056: 2025-04-04 14:26:32.063333 - step 47 of 48 - 9944 active elements (56 deactivated)
15:28:01 INFO opendrift:2056: 2025-04-04 14:56:32.063333 - step 48 of 48 - 9935 active elements (65 deactivated)
Print and plot results
print(o)
===========================
--------------------
Reader performance:
--------------------
global_landmask
0:00:01.4 total
0:00:00.0 preparing
0:00:01.4 reading
0:00:00.0 masking
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
0:01:11.6 total
0:00:00.0 preparing
0:01:09.7 reading
0:00:02.6 interpolation
0:00:00.0 interpolation_time
0:00:01.8 rotating vectors
0:00:00.0 masking
--------------------
Performance:
1:30.2 total time
4.2 configuration
0.0 preparing main loop
0.0 moving elements to ocean
1:25.9 main loop
6.1 updating elements
0.0 oil weathering
0.0 updating viscosities
0.0 updating densities
0.0 emulsification
0.0 dispersion
5.5 vertical mixing
0.0 cleaning up
--------------------
===========================
Model: OpenOil (OpenDrift version 1.13.1)
9923 active Oil particles (77 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
upward_sea_water_velocity
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-04-03 15:26:32.063333 UTC
Present: 2025-04-04 15:26:32.063333 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:28:15 INFO opendrift:4600: Saving animation to /root/project/docs/source/gallery/animations/example_cone_0.gif...
15:28:29 INFO opendrift:3036: Time to make animation: 0:00:27.508853

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

15:28:29 WARNING opendrift:2429: Plotting fast. This will make your plots less accurate.
(<GeoAxes: title={'center': 'OpenDrift - OpenOil (EKOFISK)\n2025-04-03 15:26 to 2025-04-04 15:26 UTC (25 steps)'}>, <Figure size 685.625x1100 with 1 Axes>)
Total running time of the script: (2 minutes 26.165 seconds)