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
11:35:34 INFO    opendrift:507: OpenDriftSimulation initialised (version 1.14.2 / v1.14.2-23-g09d0c2d)

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)]
11:35:34 INFO    opendrift.models.basemodel.environment:206: Adding a global landmask from GSHHG
11:35:38 INFO    opendrift.models.basemodel.environment:229: Fallback values will be used for the following variables which have no readers:
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_surface_height: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    upward_sea_water_velocity: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_significant_height: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_ice_area_fraction: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_ice_x_velocity: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_ice_y_velocity: 0.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_water_temperature: 10.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_water_salinity: 34.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    sea_floor_depth_below_sea_level: 10000.000000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    ocean_vertical_diffusivity: 0.020000
11:35:38 INFO    opendrift.models.basemodel.environment:232:    ocean_mixed_layer_thickness: 50.000000
11:35:38 INFO    opendrift.models.openoil.adios.dirjs:86: Querying ADIOS database for oil: EKOFISK
11:35:38 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.
11:35:38 INFO    opendrift.models.openoil.openoil:1712: 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)
11:35:39 INFO    opendrift:911: Using existing reader for land_binary_mask
11:35:39 INFO    opendrift:940: All points are in ocean
11:35:39 INFO    opendrift.models.openoil.openoil:687: Oil-water surface tension is 0.027884 Nm
11:35:39 INFO    opendrift.models.openoil.openoil:700: Max water fraction not available for EKOFISK, using default
11:35:39 INFO    opendrift:2102: 2025-05-28 11:35:34.740499 - step 1 of 48 - 417 active elements (0 deactivated)
11:35:39 INFO    opendrift.readers:61: Opening file with xr.open_dataset
11:35:40 INFO    opendrift.readers.reader_netCDF_CF_generic:332: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
11:35:44 INFO    opendrift:2102: 2025-05-28 12:05:34.740499 - step 2 of 48 - 834 active elements (0 deactivated)
11:35:46 INFO    opendrift:2102: 2025-05-28 12:35:34.740499 - step 3 of 48 - 1250 active elements (0 deactivated)
11:35:46 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`.
11:35:46 INFO    opendrift:2102: 2025-05-28 13:05:34.740499 - step 4 of 48 - 1667 active elements (0 deactivated)
11:35: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`.
11:35:48 INFO    opendrift:2102: 2025-05-28 13:35:34.740499 - step 5 of 48 - 2084 active elements (0 deactivated)
11:35: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`.
11:35:48 INFO    opendrift:2102: 2025-05-28 14:05:34.740499 - step 6 of 48 - 2500 active elements (0 deactivated)
11:35: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`.
11:35:50 INFO    opendrift:2102: 2025-05-28 14:35:34.740499 - step 7 of 48 - 2917 active elements (0 deactivated)
11:35: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`.
11:35:50 INFO    opendrift:2102: 2025-05-28 15:05:34.740499 - step 8 of 48 - 3334 active elements (0 deactivated)
11:35: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`.
11:35:52 INFO    opendrift:2102: 2025-05-28 15:35:34.740499 - step 9 of 48 - 3750 active elements (0 deactivated)
11:35: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`.
11:35:53 INFO    opendrift:2102: 2025-05-28 16:05:34.740499 - step 10 of 48 - 4167 active elements (0 deactivated)
11:35:55 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`.
11:35:55 INFO    opendrift:2102: 2025-05-28 16:35:34.740499 - step 11 of 48 - 4583 active elements (0 deactivated)
11:35:55 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`.
11:35:55 INFO    opendrift:2102: 2025-05-28 17:05:34.740499 - step 12 of 48 - 5000 active elements (0 deactivated)
11:35: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`.
11:35:57 INFO    opendrift:2102: 2025-05-28 17:35:34.740499 - step 13 of 48 - 5417 active elements (0 deactivated)
11:35: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`.
11:35:57 INFO    opendrift:2102: 2025-05-28 18:05:34.740499 - step 14 of 48 - 5833 active elements (0 deactivated)
11:36: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`.
11:36:00 INFO    opendrift:2102: 2025-05-28 18:35:34.740499 - step 15 of 48 - 6250 active elements (0 deactivated)
11:36: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`.
11:36:00 INFO    opendrift:2102: 2025-05-28 19:05:34.740499 - step 16 of 48 - 6667 active elements (0 deactivated)
11:36:02 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`.
11:36:02 INFO    opendrift:2102: 2025-05-28 19:35:34.740499 - step 17 of 48 - 7083 active elements (0 deactivated)
11:36:02 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`.
11:36:02 INFO    opendrift:2102: 2025-05-28 20:05:34.740499 - step 18 of 48 - 7500 active elements (0 deactivated)
11:36:05 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`.
11:36:05 INFO    opendrift:2102: 2025-05-28 20:35:34.740499 - step 19 of 48 - 7916 active elements (0 deactivated)
11:36: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`.
11:36:07 INFO    opendrift:2102: 2025-05-28 21:05:34.740499 - step 20 of 48 - 8333 active elements (0 deactivated)
11:36:09 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`.
11:36:12 INFO    opendrift:2102: 2025-05-28 21:35:34.740499 - step 21 of 48 - 8749 active elements (1 deactivated)
11:36: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`.
11:36:12 INFO    opendrift:2102: 2025-05-28 22:05:34.740499 - step 22 of 48 - 9163 active elements (3 deactivated)
11:36:15 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`.
11:36:15 INFO    opendrift:2102: 2025-05-28 22:35:34.740499 - step 23 of 48 - 9575 active elements (8 deactivated)
11:36:15 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`.
11:36:16 INFO    opendrift:2102: 2025-05-28 23:05:34.740499 - step 24 of 48 - 9983 active elements (17 deactivated)
11:36: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`.
11:36:18 INFO    opendrift:2102: 2025-05-28 23:35:34.740499 - step 25 of 48 - 9972 active elements (28 deactivated)
11:36: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`.
11:36:19 INFO    opendrift:2102: 2025-05-29 00:05:34.740499 - step 26 of 48 - 9963 active elements (37 deactivated)
11:36:21 INFO    opendrift:2102: 2025-05-29 00:35:34.740499 - step 27 of 48 - 9955 active elements (45 deactivated)
11:36:22 INFO    opendrift:2102: 2025-05-29 01:05:34.740499 - step 28 of 48 - 9947 active elements (53 deactivated)
11:36:24 INFO    opendrift:2102: 2025-05-29 01:35:34.740499 - step 29 of 48 - 9940 active elements (60 deactivated)
11:36:25 INFO    opendrift:2102: 2025-05-29 02:05:34.740499 - step 30 of 48 - 9938 active elements (62 deactivated)
11:36:28 INFO    opendrift:2102: 2025-05-29 02:35:34.740499 - step 31 of 48 - 9927 active elements (73 deactivated)
11:36:28 INFO    opendrift:2102: 2025-05-29 03:05:34.740499 - step 32 of 48 - 9917 active elements (83 deactivated)
11:36:31 INFO    opendrift:2102: 2025-05-29 03:35:34.740499 - step 33 of 48 - 9910 active elements (90 deactivated)
11:36:31 INFO    opendrift:2102: 2025-05-29 04:05:34.740499 - step 34 of 48 - 9896 active elements (104 deactivated)
11:36:34 INFO    opendrift:2102: 2025-05-29 04:35:34.740499 - step 35 of 48 - 9886 active elements (114 deactivated)
11:36:35 INFO    opendrift:2102: 2025-05-29 05:05:34.740499 - step 36 of 48 - 9870 active elements (130 deactivated)
11:36:37 INFO    opendrift:2102: 2025-05-29 05:35:34.740499 - step 37 of 48 - 9862 active elements (138 deactivated)
11:36:38 INFO    opendrift:2102: 2025-05-29 06:05:34.740499 - step 38 of 48 - 9854 active elements (146 deactivated)
11:36:41 INFO    opendrift:2102: 2025-05-29 06:35:34.740499 - step 39 of 48 - 9845 active elements (155 deactivated)
11:36:41 INFO    opendrift:2102: 2025-05-29 07:05:34.740499 - step 40 of 48 - 9837 active elements (163 deactivated)
11:36:45 INFO    opendrift:2102: 2025-05-29 07:35:34.740499 - step 41 of 48 - 9833 active elements (167 deactivated)
11:36:46 INFO    opendrift:2102: 2025-05-29 08:05:34.740499 - step 42 of 48 - 9830 active elements (170 deactivated)
11:36:48 INFO    opendrift:2102: 2025-05-29 08:35:34.740499 - step 43 of 48 - 9822 active elements (178 deactivated)
11:36:49 INFO    opendrift:2102: 2025-05-29 09:05:34.740499 - step 44 of 48 - 9810 active elements (190 deactivated)
11:36:52 INFO    opendrift:2102: 2025-05-29 09:35:34.740499 - step 45 of 48 - 9805 active elements (195 deactivated)
11:36:52 INFO    opendrift:2102: 2025-05-29 10:05:34.740499 - step 46 of 48 - 9797 active elements (203 deactivated)
11:36:55 INFO    opendrift:2102: 2025-05-29 10:35:34.740499 - step 47 of 48 - 9793 active elements (207 deactivated)
11:36:56 INFO    opendrift:2102: 2025-05-29 11:05:34.740499 - step 48 of 48 - 9790 active elements (210 deactivated)
<xarray.Dataset> Size: 44MB
Dimensions:                                                                              (
                                                                                          trajectory: 10000,
                                                                                          time: 25)
Coordinates:
  * trajectory                                                                           (trajectory) int64 80kB ...
  * time                                                                                 (time) datetime64[ns] 200B ...
Data variables: (12/44)
    status                                                                               (trajectory, time) float32 1MB ...
    moving                                                                               (trajectory, time) float32 1MB ...
    age_seconds                                                                          (trajectory, time) float32 1MB ...
    origin_marker                                                                        (trajectory, time) float32 1MB ...
    lon                                                                                  (trajectory, time) float32 1MB ...
    lat                                                                                  (trajectory, time) float32 1MB ...
    ...                                                                                   ...
    sea_water_temperature                                                                (trajectory, time) float32 1MB ...
    sea_water_salinity                                                                   (trajectory, time) float32 1MB ...
    sea_floor_depth_below_sea_level                                                      (trajectory, time) float32 1MB ...
    ocean_vertical_diffusivity                                                           (trajectory, time) float32 1MB ...
    land_binary_mask                                                                     (trajectory, time) float32 1MB ...
    ocean_mixed_layer_thickness                                                          (trajectory, time) float32 1MB ...
Attributes: (12/164)
    Conventions:                                                             ...
    standard_name_vocabulary:                                                ...
    featureType:                                                             ...
    title:                                                                   ...
    summary:                                                                 ...
    keywords:                                                                ...
    ...                                                                                                               ...
    geospatial_lon_units:                                                    ...
    geospatial_lon_resolution:                                               ...
    runtime:                                                                 ...
    geospatial_vertical_min:                                                 ...
    geospatial_vertical_max:                                                 ...
    geospatial_vertical_positive:                                            ...


Print and plot results

print(o)
===========================
--------------------
Reader performance:
--------------------
global_landmask
 0:00:01.6  total
 0:00:00.0  preparing
 0:00:01.6  reading
 0:00:00.0  masking
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
 0:01:01.5  total
 0:00:00.0  preparing
 0:01:00.2  reading
 0:00:03.3  interpolation
 0:00:00.1  interpolation_time
 0:00:01.3  rotating vectors
 0:00:00.0  masking
--------------------
Performance:
 1:24.4 total time
    4.2 configuration
    0.1 preparing main loop
      0.0 moving elements to ocean
 1:19.9 main loop
      9.1 updating elements
        0.1 oil weathering
          0.0 updating viscosities
          0.0 updating densities
          0.0 emulsification
          0.0 dispersion
        8.2 vertical mixing
    0.0 cleaning up
--------------------
===========================
Model:  OpenOil     (OpenDrift version 1.14.2)
        9778 active Oil particles  (222 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-05-28 11:35:34.740499 UTC
        Present: 2025-05-29 11:35:34.740499 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)
11:37:29 INFO    opendrift:4609: Saving animation to /root/project/docs/source/gallery/animations/example_cone_0.gif...
11:37:56 INFO    opendrift:3062: Time to make animation: 0:00:57.521198
../_images/example_cone_0.gif
o.plot(fast=True, ocean_color='skyblue', land_color='dimgray', text=text)
OpenDrift - OpenOil (EKOFISK) 2025-05-28 11:35 to 2025-05-29 11:35 UTC (25 steps)
11:37:56 WARNING opendrift:2459: Plotting fast. This will make your plots less accurate.

(<GeoAxes: title={'center': 'OpenDrift - OpenOil (EKOFISK)\n2025-05-28 11:35 to 2025-05-29 11:35 UTC (25 steps)'}>, <Figure size 779.006x1100 with 1 Axes>)

Total running time of the script: (2 minutes 59.518 seconds)

Gallery generated by Sphinx-Gallery