Note
Go to the end to download the full example code.
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)
09:40:54 INFO opendrift.models.basemodel:515: OpenDriftSimulation initialised (version 1.11.13 / v1.11.13-48-g5bea84b)
09:40:54 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
09:40:55 INFO opendrift.readers.reader_netCDF_CF_generic:325: Detected dimensions: {'time': 'time', 'x': 'x', 'y': 'y'}
09:40:55 INFO opendrift.readers.reader_netCDF_CF_generic:102: Opening dataset: https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
09:40:57 INFO opendrift.readers.reader_netCDF_CF_generic:325: Detected dimensions: {'x': 'X', 'y': 'Y', 'z': 'depth', 'time': 'time'}
09:40:57 INFO opendrift.models.openoil.openoil:1710: Oil type not specified, using default: GENERIC BUNKER C
09:40:57 INFO opendrift.models.openoil.adios.dirjs:90: Querying ADIOS database for oil: GENERIC BUNKER C
09:40:57 INFO opendrift.models.openoil.openoil:1719: Using density 971.1 and viscosity 0.0005020658058702914 of oiltype GENERIC BUNKER C
09:40:57 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...
09:41:02 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers:
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_ice_area_fraction: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_ice_x_velocity: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: sea_ice_y_velocity: 0.000000
09:41:02 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.020000
09:41:02 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000
09:41:03 INFO opendrift.models.basemodel:936: Using existing reader for land_binary_mask
09:41:03 INFO opendrift.models.basemodel:947: All points are in ocean
09:41:03 INFO opendrift.models.openoil.openoil:687: Oil-water surface tension is 0.035282 Nm
09:41:03 INFO opendrift.models.openoil.openoil:700: Max water fraction not available for GENERIC BUNKER C, using default
09:41:03 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.
09:41:03 INFO opendrift.models.basemodel:2038: 2024-10-01 07:00:00 - step 1 of 48 - 2000 active elements (0 deactivated)
09:41:06 INFO opendrift.models.basemodel:2038: 2024-10-01 07:15:00 - step 2 of 48 - 2000 active elements (0 deactivated)
09:41:08 INFO opendrift.models.basemodel:2038: 2024-10-01 07:30:00 - step 3 of 48 - 2000 active elements (0 deactivated)
09:41:08 INFO opendrift.models.basemodel:2038: 2024-10-01 07:45:00 - step 4 of 48 - 2000 active elements (0 deactivated)
09:41:08 INFO opendrift.models.basemodel:2038: 2024-10-01 08:00:00 - step 5 of 48 - 2000 active elements (0 deactivated)
09:41:08 INFO opendrift.models.basemodel:2038: 2024-10-01 08:15:00 - step 6 of 48 - 2000 active elements (0 deactivated)
09:41:10 INFO opendrift.models.basemodel:2038: 2024-10-01 08:30:00 - step 7 of 48 - 2000 active elements (0 deactivated)
09:41:10 INFO opendrift.models.basemodel:2038: 2024-10-01 08:45:00 - step 8 of 48 - 2000 active elements (0 deactivated)
09:41:10 INFO opendrift.models.basemodel:2038: 2024-10-01 09:00:00 - step 9 of 48 - 2000 active elements (0 deactivated)
09:41:10 INFO opendrift.models.basemodel:2038: 2024-10-01 09:15:00 - step 10 of 48 - 2000 active elements (0 deactivated)
09:41:12 INFO opendrift.models.basemodel:2038: 2024-10-01 09:30:00 - step 11 of 48 - 2000 active elements (0 deactivated)
09:41:12 INFO opendrift.models.basemodel:2038: 2024-10-01 09:45:00 - step 12 of 48 - 2000 active elements (0 deactivated)
09:41:13 INFO opendrift.models.basemodel:2038: 2024-10-01 10:00:00 - step 13 of 48 - 2000 active elements (0 deactivated)
09:41:13 INFO opendrift.models.basemodel:2038: 2024-10-01 10:15:00 - step 14 of 48 - 2000 active elements (0 deactivated)
09:41:15 INFO opendrift.models.basemodel:2038: 2024-10-01 10:30:00 - step 15 of 48 - 2000 active elements (0 deactivated)
09:41:15 INFO opendrift.models.basemodel:2038: 2024-10-01 10:45:00 - step 16 of 48 - 2000 active elements (0 deactivated)
09:41:15 INFO opendrift.models.basemodel:2038: 2024-10-01 11:00:00 - step 17 of 48 - 2000 active elements (0 deactivated)
09:41:15 INFO opendrift.models.basemodel:2038: 2024-10-01 11:15:00 - step 18 of 48 - 2000 active elements (0 deactivated)
09:41:17 INFO opendrift.models.basemodel:2038: 2024-10-01 11:30:00 - step 19 of 48 - 2000 active elements (0 deactivated)
09:41:17 INFO opendrift.models.basemodel:2038: 2024-10-01 11:45:00 - step 20 of 48 - 2000 active elements (0 deactivated)
09:41:17 INFO opendrift.models.basemodel:2038: 2024-10-01 12:00:00 - step 21 of 48 - 2000 active elements (0 deactivated)
09:41:17 INFO opendrift.models.basemodel:2038: 2024-10-01 12:15:00 - step 22 of 48 - 2000 active elements (0 deactivated)
09:41:19 INFO opendrift.models.basemodel:2038: 2024-10-01 12:30:00 - step 23 of 48 - 2000 active elements (0 deactivated)
09:41:19 INFO opendrift.models.basemodel:2038: 2024-10-01 12:45:00 - step 24 of 48 - 2000 active elements (0 deactivated)
09:41:19 INFO opendrift.models.basemodel:2038: 2024-10-01 13:00:00 - step 25 of 48 - 2000 active elements (0 deactivated)
09:41:19 INFO opendrift.models.basemodel:2038: 2024-10-01 13:15:00 - step 26 of 48 - 2000 active elements (0 deactivated)
09:41:21 INFO opendrift.models.basemodel:2038: 2024-10-01 13:30:00 - step 27 of 48 - 2000 active elements (0 deactivated)
09:41:21 INFO opendrift.models.basemodel:2038: 2024-10-01 13:45:00 - step 28 of 48 - 2000 active elements (0 deactivated)
09:41:21 INFO opendrift.models.basemodel:2038: 2024-10-01 14:00:00 - step 29 of 48 - 2000 active elements (0 deactivated)
09:41:22 INFO opendrift.models.basemodel:2038: 2024-10-01 14:15:00 - step 30 of 48 - 2000 active elements (0 deactivated)
09:41:23 INFO opendrift.models.basemodel:2038: 2024-10-01 14:30:00 - step 31 of 48 - 2000 active elements (0 deactivated)
09:41:23 INFO opendrift.models.basemodel:2038: 2024-10-01 14:45:00 - step 32 of 48 - 2000 active elements (0 deactivated)
09:41:24 INFO opendrift.models.basemodel:2038: 2024-10-01 15:00:00 - step 33 of 48 - 2000 active elements (0 deactivated)
09:41:24 INFO opendrift.models.basemodel:2038: 2024-10-01 15:15:00 - step 34 of 48 - 2000 active elements (0 deactivated)
09:41:25 INFO opendrift.models.basemodel:2038: 2024-10-01 15:30:00 - step 35 of 48 - 2000 active elements (0 deactivated)
09:41:26 INFO opendrift.models.basemodel:2038: 2024-10-01 15:45:00 - step 36 of 48 - 2000 active elements (0 deactivated)
09:41:26 INFO opendrift.models.basemodel:2038: 2024-10-01 16:00:00 - step 37 of 48 - 2000 active elements (0 deactivated)
09:41:26 INFO opendrift.models.basemodel:2038: 2024-10-01 16:15:00 - step 38 of 48 - 2000 active elements (0 deactivated)
09:41:28 INFO opendrift.models.basemodel:2038: 2024-10-01 16:30:00 - step 39 of 48 - 2000 active elements (0 deactivated)
09:41:28 INFO opendrift.models.basemodel:2038: 2024-10-01 16:45:00 - step 40 of 48 - 2000 active elements (0 deactivated)
09:41:28 INFO opendrift.models.basemodel:2038: 2024-10-01 17:00:00 - step 41 of 48 - 2000 active elements (0 deactivated)
09:41:28 INFO opendrift.models.basemodel:2038: 2024-10-01 17:15:00 - step 42 of 48 - 2000 active elements (0 deactivated)
09:41:30 INFO opendrift.models.basemodel:2038: 2024-10-01 17:30:00 - step 43 of 48 - 2000 active elements (0 deactivated)
09:41:30 INFO opendrift.models.basemodel:2038: 2024-10-01 17:45:00 - step 44 of 48 - 2000 active elements (0 deactivated)
09:41:30 INFO opendrift.models.basemodel:2038: 2024-10-01 18:00:00 - step 45 of 48 - 2000 active elements (0 deactivated)
09:41:30 INFO opendrift.models.basemodel:2038: 2024-10-01 18:15:00 - step 46 of 48 - 2000 active elements (0 deactivated)
09:41:32 INFO opendrift.models.basemodel:2038: 2024-10-01 18:30:00 - step 47 of 48 - 2000 active elements (0 deactivated)
09:41:32 INFO opendrift.models.basemodel:2038: 2024-10-01 18:45:00 - step 48 of 48 - 2000 active elements (0 deactivated)
09:41:32 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
===========================
--------------------
Reader performance:
--------------------
https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be
0:00:24.8 total
0:00:00.0 preparing
0:00:23.9 reading
0:00:00.6 interpolation
0:00:00.0 interpolation_time
0:00:00.9 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:00.0 total
0:00:00.0 preparing
0:00:00.0 reading
0:00:00.0 masking
--------------------
Performance:
38.1 total time
8.4 configuration
0.1 preparing main loop
0.0 moving elements to ocean
29.5 main loop
3.6 updating elements
1.7 oil weathering
0.0 updating viscosities
0.0 updating densities
1.7 evaporation
0.0 emulsification
0.0 dispersion
1.7 vertical mixing
0.0 cleaning up
--------------------
===========================
Model: OpenOil (OpenDrift version 1.11.13)
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-10-01 07:00:00 UTC
Present: 2024-10-01 19:00:00 UTC
Calculation steps: 48 * 0:15:00 - total time: 12:00:00
Output steps: 25 * 0:30:00
===========================
09:41:32 WARNING opendrift.models.basemodel:2411: Plotting fast. This will make your plots less accurate.
09:42:00 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:1683: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
result = super().scatter(*args, **kwargs)
09:42:02 INFO opendrift.models.basemodel:4608: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_0.gif...
09:42:14 INFO opendrift.models.basemodel:3037: Time to make animation: 0:00:13.675231
/root/project/opendrift/models/oceandrift.py:687: UserWarning: Attempting to set identical low and high ylims makes transformation singular; automatically expanding.
axk.set_ylim([maxdepth, 0])
/root/project/opendrift/models/oceandrift.py:704: UserWarning: Attempting to set identical low and high ylims makes transformation singular; automatically expanding.
axn.set_ylim([maxdepth, 0])
09:42:15 INFO opendrift.models.basemodel:4608: Saving animation to /root/project/docs/source/gallery/animations/example_oil_verticalmixing_1.gif...
09:42:24 INFO opendrift.models.oceandrift:722: Time to make animation: 0:00:10.267036
Total running time of the script: (1 minutes 41.812 seconds)