{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Biodegradation of oil at depth\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nfrom datetime import datetime, timedelta\nfrom opendrift.readers import reader_netCDF_CF_generic\nfrom opendrift.models.openoil import OpenOil\n\no = OpenOil(loglevel=0) # Set loglevel to 0 for debug information\ntime = datetime.now()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Current from HYCOM and wind from NCEP GFS\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.add_readers_from_list([\n 'https://tds.hycom.org/thredds/dodsC/FMRC_ESPC-D-V02_uv3z/FMRC_ESPC-D-V02_uv3z_best.ncd',\n 'https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'])\no.set_config('environment:constant:ocean_mixed_layer_thickness', 20)\no.set_config('drift', {'current_uncertainty': 0, 'wind_uncertainty': 0, 'horizontal_diffusivity': 20})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Configuration\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.set_config('drift:vertical_mixing', True)\no.set_config('drift:vertical_mixing', True)\no.set_config('processes:biodegradation', True)\no.set_config('processes:dispersion', False)\no.set_config('biodegradation:method', 'half_time')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Fast decay for droplets, and slow decay for slick \n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"kwargs = {'biodegradation_half_time_slick': 3, # days\n 'biodegradation_half_time_droplet': 1, # days\n 'oil_type': 'GENERIC MEDIUM CRUDE', 'm3_per_hour': .5, 'diameter': 8e-5} # small droplets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Seed oil at surface and at 150m depth\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"time = datetime.today() - timedelta(days=5)\nlon = 23.5\nlat = 35.0\no.seed_elements(lon=lon, lat=lat, z=0, radius=100, number=3000, time=time, **kwargs)\no.seed_elements(lon=lon, lat=lat, z=-150, radius=100, number=3000, time=time, **kwargs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Running model\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.run(duration=timedelta(days=5), time_step=3600, outfile='oil.nc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot and animate results\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.animation(color='z', markersize='mass_oil', markersize_scaling=80)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.plot_oil_budget(show_watercontent_and_viscosity=False, show_wind_and_current=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Custom oil budget plot\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"b = o.get_oil_budget()\nimport matplotlib.pyplot as plt\ntime, time_relative = o.get_time_array()\ntime = np.array([t.total_seconds() / 3600. for t in time_relative])\nfig, ax = plt.subplots()\nax.plot(time, b['mass_submerged'], label='Submerged oil mass')\nax.plot(time, b['mass_surface'], label='Surface oil mass')\nax.plot(time, b['mass_biodegraded'], label='Biodegraded oil mass')\nax.set_title(f'{o.get_oil_name()}, {b[\"oil_density\"].max():.2f} kg/m3')\nplt.legend()\nplt.xlabel('Time [hours]')\nplt.ylabel('Mass oil [kg]')\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Animation of vertical behaviour\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.animation_profile(markersize='mass_oil', markersize_scaling=80, color='z', alpha=.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}