{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Biodegradation of oil\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()\n\n# No motion is needed for this test\no.set_config('environment:constant', {k: 0 for k in\n ['x_wind', 'y_wind', 'x_sea_water_velocity', 'y_sea_water_velocity']})\no.set_config('drift', {'current_uncertainty': 0, 'wind_uncertainty': 0, 'horizontal_diffusivity': 10})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding some particles\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.set_config('drift:vertical_mixing', True)\no.set_config('processes:biodegradation', True)\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': 1e-5} # small droplets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seed 500 oil elements at surface, and 500 elements at 50m depth\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.seed_elements(lon=4, lat=60.0, z=0, number=500, time=datetime.now(), **kwargs)\no.seed_elements(lon=4, lat=60.0, z=-50, number=500, time=datetime.now(), **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(hours=72), time_step=3600, outfile='oil.nc')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot results\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=50, 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 }