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)
20:20:25 INFO    opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-26-g390e945)
20:20:25 INFO    opendrift.readers:58: Opening file with xr.open_dataset
20:20:27 INFO    opendrift.readers.reader_netCDF_CF_generic:337: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
20:20:27 INFO    opendrift.readers:58: Opening file with xr.open_dataset
20:20:34 INFO    opendrift.readers.reader_netCDF_CF_generic:337: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
20:20:34 INFO    opendrift.models.openoil.openoil:1706: Oil type not specified, using default: GENERIC BUNKER C
20:20:34 INFO    opendrift.models.openoil.adios.dirjs:86: Querying ADIOS database for oil: GENERIC BUNKER C
20:20:34 INFO    opendrift.models.openoil.openoil:1715: Using density 988.1 and viscosity 0.021692333877975645 of oiltype GENERIC BUNKER C
20:20:34 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...
20:20:37 INFO    opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_significant_height: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_x_velocity: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_stokes_drift_y_velocity: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_ice_area_fraction: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_ice_x_velocity: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    sea_ice_y_velocity: 0.000000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    ocean_vertical_diffusivity: 0.020000
20:20:37 INFO    opendrift.models.basemodel.environment:248:    ocean_mixed_layer_thickness: 50.000000
20:20:38 INFO    opendrift.models.basemodel:935: Using existing reader for land_binary_mask
20:20:38 INFO    opendrift.models.basemodel:946: All points are in ocean
20:20:38 INFO    opendrift.models.openoil.openoil:684: Oil-water surface tension is 0.035935 Nm
20:20:38 INFO    opendrift.models.openoil.openoil:697: Max water fraction not available for GENERIC BUNKER C, using default
20:20:38 WARNING opendrift.models.basemodel:729: 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.
20:20:38 INFO    opendrift.models.basemodel:2035: 2024-12-12 17:00:00 - step 1 of 48 - 2000 active elements (0 deactivated)
20:20:40 INFO    opendrift.models.basemodel:2035: 2024-12-12 17:15:00 - step 2 of 48 - 2000 active elements (0 deactivated)
20:20:41 INFO    opendrift.models.basemodel:2035: 2024-12-12 17:30:00 - step 3 of 48 - 2000 active elements (0 deactivated)
20:20:42 INFO    opendrift.models.basemodel:2035: 2024-12-12 17:45:00 - step 4 of 48 - 2000 active elements (0 deactivated)
20:20:42 INFO    opendrift.models.basemodel:2035: 2024-12-12 18:00:00 - step 5 of 48 - 2000 active elements (0 deactivated)
20:20:42 INFO    opendrift.models.basemodel:2035: 2024-12-12 18:15:00 - step 6 of 48 - 2000 active elements (0 deactivated)
20:20:44 INFO    opendrift.models.basemodel:2035: 2024-12-12 18:30:00 - step 7 of 48 - 2000 active elements (0 deactivated)
20:20:44 INFO    opendrift.models.basemodel:2035: 2024-12-12 18:45:00 - step 8 of 48 - 2000 active elements (0 deactivated)
20:20:44 INFO    opendrift.models.basemodel:2035: 2024-12-12 19:00:00 - step 9 of 48 - 2000 active elements (0 deactivated)
20:20:44 INFO    opendrift.models.basemodel:2035: 2024-12-12 19:15:00 - step 10 of 48 - 2000 active elements (0 deactivated)
20:20:46 INFO    opendrift.models.basemodel:2035: 2024-12-12 19:30:00 - step 11 of 48 - 2000 active elements (0 deactivated)
20:20:46 INFO    opendrift.models.basemodel:2035: 2024-12-12 19:45:00 - step 12 of 48 - 2000 active elements (0 deactivated)
20:20:47 INFO    opendrift.models.basemodel:2035: 2024-12-12 20:00:00 - step 13 of 48 - 2000 active elements (0 deactivated)
20:20:47 INFO    opendrift.models.basemodel:2035: 2024-12-12 20:15:00 - step 14 of 48 - 2000 active elements (0 deactivated)
20:20:48 INFO    opendrift.models.basemodel:2035: 2024-12-12 20:30:00 - step 15 of 48 - 2000 active elements (0 deactivated)
20:20:49 INFO    opendrift.models.basemodel:2035: 2024-12-12 20:45:00 - step 16 of 48 - 2000 active elements (0 deactivated)
20:20:49 INFO    opendrift.models.basemodel:2035: 2024-12-12 21:00:00 - step 17 of 48 - 2000 active elements (0 deactivated)
20:20:49 INFO    opendrift.models.basemodel:2035: 2024-12-12 21:15:00 - step 18 of 48 - 2000 active elements (0 deactivated)
20:20:51 INFO    opendrift.models.basemodel:2035: 2024-12-12 21:30:00 - step 19 of 48 - 2000 active elements (0 deactivated)
20:20:51 INFO    opendrift.models.basemodel:2035: 2024-12-12 21:45:00 - step 20 of 48 - 2000 active elements (0 deactivated)
20:20:51 INFO    opendrift.models.basemodel:2035: 2024-12-12 22:00:00 - step 21 of 48 - 2000 active elements (0 deactivated)
20:20:52 INFO    opendrift.models.basemodel:2035: 2024-12-12 22:15:00 - step 22 of 48 - 2000 active elements (0 deactivated)
20:20:53 INFO    opendrift.models.basemodel:2035: 2024-12-12 22:30:00 - step 23 of 48 - 2000 active elements (0 deactivated)
20:20:54 INFO    opendrift.models.basemodel:2035: 2024-12-12 22:45:00 - step 24 of 48 - 2000 active elements (0 deactivated)
20:20:54 INFO    opendrift.models.basemodel:2035: 2024-12-12 23:00:00 - step 25 of 48 - 2000 active elements (0 deactivated)
20:20:54 INFO    opendrift.models.basemodel:2035: 2024-12-12 23:15:00 - step 26 of 48 - 2000 active elements (0 deactivated)
20:20:56 INFO    opendrift.models.basemodel:2035: 2024-12-12 23:30:00 - step 27 of 48 - 2000 active elements (0 deactivated)
20:20:56 INFO    opendrift.models.basemodel:2035: 2024-12-12 23:45:00 - step 28 of 48 - 2000 active elements (0 deactivated)
20:20:56 INFO    opendrift.models.basemodel:2035: 2024-12-13 00:00:00 - step 29 of 48 - 2000 active elements (0 deactivated)
20:20:57 INFO    opendrift.models.basemodel:2035: 2024-12-13 00:15:00 - step 30 of 48 - 2000 active elements (0 deactivated)
20:20:58 INFO    opendrift.models.basemodel:2035: 2024-12-13 00:30:00 - step 31 of 48 - 2000 active elements (0 deactivated)
20:20:59 INFO    opendrift.models.basemodel:2035: 2024-12-13 00:45:00 - step 32 of 48 - 2000 active elements (0 deactivated)
20:20:59 INFO    opendrift.models.basemodel:2035: 2024-12-13 01:00:00 - step 33 of 48 - 2000 active elements (0 deactivated)
20:20:59 INFO    opendrift.models.basemodel:2035: 2024-12-13 01:15:00 - step 34 of 48 - 2000 active elements (0 deactivated)
20:21:01 INFO    opendrift.models.basemodel:2035: 2024-12-13 01:30:00 - step 35 of 48 - 2000 active elements (0 deactivated)
20:21:01 INFO    opendrift.models.basemodel:2035: 2024-12-13 01:45:00 - step 36 of 48 - 2000 active elements (0 deactivated)
20:21:01 INFO    opendrift.models.basemodel:2035: 2024-12-13 02:00:00 - step 37 of 48 - 2000 active elements (0 deactivated)
20:21:02 INFO    opendrift.models.basemodel:2035: 2024-12-13 02:15:00 - step 38 of 48 - 2000 active elements (0 deactivated)
20:21:04 INFO    opendrift.models.basemodel:2035: 2024-12-13 02:30:00 - step 39 of 48 - 2000 active elements (0 deactivated)
20:21:04 INFO    opendrift.models.basemodel:2035: 2024-12-13 02:45:00 - step 40 of 48 - 2000 active elements (0 deactivated)
20:21:04 INFO    opendrift.models.basemodel:2035: 2024-12-13 03:00:00 - step 41 of 48 - 2000 active elements (0 deactivated)
20:21:04 INFO    opendrift.models.basemodel:2035: 2024-12-13 03:15:00 - step 42 of 48 - 2000 active elements (0 deactivated)
20:21:06 INFO    opendrift.models.basemodel:2035: 2024-12-13 03:30:00 - step 43 of 48 - 2000 active elements (0 deactivated)
20:21:07 INFO    opendrift.models.basemodel:2035: 2024-12-13 03:45:00 - step 44 of 48 - 2000 active elements (0 deactivated)
20:21:07 INFO    opendrift.models.basemodel:2035: 2024-12-13 04:00:00 - step 45 of 48 - 2000 active elements (0 deactivated)
20:21:07 INFO    opendrift.models.basemodel:2035: 2024-12-13 04:15:00 - step 46 of 48 - 2000 active elements (0 deactivated)
20:21:09 INFO    opendrift.models.basemodel:2035: 2024-12-13 04:30:00 - step 47 of 48 - 2000 active elements (0 deactivated)
20:21:09 INFO    opendrift.models.basemodel:2035: 2024-12-13 04:45:00 - step 48 of 48 - 2000 active elements (0 deactivated)
20:21:11 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-12-12 17:00 to 2024-12-13 05:00 UTC (25 steps)
  • z
  • GENERIC BUNKER C (988.1 kg/m3) - 2024-12-12 17:00 to 2024-12-13 05:00
===========================
--------------------
Reader performance:
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
 0:00:24.3  total
 0:00:00.0  preparing
 0:00:23.1  reading
 0:00:00.9  interpolation
 0:00:00.0  interpolation_time
 0:00:01.2  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.8  total
 0:00:00.0  preparing
 0:00:01.8  reading
 0:00:00.0  masking
--------------------
Performance:
   45.6 total time
   12.2 configuration
    0.1 preparing main loop
      0.0 moving elements to ocean
   31.4 main loop
      5.5 updating elements
        2.4 oil weathering
          0.0 updating viscosities
          0.0 updating densities
          2.4 evaporation
          0.0 emulsification
          0.0 dispersion
        2.8 vertical mixing
    1.8 cleaning up
--------------------
===========================
Model:  OpenOil     (OpenDrift version 1.12.0)
        2000 active Oil particles  (0 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-12-12 17:00:00 UTC
        Present: 2024-12-13 05:00:00 UTC
        Calculation steps: 48 * 0:15:00 - total time: 12:00:00
        Output steps: 25 * 0:30:00
===========================

20:21:11 WARNING opendrift.models.basemodel:2410: Plotting fast. This will make your plots less accurate.
20:21:48 WARNING opendrift.models.basemodel:2410: 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)
20:21:50 INFO    opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_0.gif...
20:22:11 INFO    opendrift.models.basemodel:3037: Time to make animation: 0:00:23.807293
20:22:12 INFO    opendrift.models.basemodel:4613: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_1.gif...
20:22:24 INFO    opendrift.models.oceandrift:713: Time to make animation: 0:00:12.614530
../_images/example_oil_verticalmixing_0.gif ../_images/example_oil_verticalmixing_1.gif

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

Gallery generated by Sphinx-Gallery