{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# ChemicalDrift - Transport and fate of organic compounds\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from opendrift.readers import reader_netCDF_CF_generic\nfrom opendrift.models.chemicaldrift import ChemicalDrift\nfrom opendrift.readers.reader_constant import Reader as ConstantReader\nfrom datetime import timedelta, datetime\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n\no = ChemicalDrift(loglevel=0, seed=0)\n\n# Norkyst\nreader_norkyst = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')\nmixed_layer = ConstantReader({'ocean_mixed_layer_thickness': 40})\no.add_reader([reader_norkyst,mixed_layer])\n\no.set_config('drift:vertical_mixing', True)\no.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Large1994')\no.set_config('chemical:particle_diameter',30.e-6) # m\no.set_config('chemical:particle_diameter_uncertainty',5.e-6) # m\no.set_config('chemical:sediment:resuspension_critvel',0.15) # m/s\no.set_config('chemical:transformations:volatilization', True)\no.set_config('chemical:transformations:degradation', True)\no.set_config('chemical:transformations:degradation_mode', 'OverallRateConstants')\no.set_config('seed:LMM_fraction',.9)\no.set_config('seed:particle_fraction',.1)\no.set_config('general:coastline_action', 'previous')\n\no.init_chemical_compound(\"Phenanthrene\")\n\n# Modify half-life times with unrealistic values for this demo\no.set_config('chemical:transformations:t12_W_tot', 6.) # hours\no.set_config('chemical:transformations:t12_S_tot', 12.) # hours\n\no.list_configspec()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Seeding 500 lagrangian elements each representign 2mg og target chemical\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"td=datetime.today()\ntime = td - timedelta(days=10)\n\nlatseed= 57.6; lonseed= 10.6 # Skagen\n\nntraj=500\niniz=np.random.rand(ntraj) * -10. # seeding the chemicals in the upper 10m\n\no.seed_elements(lonseed, latseed, z=iniz, radius=2000,number=ntraj,time=time, mass=2e3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Running model\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.run(steps=48*2, time_step=1800, time_step_output=1800)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Print and plot results\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print('Final speciation:')\nfor isp,sp in enumerate(o.name_species):\n print ('{:32}: {:>6}'.format(sp,sum(o.elements.specie==isp)))\n\nprint('Number of transformations:')\nfor isp in range(o.nspecies):\n print('{}'.format(['{:>9}'.format(np.int32(item)) for item in o.ntransformations[isp,:]]) )\n\nmass = o.get_property('mass')\nmass_d = o.get_property('mass_degraded')\nmass_v = o.get_property('mass_volatilized')\n\nm_pre = sum(mass[0][-1])\nm_deg = sum(mass_d[0][-1])\nm_vol = sum(mass_v[0][-1])\nm_tot = m_pre + m_deg + m_vol\n\nprint('Mass budget for target chemical:')\nprint('mass preserved : {:.3f}'.format(m_pre * 1e-6),' g {:.3f}'.format(m_pre/m_tot*100),'%')\nprint('mass degraded : {:.3f}'.format(m_deg * 1e-6),' g {:.3f}'.format(m_deg/m_tot*100),'%')\nprint('mass volatilized : {:.3f}'.format(m_vol * 1e-6),' g {:.3f}'.format(m_vol/m_tot*100),'%')\n\nlegend=['dissolved', '', 'SPM', 'sediment', '']\n\no.animation_profile(color='specie',\n markersize='mass',\n markersize_scaling=30,\n alpha=.5,\n vmin=0,vmax=o.nspecies-1,\n legend = legend,\n legend_loc = 3,\n fps = 10\n )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.animation(color='specie',\n markersize='mass',\n markersize_scaling=100,\n alpha=.5,\n vmin=0,vmax=o.nspecies-1,\n colorbar=False,\n fast = True,\n legend = legend,\n legend_loc = 3,\n fps=10\n )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"o.plot_mass(legend = legend,\n time_unit = 'hours',\n title = 'Chemical mass budget')"
]
}
],
"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
}