{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Drifter\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from datetime import timedelta\nimport numpy as np\nfrom opendrift.readers import reader_netCDF_CF_generic\nfrom opendrift.models.oceandrift import OceanDrift\n\no = OceanDrift(loglevel=20) # Basic drift model suitable for passive tracers or drifters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Preparing Readers\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "reader_current = reader_netCDF_CF_generic.Reader(o.test_data_folder() +\n '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')\nreader_wind = reader_netCDF_CF_generic.Reader(o.test_data_folder() +\n '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')\n\no.add_reader([reader_current, reader_wind])\n\n# Prevent mixing elements downwards\no.set_config('drift:vertical_mixing', False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding elements\n\n Elements are moved with the ocean current, in addition to a fraction of\n the wind speed (wind_drift_factor). This factor depends on the properties\n of the elements. Typical empirical values are:\n - 0.035 (3.5 %) for oil and iSphere driftes\n - 0.01 (1 %) for CODE drifters partly submerged ~0.5 m\n As there are large uncertainties, it makes sense to provide a statistical\n distribution of wind_drift_factors\n\n Using a constant value for all elements:\nwind_drift_factor = 0.03\n\n Giving each element a unique (random) wind_drift_factor\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "wind_drift_factor = np.random.uniform(0, 0.06, 2000)\no.seed_elements(4.7, 59.9, radius=3000, number=2000,\n time=reader_current.start_time,\n wind_drift_factor=wind_drift_factor)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running model\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.run(time_step=timedelta(minutes=15),\n time_step_output=timedelta(minutes=60))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print and plot results\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(o)\no.animation(color='wind_drift_factor', fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Plot trajectories, colored by the wind_drift_factor of each element\no.plot(linecolor='wind_drift_factor', fast=True)" ] } ], "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 }