Oil vertical mixing

import os
from datetime import 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

ncfile = 'oilmixing.nc'
import_file = False  # Set to True to import previous run

if import_file is True:
    o.io_import_file(ncfile)
else:
    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])

    # Seed oil elements at defined position and time
    o.seed_elements(lon=4.9, lat=62.1, z=0, radius=1000, number=2000,
                    time=reader_arome.start_time)

    # Adjusting some configuration
    #o.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Sundby1983')

    # Running model
    o.run(end_time=reader_arome.start_time + timedelta(hours=12),
          time_step=900, time_step_output=1800, outfile=ncfile)

Out:

13:43:49 INFO    opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.7.1 / v1.7.1-87-g074c1d2)
13:43:49 INFO    opendrift.readers.reader_netCDF_CF_generic: Opening dataset: https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc
13:43:50 INFO    opendrift.readers.reader_netCDF_CF_generic: Opening dataset: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
13:43:52 INFO    opendrift.models.openoil: Oil type not specified, using default: AASGARD A 2003
querying DB:
Oil.name ==  'AASGARD A 2003'
13:43:52 INFO    opendrift.models.openoil: Using density 816.6828030078809 and viscosity 3.298187589355751e-05 of oiltype AASGARD A 2003
13:43:52 INFO    opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers:
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_significant_height: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_ice_area_fraction: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_ice_x_velocity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    sea_ice_y_velocity: 0.000000
13:43:52 INFO    opendrift.models.basemodel:    ocean_vertical_diffusivity: 0.020000
13:43:52 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:43:52 INFO    opendrift_landmask_data.mask: locking landmask for generation..
13:43:52 INFO    opendrift_landmask_data.mask: decompressing memmap landmask to /tmp/landmask/mask.dat..
13:44:03 INFO    opendrift_landmask_data.mask: landmask generated
13:44:06 INFO    opendrift.models.basemodel: Using existing reader for land_binary_mask
13:44:06 INFO    opendrift.models.basemodel: All points are in ocean
13:44:06 INFO    opendrift.models.openoil: Oil-water surface tension is 0.028134 Nm
13:44:06 INFO    opendrift.models.basemodel: 2021-09-24 11:00:00 - step 1 of 48 - 2000 active elements (0 deactivated)
13:44:08 INFO    opendrift.models.basemodel: 2021-09-24 11:15:00 - step 2 of 48 - 2000 active elements (0 deactivated)
13:44:10 INFO    opendrift.models.basemodel: 2021-09-24 11:30:00 - step 3 of 48 - 2000 active elements (0 deactivated)
13:44:10 INFO    opendrift.models.basemodel: 2021-09-24 11:45:00 - step 4 of 48 - 2000 active elements (0 deactivated)
13:44:10 INFO    opendrift.models.basemodel: 2021-09-24 12:00:00 - step 5 of 48 - 2000 active elements (0 deactivated)
13:44:10 INFO    opendrift.models.basemodel: 2021-09-24 12:15:00 - step 6 of 48 - 2000 active elements (0 deactivated)
13:44:12 INFO    opendrift.models.basemodel: 2021-09-24 12:30:00 - step 7 of 48 - 2000 active elements (0 deactivated)
13:44:12 INFO    opendrift.models.basemodel: 2021-09-24 12:45:00 - step 8 of 48 - 2000 active elements (0 deactivated)
13:44:12 INFO    opendrift.models.basemodel: 2021-09-24 13:00:00 - step 9 of 48 - 2000 active elements (0 deactivated)
13:44:12 INFO    opendrift.models.basemodel: 2021-09-24 13:15:00 - step 10 of 48 - 2000 active elements (0 deactivated)
13:44:14 INFO    opendrift.models.basemodel: 2021-09-24 13:30:00 - step 11 of 48 - 2000 active elements (0 deactivated)
13:44:15 INFO    opendrift.models.basemodel: 2021-09-24 13:45:00 - step 12 of 48 - 2000 active elements (0 deactivated)
13:44:15 INFO    opendrift.models.basemodel: 2021-09-24 14:00:00 - step 13 of 48 - 2000 active elements (0 deactivated)
13:44:15 INFO    opendrift.models.basemodel: 2021-09-24 14:15:00 - step 14 of 48 - 2000 active elements (0 deactivated)
13:44:16 INFO    opendrift.models.basemodel: 2021-09-24 14:30:00 - step 15 of 48 - 2000 active elements (0 deactivated)
13:44:17 INFO    opendrift.models.basemodel: 2021-09-24 14:45:00 - step 16 of 48 - 2000 active elements (0 deactivated)
13:44:17 WARNING opendrift.readers.basereader.structured: 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`.
13:44:17 WARNING opendrift.readers.basereader.structured: 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`.
13:44:17 INFO    opendrift.models.basemodel: 2021-09-24 15:00:00 - step 17 of 48 - 2000 active elements (0 deactivated)
13:44:17 INFO    opendrift.models.basemodel: 2021-09-24 15:15:00 - step 18 of 48 - 2000 active elements (0 deactivated)
13:44:19 INFO    opendrift.models.basemodel: 2021-09-24 15:30:00 - step 19 of 48 - 1999 active elements (1 deactivated)
13:44:19 INFO    opendrift.models.basemodel: 2021-09-24 15:45:00 - step 20 of 48 - 1993 active elements (7 deactivated)
13:44:19 WARNING opendrift.readers.basereader.structured: 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`.
13:44:19 WARNING opendrift.readers.basereader.structured: 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`.
13:44:19 INFO    opendrift.models.basemodel: 2021-09-24 16:00:00 - step 21 of 48 - 1989 active elements (11 deactivated)
13:44:19 INFO    opendrift.models.basemodel: 2021-09-24 16:15:00 - step 22 of 48 - 1985 active elements (15 deactivated)
13:44:21 INFO    opendrift.models.basemodel: 2021-09-24 16:30:00 - step 23 of 48 - 1983 active elements (17 deactivated)
13:44:21 INFO    opendrift.models.basemodel: 2021-09-24 16:45:00 - step 24 of 48 - 1982 active elements (18 deactivated)
13:44:21 WARNING opendrift.readers.basereader.structured: 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`.
13:44:21 WARNING opendrift.readers.basereader.structured: 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`.
13:44:22 INFO    opendrift.models.basemodel: 2021-09-24 17:00:00 - step 25 of 48 - 1982 active elements (18 deactivated)
13:44:22 INFO    opendrift.models.basemodel: 2021-09-24 17:15:00 - step 26 of 48 - 1982 active elements (18 deactivated)
13:44:24 INFO    opendrift.models.basemodel: 2021-09-24 17:30:00 - step 27 of 48 - 1981 active elements (19 deactivated)
13:44:24 INFO    opendrift.models.basemodel: 2021-09-24 17:45:00 - step 28 of 48 - 1981 active elements (19 deactivated)
13:44:24 INFO    opendrift.models.basemodel: 2021-09-24 18:00:00 - step 29 of 48 - 1980 active elements (20 deactivated)
13:44:24 INFO    opendrift.models.basemodel: 2021-09-24 18:15:00 - step 30 of 48 - 1980 active elements (20 deactivated)
13:44:26 INFO    opendrift.models.basemodel: 2021-09-24 18:30:00 - step 31 of 48 - 1980 active elements (20 deactivated)
13:44:26 INFO    opendrift.models.basemodel: 2021-09-24 18:45:00 - step 32 of 48 - 1980 active elements (20 deactivated)
13:44:26 INFO    opendrift.models.basemodel: 2021-09-24 19:00:00 - step 33 of 48 - 1980 active elements (20 deactivated)
13:44:26 INFO    opendrift.models.basemodel: 2021-09-24 19:15:00 - step 34 of 48 - 1980 active elements (20 deactivated)
13:44:28 INFO    opendrift.models.basemodel: 2021-09-24 19:30:00 - step 35 of 48 - 1978 active elements (22 deactivated)
13:44:29 INFO    opendrift.models.basemodel: 2021-09-24 19:45:00 - step 36 of 48 - 1978 active elements (22 deactivated)
13:44:29 INFO    opendrift.models.basemodel: 2021-09-24 20:00:00 - step 37 of 48 - 1978 active elements (22 deactivated)
13:44:29 INFO    opendrift.models.basemodel: 2021-09-24 20:15:00 - step 38 of 48 - 1978 active elements (22 deactivated)
13:44:31 INFO    opendrift.models.basemodel: 2021-09-24 20:30:00 - step 39 of 48 - 1978 active elements (22 deactivated)
13:44:31 INFO    opendrift.models.basemodel: 2021-09-24 20:45:00 - step 40 of 48 - 1978 active elements (22 deactivated)
13:44:32 INFO    opendrift.models.basemodel: 2021-09-24 21:00:00 - step 41 of 48 - 1978 active elements (22 deactivated)
13:44:32 INFO    opendrift.models.basemodel: 2021-09-24 21:15:00 - step 42 of 48 - 1978 active elements (22 deactivated)
13:44:34 INFO    opendrift.models.basemodel: 2021-09-24 21:30:00 - step 43 of 48 - 1978 active elements (22 deactivated)
13:44:34 INFO    opendrift.models.basemodel: 2021-09-24 21:45:00 - step 44 of 48 - 1978 active elements (22 deactivated)
13:44:34 INFO    opendrift.models.basemodel: 2021-09-24 22:00:00 - step 45 of 48 - 1978 active elements (22 deactivated)
13:44:35 INFO    opendrift.models.basemodel: 2021-09-24 22:15:00 - step 46 of 48 - 1978 active elements (22 deactivated)
13:44:39 INFO    opendrift.models.basemodel: 2021-09-24 22:30:00 - step 47 of 48 - 1978 active elements (22 deactivated)
13:44:39 INFO    opendrift.models.basemodel: 2021-09-24 22:45:00 - step 48 of 48 - 1977 active elements (23 deactivated)
13:44:39 INFO    opendrift.export.io_netcdf: Wrote 25 steps to file oilmixing.nc

Print and plot results

print(o)

o.plot(linecolor='z', fast=True)
o.plot_property('z')
o.plot_oil_budget()
o.animation(fast=True)
o.animate_vertical_distribution()

os.remove(ncfile)  # cleaning up
  • OpenDrift - OpenOil (AASGARD A 2003) 2021-09-24 11:00 to 2021-09-24 23:00 UTC (25 steps)
  • z
  • AASGARD A 2003 (816.7 kg/m3) - 2021-09-24 11:00 to 2021-09-24 23:00

Out:

===========================
--------------------
Reader performance:
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
 0:00:27.0  total
 0:00:00.0  preparing
 0:00:25.2  reading
 0:00:00.7  interpolation
 0:00:00.0  interpolation_time
 0:00:00.0  masking
 0:00:01.7  rotating vectors
--------------------
https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc
--------------------
global_landmask
 0:00:00.1  total
 0:00:00.0  preparing
 0:00:00.1  reading
 0:00:00.0  masking
--------------------
Performance:
   50.6 total time
    2.6 configuration
   14.3 preparing main loop
     14.2 making dynamical landmask
      0.0 moving elements to ocean
     27.6 readers
        0.1 global_landmask
        0.2 postprocessing
   32.7 main loop
       27.1 https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
      4.7 updating elements
        2.2 oil weathering
          0.0 updating viscosities
          1.1 updating densities
          1.0 evaporation
          0.0 emulsification
          0.0 dispersion
        2.2 vertical mixing
    0.7 cleaning up
--------------------
===========================
Model:  OpenOil     (OpenDrift version 1.7.1)
        1973 active Oil particles  (27 deactivated, 0 scheduled)
-------------------
Environment variables:
  -----
  sea_floor_depth_below_sea_level
  sea_water_salinity
  sea_water_temperature
  upward_sea_water_velocity
  x_sea_water_velocity
  y_sea_water_velocity
     1) https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
  -----
  x_wind
  y_wind
     1) https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
     2) https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc
  -----
  land_binary_mask
     1) global_landmask
  -----
Readers not added for the following variables:
  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

Time:
        Start: 2021-09-24 11:00:00
        Present: 2021-09-24 23:00:00
        Calculation steps: 48 * 0:15:00 - total time: 12:00:00
        Output steps: 25 * 0:30:00
===========================

13:44:40 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.
/opt/conda/envs/opendrift/lib/python3.9/site-packages/numpy/ma/core.py:1015: RuntimeWarning: overflow encountered in multiply
  result = self.f(da, db, *args, **kwargs)
13:45:00 WARNING opendrift.models.basemodel: Plotting fast. This will make your plots less accurate.
13:45:01 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_0.gif...
13:45:01 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
13:45:08 INFO    opendrift.models.basemodel: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_1.gif...
13:45:08 INFO    opendrift.models.basemodel: Making animated gif...
MovieWriter imagemagick unavailable; using Pillow instead.
../_images/example_oil_verticalmixing_0.gif ../_images/example_oil_verticalmixing_1.gif

Total running time of the script: ( 1 minutes 34.686 seconds)

Gallery generated by Sphinx-Gallery