{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Water column stretching\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.readers import reader_oscillating\nfrom opendrift.models.oceandrift import OceanDrift" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In OpenDrift, the vertical position of elements (\"z\") is defined as relative to actual surface,\nand not an absolute reference level (e.g. mean sea surface height).\nThus if sea surface elevation changes with time (e.g. tides),\nwe need to add a \"correction / perturbation\" to z, otherwise elements at/near seafloor\nwill be lifted if surface elevation increases and z (relative to surface) remains unchanged.\nThis correction is presently only implemented for OceanDrift, and must be switched on\nwith config setting \"drift:water:column_stretching\"\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# To illustrate, we add a reader with oscillating sea surface elevation (tidal)\n# with amplitude of 1m and peroid of 6 hours\ntime = datetime.now()\nreader_tidal = reader_oscillating.Reader('sea_surface_height', amplitude=-1,\n period=timedelta(hours=6), zero_time=time)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First an illustration withouth this correction.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = OceanDrift(loglevel=20)\no.add_reader(reader_tidal)\no.set_config('drift:water_column_stretching', False)\no.set_config('environment:constant:sea_floor_depth_below_sea_level', 10)\nz = np.arange(0, -11, -1) # Seeding one particle every meter from surface to 10m depth\no.seed_elements(lon=0, lat=0, time=time, z=z, number=11)\no.run(duration=timedelta(hours=24), time_step=1800)\no.result.z.plot.line(x='time', add_legend=False)\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We see that the particles remain at their initial depths (since we have no vertical advection or mixing),\nexcept for the element starting at seafloor, which is lifted up when sea level rises,\nsince the config setting `drift:seafloor_action` is `lift_to_seafloor` by default.\nThis lifting is in this case unphysical.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We then make a simulation wih correction for the stretching/contraction of the water column.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = OceanDrift(loglevel=20)\no.add_reader(reader_tidal)\no.set_config('drift:water_column_stretching', True)\no.set_config('environment:constant:sea_floor_depth_below_sea_level', 10)\no.seed_elements(lon=0, lat=0, time=time, z=z, number=11)\no.run(duration=timedelta(hours=24), time_step=1800)\no.result.z.plot.line(x='time', add_legend=False)\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we see that element depth (z, relative to surface) is changed so that\nelements at surface and seafloor remain at resp surface (z=0) and\nseafloor (z = sea_floor_depth + sea_surface_elevation)\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.14.2" } }, "nbformat": 4, "nbformat_minor": 0 }