OpenOil is a 3D oil drift module bundled within the OpenDrift framework.

The oil weathering calculations is based on the NOAA-ERR-ERD OilLibrary package, which is installed as a dependency. The code for evaporation and emulsification in OpenOil is borrowed from the NOAA PyGnome code, and adapted to the OpenDrift architecture.

Example of ship leaking oil along the coast of Northern Norway

Simulation of Deepwater Horizon (Macondo) accident, initiated from satellite images

Satellite images provided by Prof. Chuanmin Hu, and ocean model output provided by Prof. Vassiliki Kourafalou

Example oil budget for a simulation

Oil properties affecting the drift

The vertical (and thus indirectly also the horizontal) motion of oil (droplets) is affected by oil density and droplet diameters.

When using the NOAA oil weathering model (o = OpenOil(weathering_model='noaa')), which is the default, the density is obtained from the NOAA database according to the oiltype selected when seeding. This value can not be overridden by the user, and it will also change during the simulation due to oil weathering processes (evaporation and emulsification).

The droplet diameter may be given explicitly when seeding, e.g.:

o.seed_elements(4, 60, number=100,, diameter=1e-5)

In this case, the diameter will not change during the simulation, which is useful e.g. for sensitivity tests. The same diameter will be used for all elements for this example, but an array of the same length as the number of elements may also be provided.

If a constant droplet diameter is not given by the user, it will be chosen randomly within given config limits for a subsea spill (‘blowout’), and modified after any later wave breaking event. Oil droplets seeded under sea surface (z<0) will be assigned initial diameters between the following limits, typical for a subsea blowout (Johansen, 2000):

o.set_config('seed:droplet_diameter_min_subsea', 0.0005)  # 0.5 mm
o.set_config('seed:droplet_diameter_max_subsea', 0.005)   # 5 mm

Note that these config settings must be adjusted before the seeding call. After each wave breaking event, a new droplet diameter will be chosen based on the config setting for droplet size distribution.

Module Contents



Extending LagrangianArray with variables relevant for oil particles.


Open source oil trajectory model based on the OpenDrift framework.



class opendrift.models.openoil.Oil(**kwargs)[source]

Bases: opendrift.elements.LagrangianArray

Extending LagrangianArray with variables relevant for oil particles.

Initialises a LagrangianArray with given properties.


Keyword arguments (kwargs) with names corresponding to the OrderedDict ‘variables’ of the class, and corresponding values. The values must be ndarrays of equal length, or scalars. All (or none) variables must be given, unless a default value is specified in the OrderedDict ‘variables’ An empty object may be created by giving no input.

class opendrift.models.openoil.OpenOil(weathering_model='noaa', *args, **kwargs)[source]

Bases: opendrift.models.oceandrift.OceanDrift

Open source oil trajectory model based on the OpenDrift framework.

Developed at MET Norway based on oil weathering parameterisations found in open/published litterature.

Under construction.

Initialise OpenDriftSimulation

seed: integer or None. A given integer will yield identical

random numbers drawn each simulation. Random numbers are e.g. used to distribute particles spatially when seeding, and may be used by modules (subclasses) for e.g. diffusion. Specifying a fixed value (default: 0) is useful for sensitivity tests. With seed = None, different random numbers will be drawn for subsequent runs, even with identical configuration/input.

iomodule: name of module used to export data

default: netcdf, see for more alternatives. iomodule is module/filename without preceeding io_

loglevel: set to 0 (default) to retrieve all debug information.

Provide a higher value (e.g. 20) to receive less output. Use the string ‘custom’ to configure logging from outside.

logtime: if True, a time stamp is given for each logging line.

logtime can also be given as a python time specifier (e.g. ‘%H:%M:%S’)

max_speed = 1.3

The mass of oil is summed within a grid of 100x100 cells covering the oil at a given time. Each oil particle within each cell is given a film thickness as the amount of oil divided by the cell area.


Oil weathering scheme adopted from NOAA PyGNOME model:


Plotting distribution of droplet radii, for debugging

update_terminal_velocity(self, Tprofiles=None, Sprofiles=None, z_index=None)[source]

Calculate terminal velocity for oil droplets

according to:

  • Tkalich et al. (2002): Vertical mixing of oil droplets by breaking waves

  • Marine Pollution Bulletin 44, 1219-1229

If profiles of temperature and salt are passed into this function, they will be interpolated from the profiles. if not, T,S will be fetched from reader.


Calculate entrainment probability before main loop

surface_wave_mixing(self, time_step_seconds)[source]

Mix surface oil into water column.


set surfaced particles to exactly zero depth to let them form a slick

resurface_elements(self, minimum_depth=None)[source]

Oil elements reaching surface (or above) form slick, not droplet


Update positions and properties of oil particles.


Get oil budget for the current simulation

The oil budget consists of the following categories:

  • surface: the sum of variable mass_oil for all active elements where z = 0

  • submerged: the sum of variable mass_oil for all active elements where z < 0

  • stranded: the sum of variable mass_oil for all elements which are stranded

  • evaporated: the sum of variable mass_evaporated for all elements

  • dispersed: the sum of variable mass_dispersed for all elements

The sum (total mass) shall equal the mass released. Note that the mass of oil is conserved, whereas the volume may change with changes in density and water uptake (emulsification). Therefore mass should be used for budgets, eventually converted to volume (by dividing on density) in the final step before presentation.

Note that mass_oil is the mass of pure oil. The mass of oil emulsion (oil containing entrained water droplets) can be calculated as:

mass_emulsion = mass_oil / (1 - water_fraction)

I.e. water_fraction = 0 means pure oil, water_fraction = 0.5 means mixture of 50% oil and 50% water, and water_fraction = 0.9 (which is maximum) means 10% oil and 90% water.

plot_oil_budget(self, filename=None, ax=None, show_density_viscosity=True, show_wind_and_current=True)[source]

Returns the fraction of oil elements which has been entrained vs time

plot_oil_density_and_viscosity(self, ax=None, show=True)[source]
set_oiltype(self, oiltype)[source]
store_oil_seed_metadata(self, **kwargs)[source]
seed_elements(self, *args, **kwargs)[source]

Seed elements with given position(s), time and properties.

lon: scalar or array

central longitude(s).

lat: scalar or array

central latitude(s).

radius: scalar or array

radius in meters around each lon-lat pair, within which particles will be randomly seeded.

number: integer, total number of particles to be seeded

If number is None, the number of elements is the length of lon/lat or time if these are arrays. Otherwise the number of elements are obtained from the config-default.

time: datenum or list

The time at which particles are seeded/released. If time is a list with two elements, elements are seeded continously from start/first to end/last time. If time is a list with more than two elements, the number of elements is equal to len(time) and are seeded as a time series.

radius_type: string

If ‘gaussian’ (default), the radius is the standard deviation in x-y-directions. If ‘uniform’, elements are spread evenly and always inside a circle with the given radius.


keyword arguments containing properties/attributes and values corresponding to the actual particle type (ElementType). These are forwarded to the ElementType class. All properties for which there are no default value must be specified.

seed_cone(self, *args, **kwargs)[source]

Seed elements along a transect/cone between two points/times


lon: scalar or list with 2 elements [lon0, lon1]

lat: scalar or list with 2 elements [lat0, lat]

time: datetime or list with 2 elements [t0, t1]

radius: scalar or list with 2 elements [r0, r1] Unit: meters

number (int): The number of elements. If this is None, the number of elements is taken from configuration.

Elements are seeded along a transect from

(lon0, lat0) with uncertainty radius r0 at time t0, towards (lon1, lat1) with uncertainty radius r1 at time t1. If r0 != r1, the unceetainty radius is linearly changed along the transect, thus outlining a “cone”.

seed_from_gml(self, gmlfile, num_elements=1000, *args, **kwargs)[source]

Read oil slick contours from GML file, and seed particles within.

seed_from_geotiff_thickness(self, filename, number=50000, *args, **kwargs)[source]

Seed from files as provided by Prof. Chuanmin Hu