{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Comparing oil budgets\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from datetime import datetime, timedelta\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom opendrift.models.openoil import OpenOil" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Comparing the weathering and properties\nof different oils at different wind speeds\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "oiltypes = ['GENERIC HEAVY CRUDE', 'GENERIC MEDIUM CRUDE', 'GENERIC LIGHT CRUDE',\n 'GENERIC DIESEL']\nwind_speeds = [5, 10]\nhours = 24\nb = {}\nviscosities = {}\ndensities = {}\nwater_fractions = {}\n\nfor wind_speed in wind_speeds:\n for ot in oiltypes:\n o = OpenOil(loglevel=50)\n print('%s m/s - %s' % (wind_speed, ot))\n o.set_config('environment:constant:x_wind', wind_speed)\n o.set_config('environment:constant:y_wind', 0)\n o.set_config('environment:constant:x_sea_water_velocity', 0)\n o.set_config('environment:constant:y_sea_water_velocity', 0)\n o.set_config('environment:constant:land_binary_mask', 0)\n o.set_config('general:use_auto_landmask', False)\n o.set_config('processes:dispersion', False)\n o.seed_elements(lon=0, lat=0, time=datetime.now(), number=1000, oil_type=ot)\n o.run(duration=timedelta(hours=hours), time_step=600)\n b[ot] = o.get_oil_budget()\n # Get viscosity and density\n kin_viscosity = o.history['viscosity']\n dyn_viscosity = kin_viscosity * o.history['density'] * 1000 # mPas\n viscosities[ot] = dyn_viscosity.mean(axis=0)\n densities[ot] = o.history['density'].mean(axis=0)\n water_fractions[ot] = o.history['water_fraction'].mean(axis=0)\n\n time, time_relative = o.get_time_array()\n time = np.array([t.total_seconds() / 3600. for t in time_relative])\n\n figw,(axevap, axsurf, axsub) = plt.subplots(3,1)\n figp,(axdens, axvisc, axw) = plt.subplots(3,1)\n for ot in oiltypes:\n axevap.plot(time, 100*b[ot]['mass_evaporated']/b[ot]['mass_total'], label=ot)\n axsurf.plot(time, 100*b[ot]['mass_surface']/b[ot]['mass_total'], label=ot)\n axsub.plot(time, 100*b[ot]['mass_submerged']/b[ot]['mass_total'], label=ot)\n axdens.plot(time, densities[ot], label=ot)\n axvisc.plot(time, viscosities[ot], label=ot)\n axw.plot(time, water_fractions[ot], label=ot)\n\n for ax in (axevap, axsurf, axsub, axdens, axvisc, axw):\n if ax in (axevap, axsurf, axsub):\n ax.set_ylim([0, 100])\n ax.set_xlim([0, hours])\n\n axevap.set_title('Wind speed %s m/s' % wind_speed)\n axsurf.set_ylabel('Surface [%]')\n axevap.set_ylabel('Evaporated [%]')\n axsub.set_ylabel('Submerged [%]')\n axsub.legend()\n axsub.set_xlabel('Time [hours]')\n\n axdens.set_title('Wind speed %s m/s' % wind_speed)\n axvisc.set_ylabel('Viscosity [mPas]')\n axvisc.set_yscale('log')\n axdens.set_ylabel('Density [kg/m3]')\n axw.set_ylabel('Water fraction')\n axw.set_xlabel('Time [hours]')\n axw.legend()\n plt.tight_layout()\n plt.show()" ] } ], "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 }