.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_coastline_options.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_example_coastline_options.py: Coastline interaction ====================== Example to illustrate stranding options using an artificial east-west oscillating current field .. GENERATED FROM PYTHON SOURCE LINES 9-21 .. code-block:: Python from datetime import datetime, timedelta from opendrift.readers import reader_oscillating from opendrift.models.oceandrift import OceanDrift duration = timedelta(hours=36) time_step = timedelta(hours=.5) number = 500 # Oscillating east-west current to illustrate stranding options reader_osc = reader_oscillating.Reader('x_sea_water_velocity', amplitude=1, zero_time=datetime.utcnow()) .. GENERATED FROM PYTHON SOURCE LINES 22-28 Coastline option "stranding" ============================ Particles are moved forward with forcing velocity (e.g. current and wind drift) times the time step. If the next position is on land, the particle is deactivated. Note that particles may "jump" a distance onto land, depending on the calculation timestep. .. GENERATED FROM PYTHON SOURCE LINES 28-38 .. code-block:: Python o = OceanDrift(loglevel=50) o.add_reader([reader_osc]) o.set_config('environment:fallback:y_sea_water_velocity', .2) o.set_config('general:coastline_action', 'stranding') o.set_config('general:coastline_approximation_precision', None) o.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time) o.run(duration=duration, time_step=time_step) print(f'Calculation time: {o.timing["total time"]}') o.animation() .. rst-class:: sphx-glr-script-out .. code-block:: none Calculation time: 0:00:06.745024 .. GENERATED FROM PYTHON SOURCE LINES 39-40 .. image:: /gallery/animations/example_coastline_options_0.gif .. GENERATED FROM PYTHON SOURCE LINES 42-49 Coastline option "stranding" with higher precision ================================================== By setting config "general:coastline_approximation_precision" to desired accuracy in degrees (default is 0.01 as in this example), a more exact coastline crossing is calculated by the deactivated particles. Note that with a (too) large compuation time step, particles may still "jump" over islands. An alternative to avoid this possibility is to use a smaller timestep for the simulation, though at a larger computational cost. .. GENERATED FROM PYTHON SOURCE LINES 49-59 .. code-block:: Python o = OceanDrift(loglevel=50) o.add_reader([reader_osc]) o.set_config('environment:fallback:y_sea_water_velocity', .2) o.set_config('general:coastline_action', 'stranding') o.set_config('general:coastline_approximation_precision', .001) # approx 100m o.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time) o.run(duration=duration, time_step=time_step) print(f'Calculation time: {o.timing["total time"]}') o.animation() .. rst-class:: sphx-glr-script-out .. code-block:: none Calculation time: 0:00:03.686012 .. GENERATED FROM PYTHON SOURCE LINES 60-61 .. image:: /gallery/animations/example_coastline_options_1.gif .. GENERATED FROM PYTHON SOURCE LINES 63-70 Coastline option "previous" =========================== Particles hitting land are moved back to previous position in water, and may move offshore if currents/winds/forcing change direction. Here we see that several particles are jumping over small island. Reducing timestep to e.g. 15 minutes will reduce this problem. .. GENERATED FROM PYTHON SOURCE LINES 70-79 .. code-block:: Python o = OceanDrift(loglevel=50) o.add_reader([reader_osc]) o.set_config('environment:fallback:y_sea_water_velocity', .2) o.set_config('general:coastline_action', 'previous') o.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time) o.run(duration=duration, time_step=time_step) print(f'Calculation time: {o.timing["total time"]}') o.animation() .. rst-class:: sphx-glr-script-out .. code-block:: none Calculation time: 0:00:03.475888 .. GENERATED FROM PYTHON SOURCE LINES 80-81 .. image:: /gallery/animations/example_coastline_options_2.gif .. GENERATED FROM PYTHON SOURCE LINES 83-87 Coastline option "none" ======================= No interaction with land, as used by e.g. WindBlow model (atmospheric drift) .. GENERATED FROM PYTHON SOURCE LINES 87-96 .. code-block:: Python o = OceanDrift(loglevel=50) o.add_reader([reader_osc]) o.set_config('environment:fallback:y_sea_water_velocity', .2) o.set_config('general:coastline_action', 'none') o.seed_elements(lon=12.2, lat=67.7, radius=5000, number=number, time=reader_osc.zero_time) o.run(duration=duration, time_step=time_step) print(f'Calculation time: {o.timing["total time"]}') o.animation() .. rst-class:: sphx-glr-script-out .. code-block:: none Calculation time: 0:00:01.498991 .. GENERATED FROM PYTHON SOURCE LINES 97-98 .. image:: /gallery/animations/example_coastline_options_3.gif .. rst-class:: sphx-glr-timing **Total running time of the script:** (3 minutes 54.391 seconds) .. _sphx_glr_download_gallery_example_coastline_options.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_coastline_options.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_coastline_options.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_coastline_options.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_