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])

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

    # 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)

    # Running model
    o.run(end_time=reader_arome.start_time + timedelta(hours=12),
          time_step=900, time_step_output=1800, outfile=ncfile)
13:01:09 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-99-gd2132d3)
13:01:09 INFO    opendrift.readers.reader_netCDF_CF_generic:102: Opening dataset: https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc
13:01:10 INFO    opendrift.readers.reader_netCDF_CF_generic:325: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
13:01:10 INFO    opendrift.readers.reader_netCDF_CF_generic:102: Opening dataset: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
13:01:12 INFO    opendrift.readers.reader_netCDF_CF_generic:325: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
13:01:12 INFO    opendrift.models.openoil.openoil:1710: Oil type not specified, using default: GENERIC BUNKER C
13:01:12 INFO    opendrift.models.openoil.adios.dirjs:90: Querying ADIOS database for oil: GENERIC BUNKER C
13:01:12 INFO    opendrift.models.openoil.openoil:1719: Using density 971.1 and viscosity 0.0005020658058702914 of oiltype GENERIC BUNKER C
13:01:12 INFO    opendrift.models.basemodel.environment:218: 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:01:16 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_ice_area_fraction: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_ice_x_velocity: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    sea_ice_y_velocity: 0.000000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.020000
13:01:16 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000
13:01:17 INFO    opendrift.models.basemodel:936: Using existing reader for land_binary_mask
13:01:17 INFO    opendrift.models.basemodel:947: All points are in ocean
13:01:17 INFO    opendrift.models.openoil.openoil:687: Oil-water surface tension is 0.035282 Nm
13:01:17 INFO    opendrift.models.openoil.openoil:700: Max water fraction not available for GENERIC BUNKER C, using default
13:01:17 WARNING opendrift.models.basemodel:730: Seafloor check not being run because environment is missing. This will happen the first time the function is run but if it happens subsequently there is probably a problem.
13:01:17 INFO    opendrift.models.basemodel:2038: 2024-11-11 10:00:00 - step 1 of 48 - 2000 active elements (0 deactivated)
13:01:18 INFO    opendrift.models.basemodel:2038: 2024-11-11 10:15:00 - step 2 of 48 - 2000 active elements (0 deactivated)
13:01:20 INFO    opendrift.models.basemodel:2038: 2024-11-11 10:30:00 - step 3 of 48 - 2000 active elements (0 deactivated)
13:01:20 INFO    opendrift.models.basemodel:2038: 2024-11-11 10:45:00 - step 4 of 48 - 2000 active elements (0 deactivated)
13:01:21 INFO    opendrift.models.basemodel:2038: 2024-11-11 11:00:00 - step 5 of 48 - 2000 active elements (0 deactivated)
13:01:21 INFO    opendrift.models.basemodel:2038: 2024-11-11 11:15:00 - step 6 of 48 - 2000 active elements (0 deactivated)
13:01:23 INFO    opendrift.models.basemodel:2038: 2024-11-11 11:30:00 - step 7 of 48 - 2000 active elements (0 deactivated)
13:01:23 INFO    opendrift.models.basemodel:2038: 2024-11-11 11:45:00 - step 8 of 48 - 2000 active elements (0 deactivated)
13:01:23 INFO    opendrift.models.basemodel:2038: 2024-11-11 12:00:00 - step 9 of 48 - 2000 active elements (0 deactivated)
13:01:23 INFO    opendrift.models.basemodel:2038: 2024-11-11 12:15:00 - step 10 of 48 - 2000 active elements (0 deactivated)
13:01:25 INFO    opendrift.models.basemodel:2038: 2024-11-11 12:30:00 - step 11 of 48 - 2000 active elements (0 deactivated)
13:01:25 INFO    opendrift.models.basemodel:2038: 2024-11-11 12:45:00 - step 12 of 48 - 2000 active elements (0 deactivated)
13:01:25 INFO    opendrift.models.basemodel:2038: 2024-11-11 13:00:00 - step 13 of 48 - 2000 active elements (0 deactivated)
13:01:26 INFO    opendrift.models.basemodel:2038: 2024-11-11 13:15:00 - step 14 of 48 - 2000 active elements (0 deactivated)
13:01:27 INFO    opendrift.models.basemodel:2038: 2024-11-11 13:30:00 - step 15 of 48 - 2000 active elements (0 deactivated)
13:01:27 INFO    opendrift.models.basemodel:2038: 2024-11-11 13:45:00 - step 16 of 48 - 2000 active elements (0 deactivated)
13:01:28 INFO    opendrift.models.basemodel:2038: 2024-11-11 14:00:00 - step 17 of 48 - 2000 active elements (0 deactivated)
13:01:28 INFO    opendrift.models.basemodel:2038: 2024-11-11 14:15:00 - step 18 of 48 - 2000 active elements (0 deactivated)
13:01:29 INFO    opendrift.models.basemodel:2038: 2024-11-11 14:30:00 - step 19 of 48 - 2000 active elements (0 deactivated)
13:01:30 INFO    opendrift.models.basemodel:2038: 2024-11-11 14:45:00 - step 20 of 48 - 2000 active elements (0 deactivated)
13:01:30 INFO    opendrift.models.basemodel:2038: 2024-11-11 15:00:00 - step 21 of 48 - 2000 active elements (0 deactivated)
13:01:30 INFO    opendrift.models.basemodel:2038: 2024-11-11 15:15:00 - step 22 of 48 - 2000 active elements (0 deactivated)
13:01:32 INFO    opendrift.models.basemodel:2038: 2024-11-11 15:30:00 - step 23 of 48 - 2000 active elements (0 deactivated)
13:01:32 INFO    opendrift.models.basemodel:2038: 2024-11-11 15:45:00 - step 24 of 48 - 2000 active elements (0 deactivated)
13:01:32 INFO    opendrift.models.basemodel:2038: 2024-11-11 16:00:00 - step 25 of 48 - 2000 active elements (0 deactivated)
13:01:32 INFO    opendrift.models.basemodel:2038: 2024-11-11 16:15:00 - step 26 of 48 - 2000 active elements (0 deactivated)
13:01:34 INFO    opendrift.models.basemodel:2038: 2024-11-11 16:30:00 - step 27 of 48 - 2000 active elements (0 deactivated)
13:01:34 INFO    opendrift.models.basemodel:2038: 2024-11-11 16:45:00 - step 28 of 48 - 2000 active elements (0 deactivated)
13:01:34 INFO    opendrift.models.basemodel:2038: 2024-11-11 17:00:00 - step 29 of 48 - 2000 active elements (0 deactivated)
13:01:35 INFO    opendrift.models.basemodel:2038: 2024-11-11 17:15:00 - step 30 of 48 - 2000 active elements (0 deactivated)
13:01:36 INFO    opendrift.models.basemodel:2038: 2024-11-11 17:30:00 - step 31 of 48 - 2000 active elements (0 deactivated)
13:01:37 INFO    opendrift.models.basemodel:2038: 2024-11-11 17:45:00 - step 32 of 48 - 2000 active elements (0 deactivated)
13:01:37 INFO    opendrift.models.basemodel:2038: 2024-11-11 18:00:00 - step 33 of 48 - 2000 active elements (0 deactivated)
13:01:37 INFO    opendrift.models.basemodel:2038: 2024-11-11 18:15:00 - step 34 of 48 - 2000 active elements (0 deactivated)
13:01:39 INFO    opendrift.models.basemodel:2038: 2024-11-11 18:30:00 - step 35 of 48 - 2000 active elements (0 deactivated)
13:01:39 INFO    opendrift.models.basemodel:2038: 2024-11-11 18:45:00 - step 36 of 48 - 2000 active elements (0 deactivated)
13:01:39 INFO    opendrift.models.basemodel:2038: 2024-11-11 19:00:00 - step 37 of 48 - 2000 active elements (0 deactivated)
13:01:39 INFO    opendrift.models.basemodel:2038: 2024-11-11 19:15:00 - step 38 of 48 - 2000 active elements (0 deactivated)
13:01:43 INFO    opendrift.models.basemodel:2038: 2024-11-11 19:30:00 - step 39 of 48 - 2000 active elements (0 deactivated)
13:01:43 INFO    opendrift.models.basemodel:2038: 2024-11-11 19:45:00 - step 40 of 48 - 2000 active elements (0 deactivated)
13:01:45 INFO    opendrift.models.basemodel:2038: 2024-11-11 20:00:00 - step 41 of 48 - 1999 active elements (1 deactivated)
13:01:45 INFO    opendrift.models.basemodel:2038: 2024-11-11 20:15:00 - step 42 of 48 - 1999 active elements (1 deactivated)
13:01:47 INFO    opendrift.models.basemodel:2038: 2024-11-11 20:30:00 - step 43 of 48 - 1995 active elements (5 deactivated)
13:01:47 INFO    opendrift.models.basemodel:2038: 2024-11-11 20:45:00 - step 44 of 48 - 1993 active elements (7 deactivated)
13:01:47 INFO    opendrift.models.basemodel:2038: 2024-11-11 21:00:00 - step 45 of 48 - 1985 active elements (15 deactivated)
13:01:48 INFO    opendrift.models.basemodel:2038: 2024-11-11 21:15:00 - step 46 of 48 - 1979 active elements (21 deactivated)
13:01:49 INFO    opendrift.models.basemodel:2038: 2024-11-11 21:30:00 - step 47 of 48 - 1974 active elements (26 deactivated)
13:01:49 INFO    opendrift.models.basemodel:2038: 2024-11-11 21:45:00 - step 48 of 48 - 1969 active elements (31 deactivated)
13:01:50 INFO    opendrift.export.io_netcdf:121: 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 (GENERIC BUNKER C) 2024-11-11 10:00 to 2024-11-11 22:00 UTC (25 steps)
  • z
  • GENERIC BUNKER C (971.1 kg/m3) - 2024-11-11 10:00 to 2024-11-11 22:00
===========================
--------------------
Reader performance:
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
 0:00:23.2  total
 0:00:00.0  preparing
 0:00:22.0  reading
 0:00:00.8  interpolation
 0:00:00.0  interpolation_time
 0:00:01.1  rotating vectors
 0:00:00.0  masking
--------------------
https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc
--------------------
global_landmask
 0:00:01.6  total
 0:00:00.0  preparing
 0:00:01.6  reading
 0:00:00.0  masking
--------------------
Performance:
   40.5 total time
    7.3 configuration
    0.2 preparing main loop
      0.0 moving elements to ocean
   32.9 main loop
      4.9 updating elements
        2.0 oil weathering
          0.0 updating viscosities
          0.0 updating densities
          1.9 evaporation
          0.0 emulsification
          0.0 dispersion
        2.6 vertical mixing
    0.0 cleaning up
--------------------
===========================
Model:  OpenOil     (OpenDrift version 1.11.13)
        1959 active Oil particles  (41 deactivated, 0 scheduled)
-------------------
Environment variables:
  -----
  sea_floor_depth_below_sea_level
  sea_surface_height
  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_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: 2024-11-11 10:00:00 UTC
        Present: 2024-11-11 22:00:00 UTC
        Calculation steps: 48 * 0:15:00 - total time: 12:00:00
        Output steps: 25 * 0:30:00
===========================

13:01:50 WARNING opendrift.models.basemodel:2411: Plotting fast. This will make your plots less accurate.
13:02:24 WARNING opendrift.models.basemodel:2411: Plotting fast. This will make your plots less accurate.
/opt/conda/envs/opendrift/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1692: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
  result = super().scatter(*args, **kwargs)
13:02:27 INFO    opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_0.gif...
13:02:44 INFO    opendrift.models.basemodel:3037: Time to make animation: 0:00:19.188789
13:02:45 INFO    opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_1.gif...
13:02:57 INFO    opendrift.models.oceandrift:722: Time to make animation: 0:00:13.655603
../_images/example_oil_verticalmixing_0.gif ../_images/example_oil_verticalmixing_1.gif

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

Gallery generated by Sphinx-Gallery