Generic example

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

# Arome atmospheric model
reader_arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')
# Norkyst ocean model
reader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() + '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')

# Uncomment to use live data from thredds
#reader_arome = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc')
#reader_norkyst = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')

o.add_reader([reader_norkyst, reader_arome])

Out:

13:47:57 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.7.1 / v1.7.1-87-g074c1d2)
13:47:57 INFO    opendrift.readers.reader_netCDF_CF_generic: Opening dataset: /root/project/tests/test_data/16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc
13:47:57 INFO    opendrift.readers.reader_netCDF_CF_generic: Opening dataset: /root/project/tests/test_data/16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc

Seeding some particles time = datetime(2015, 9, 22, 6, 0, 0)

time = [reader_arome.start_time,
        reader_arome.start_time + timedelta(hours=30)]
#time = reader_arome.start_time

# Seed oil elements at defined position and time
o.seed_elements(lon=4.6, lat=60.0, radius=50, number=3000, time=time,
                wind_drift_factor=.02)

Out:

13:47:57 INFO    opendrift.models.openoil: Oil type not specified, using default: AASGARD A 2003
querying DB:
Oil.name ==  'AASGARD A 2003'
13:47:57 INFO    opendrift.models.openoil: Using density 816.6828030078809 and viscosity 3.298187589355751e-05 of oiltype AASGARD A 2003

Adjusting some configuration

o.set_config('drift:vertical_mixing', False)
o.set_config('processes:dispersion', False)
o.set_config('processes:evaporation', False)
o.set_config('processes:emulsification', True)
o.set_config('drift:current_uncertainty', .1)
o.set_config('drift:wind_uncertainty', 1)

Running model

o.run(end_time=reader_norkyst.end_time, time_step=1800,
      time_step_output=3600, outfile='openoil.nc',
      export_variables=['mass_oil'])

Out:

13:47:57 INFO    opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers:
13:47:57 INFO    opendrift.models.basemodel:    upward_sea_water_velocity: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_surface_wave_significant_height: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_ice_area_fraction: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_ice_x_velocity: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_ice_y_velocity: 0.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_water_temperature: 10.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_water_salinity: 34.000000
13:47:57 INFO    opendrift.models.basemodel:    sea_floor_depth_below_sea_level: 10000.000000
13:47:57 INFO    opendrift.models.basemodel:    ocean_vertical_diffusivity: 0.020000
13:47:57 INFO    opendrift.models.basemodel: Adding a dynamical landmask with max. priority based on assumed maximum speed of 1.3 m/s. Adding a customised landmask may be faster...
13:47:59 INFO    opendrift.models.basemodel: Using existing reader for land_binary_mask
13:47:59 INFO    opendrift.models.basemodel: All points are in ocean
13:47:59 INFO    opendrift.models.openoil: Oil-water surface tension is 0.028134 Nm
13:47:59 INFO    opendrift.models.basemodel: 2015-11-16 00:00:00 - step 1 of 132 - 50 active elements (0 deactivated)
13:47:59 INFO    opendrift.models.basemodel: 2015-11-16 00:30:00 - step 2 of 132 - 100 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 01:00:00 - step 3 of 132 - 150 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 01:30:00 - step 4 of 132 - 200 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 02:00:00 - step 5 of 132 - 250 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 02:30:00 - step 6 of 132 - 300 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 03:00:00 - step 7 of 132 - 350 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 03:30:00 - step 8 of 132 - 400 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 04:00:00 - step 9 of 132 - 450 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 04:30:00 - step 10 of 132 - 500 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 05:00:00 - step 11 of 132 - 550 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 05:30:00 - step 12 of 132 - 600 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 06:00:00 - step 13 of 132 - 650 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 06:30:00 - step 14 of 132 - 700 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 07:00:00 - step 15 of 132 - 750 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 07:30:00 - step 16 of 132 - 800 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 08:00:00 - step 17 of 132 - 850 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 08:30:00 - step 18 of 132 - 900 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 09:00:00 - step 19 of 132 - 950 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 09:30:00 - step 20 of 132 - 1000 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 10:00:00 - step 21 of 132 - 1050 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 10:30:00 - step 22 of 132 - 1100 active elements (0 deactivated)
13:48:00 INFO    opendrift.models.basemodel: 2015-11-16 11:00:00 - step 23 of 132 - 1150 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 11:30:00 - step 24 of 132 - 1200 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 12:00:00 - step 25 of 132 - 1250 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 12:30:00 - step 26 of 132 - 1300 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 13:00:00 - step 27 of 132 - 1350 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 13:30:00 - step 28 of 132 - 1400 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 14:00:00 - step 29 of 132 - 1450 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 14:30:00 - step 30 of 132 - 1500 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 15:00:00 - step 31 of 132 - 1550 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 15:30:00 - step 32 of 132 - 1600 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 16:00:00 - step 33 of 132 - 1650 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 16:30:00 - step 34 of 132 - 1700 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 17:00:00 - step 35 of 132 - 1750 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 17:30:00 - step 36 of 132 - 1800 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 18:00:00 - step 37 of 132 - 1850 active elements (0 deactivated)
13:48:01 INFO    opendrift.models.basemodel: 2015-11-16 18:30:00 - step 38 of 132 - 1900 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 19:00:00 - step 39 of 132 - 1950 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 19:30:00 - step 40 of 132 - 2000 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 20:00:00 - step 41 of 132 - 2050 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 20:30:00 - step 42 of 132 - 2100 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 21:00:00 - step 43 of 132 - 2150 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 21:30:00 - step 44 of 132 - 2200 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 22:00:00 - step 45 of 132 - 2250 active elements (0 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 22:30:00 - step 46 of 132 - 2296 active elements (4 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 23:00:00 - step 47 of 132 - 2336 active elements (14 deactivated)
13:48:02 INFO    opendrift.models.basemodel: 2015-11-16 23:30:00 - step 48 of 132 - 2376 active elements (24 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 00:00:00 - step 49 of 132 - 2402 active elements (48 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 00:30:00 - step 50 of 132 - 2394 active elements (106 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 01:00:00 - step 51 of 132 - 2361 active elements (189 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 01:30:00 - step 52 of 132 - 2344 active elements (256 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 02:00:00 - step 53 of 132 - 2337 active elements (313 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 02:30:00 - step 54 of 132 - 2305 active elements (395 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 03:00:00 - step 55 of 132 - 2295 active elements (455 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 03:30:00 - step 56 of 132 - 2258 active elements (542 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 04:00:00 - step 57 of 132 - 2189 active elements (661 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 04:30:00 - step 58 of 132 - 2138 active elements (762 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 05:00:00 - step 59 of 132 - 2071 active elements (879 deactivated)
13:48:03 INFO    opendrift.models.basemodel: 2015-11-17 05:30:00 - step 60 of 132 - 2018 active elements (982 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 06:00:00 - step 61 of 132 - 1929 active elements (1071 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 06:30:00 - step 62 of 132 - 1852 active elements (1148 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 07:00:00 - step 63 of 132 - 1771 active elements (1229 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 07:30:00 - step 64 of 132 - 1726 active elements (1274 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 08:00:00 - step 65 of 132 - 1688 active elements (1312 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 08:30:00 - step 66 of 132 - 1651 active elements (1349 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 09:00:00 - step 67 of 132 - 1624 active elements (1376 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 09:30:00 - step 68 of 132 - 1564 active elements (1436 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 10:00:00 - step 69 of 132 - 1497 active elements (1503 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 10:30:00 - step 70 of 132 - 1445 active elements (1555 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 11:00:00 - step 71 of 132 - 1403 active elements (1597 deactivated)
13:48:04 INFO    opendrift.models.basemodel: 2015-11-17 11:30:00 - step 72 of 132 - 1338 active elements (1662 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 12:00:00 - step 73 of 132 - 1256 active elements (1744 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 12:30:00 - step 74 of 132 - 1151 active elements (1849 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 13:00:00 - step 75 of 132 - 1054 active elements (1946 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 13:30:00 - step 76 of 132 - 972 active elements (2028 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 14:00:00 - step 77 of 132 - 883 active elements (2117 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 14:30:00 - step 78 of 132 - 816 active elements (2184 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 15:00:00 - step 79 of 132 - 745 active elements (2255 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 15:30:00 - step 80 of 132 - 695 active elements (2305 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 16:00:00 - step 81 of 132 - 651 active elements (2349 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 16:30:00 - step 82 of 132 - 618 active elements (2382 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 17:00:00 - step 83 of 132 - 593 active elements (2407 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 17:30:00 - step 84 of 132 - 568 active elements (2432 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 18:00:00 - step 85 of 132 - 552 active elements (2448 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 18:30:00 - step 86 of 132 - 537 active elements (2463 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 19:00:00 - step 87 of 132 - 522 active elements (2478 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 19:30:00 - step 88 of 132 - 504 active elements (2496 deactivated)
13:48:05 INFO    opendrift.models.basemodel: 2015-11-17 20:00:00 - step 89 of 132 - 495 active elements (2505 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-17 20:30:00 - step 90 of 132 - 480 active elements (2520 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-17 21:00:00 - step 91 of 132 - 470 active elements (2530 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-17 21:30:00 - step 92 of 132 - 464 active elements (2536 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-17 22:00:00 - step 93 of 132 - 460 active elements (2540 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-17 22:30:00 - step 94 of 132 - 452 active elements (2548 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-17 23:00:00 - step 95 of 132 - 443 active elements (2557 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-17 23:30:00 - step 96 of 132 - 423 active elements (2577 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 00:00:00 - step 97 of 132 - 402 active elements (2598 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 00:30:00 - step 98 of 132 - 375 active elements (2625 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 01:00:00 - step 99 of 132 - 341 active elements (2659 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 01:30:00 - step 100 of 132 - 314 active elements (2686 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 02:00:00 - step 101 of 132 - 270 active elements (2730 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 02:30:00 - step 102 of 132 - 208 active elements (2792 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 03:00:00 - step 103 of 132 - 136 active elements (2864 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 03:30:00 - step 104 of 132 - 79 active elements (2921 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 04:00:00 - step 105 of 132 - 38 active elements (2962 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 04:30:00 - step 106 of 132 - 15 active elements (2985 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 05:00:00 - step 107 of 132 - 8 active elements (2992 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 05:30:00 - step 108 of 132 - 4 active elements (2996 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 06:00:00 - step 109 of 132 - 3 active elements (2997 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 06:30:00 - step 110 of 132 - 1 active elements (2999 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 07:00:00 - step 111 of 132 - 1 active elements (2999 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 07:30:00 - step 112 of 132 - 1 active elements (2999 deactivated)
13:48:06 INFO    opendrift.models.basemodel: 2015-11-18 08:00:00 - step 113 of 132 - 1 active elements (2999 deactivated)
13:48:07 INFO    opendrift.models.basemodel: 2015-11-18 08:30:00 - step 114 of 132 - 1 active elements (2999 deactivated)
13:48:07 INFO    opendrift.models.basemodel: 2015-11-18 09:00:00 - step 115 of 132 - 1 active elements (2999 deactivated)
13:48:07 INFO    opendrift.models.basemodel: 2015-11-18 09:30:00 - step 116 of 132 - 1 active elements (2999 deactivated)
13:48:07 INFO    opendrift.models.basemodel: 2015-11-18 10:00:00 - step 117 of 132 - 1 active elements (2999 deactivated)
13:48:07 INFO    opendrift.models.basemodel: 2015-11-18 10:30:00 - step 118 of 132 - 1 active elements (2999 deactivated)
13:48:07 WARNING opendrift.models.basemodel: The simulation stopped before requested end time was reached.
13:48:07 INFO    opendrift.models.basemodel: ========================
13:48:07 INFO    opendrift.models.basemodel: End of simulation:
13:48:07 INFO    opendrift.models.basemodel: No more active or scheduled elements, quitting.
13:48:07 INFO    opendrift.models.basemodel: Traceback (most recent call last):
  File "/root/project/opendrift/models/basemodel.py", line 2473, in run
    raise ValueError('No more active or scheduled elements, quitting.')
ValueError: No more active or scheduled elements, quitting.

13:48:07 INFO    opendrift.models.basemodel: 'The simulation stopped before requested end time was reached.'

13:48:07 INFO    opendrift.models.basemodel: ========================
13:48:07 INFO    opendrift.export.io_netcdf: Wrote 60 steps to file openoil.nc

Print and plot results

o.plot(fast=True)
#o.plot(background=['x_sea_water_velocity', 'y_sea_water_velocity'], buffer=.5)
#o.animation(fast=True)
#o.animation(density=True, show_elements=False, fast=True)
OpenDrift - OpenOil (AASGARD A 2003) 2015-11-16 00:00 to 2015-11-18 11:00 UTC (60 steps)

Out:

13:48:08 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.

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

Or an animation can be generated with:

o.animation(fast=True)

Out:

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

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

Gallery generated by Sphinx-Gallery