{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Coastline interaction\n\nExample to illustrate stranding options using an artificial\neast-west oscillating current field\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from datetime import datetime, timedelta\nfrom opendrift.readers import reader_oscillating\nfrom opendrift.models.oceandrift import OceanDrift\nduration = timedelta(hours=36)\ntime_step = timedelta(hours=.5)\nnumber = 500\n\n# Oscillating east-west current to illustrate stranding options\nreader_osc = reader_oscillating.Reader('x_sea_water_velocity', amplitude=1,\n zero_time=datetime.utcnow())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Coastline option \"stranding\"\n\nParticles are moved forward with forcing velocity (e.g. current and wind drift) times the time step.\nIf the next position is on land, the particle is deactivated.\nNote that particles may \"jump\" a distance onto land, depending on the calculation timestep.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = OceanDrift(loglevel=50)\no.add_reader([reader_osc])\no.set_config('environment:fallback:y_sea_water_velocity', .2)\no.set_config('general:coastline_action', 'stranding')\no.set_config('general:coastline_approximation_precision', None)\no.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time)\no.run(duration=duration, time_step=time_step)\nprint(f'Calculation time: {o.timing[\"total time\"]}')\no.animation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Coastline option \"stranding\" with higher precision\n\nBy setting config \"general:coastline_approximation_precision\" to desired accuracy in degrees (default is 0.01 as in this example),\na more exact coastline crossing is calculated by the deactivated particles.\nNote that with a (too) large compuation time step, particles may still \"jump\" over islands.\nAn alternative to avoid this possibility is to use a smaller timestep for the simulation, though at a larger computational cost.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = OceanDrift(loglevel=50)\no.add_reader([reader_osc])\no.set_config('environment:fallback:y_sea_water_velocity', .2)\no.set_config('general:coastline_action', 'stranding')\no.set_config('general:coastline_approximation_precision', .001) # approx 100m\no.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time)\no.run(duration=duration, time_step=time_step)\nprint(f'Calculation time: {o.timing[\"total time\"]}')\no.animation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Coastline option \"previous\"\n\nParticles hitting land are moved back to previous position in water,\nand may move offshore if currents/winds/forcing change direction.\nHere we see that several particles are jumping over small island.\nReducing timestep to e.g. 15 minutes will reduce this problem.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = OceanDrift(loglevel=50)\no.add_reader([reader_osc])\no.set_config('environment:fallback:y_sea_water_velocity', .2)\no.set_config('general:coastline_action', 'previous')\no.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time)\no.run(duration=duration, time_step=time_step)\nprint(f'Calculation time: {o.timing[\"total time\"]}')\no.animation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Coastline option \"none\"\n\nNo interaction with land, as used by e.g. WindBlow model (atmospheric drift) \n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = OceanDrift(loglevel=50)\no.add_reader([reader_osc])\no.set_config('environment:fallback:y_sea_water_velocity', .2)\no.set_config('general:coastline_action', 'none')\no.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time)\no.run(duration=duration, time_step=time_step)\nprint(f'Calculation time: {o.timing[\"total time\"]}')\no.animation()" ] }, { "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 }