{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Leeway capsizing\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from datetime import timedelta\nimport cmocean\nimport xarray as xr\nfrom opendrift.readers import reader_netCDF_CF_generic\nfrom opendrift.models.leeway import Leeway\n\no = Leeway(loglevel=0) # Set loglevel to 0 for debug information\n\n# Atmospheric model for wind\n#reader_arome = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc')\nreader_arome = reader_netCDF_CF_generic.Reader(o.test_data_folder() +\n '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')\n\n# Ocean model for current\n#reader_norkyst = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc')\nreader_norkyst = reader_netCDF_CF_generic.Reader(o.test_data_folder() +\n '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')\n\no.add_reader(reader_norkyst)\no.add_reader(reader_arome)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Activating capsizing for high winds, with probability per hour given by\np(windspeed) = 0.5 + 0.5*tanh((windspeed-wind_threshold)/sigma)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.set_config('processes:capsizing', True)\no.set_config('capsizing:wind_threshold', 30)\no.set_config('capsizing:wind_threshold_sigma', 5)\no.set_config('capsizing:leeway_fraction', 0.4) # Reducing leeway coefficients to 40% of original after capsize\n\no.plot_capsize_probability()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seed leeway elements at defined position and time\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "object_type = 26 # 26 = Life-raft, no ballast\no.seed_elements(lon=4.5, lat=59.6, radius=100, number=1000,\n time=reader_arome.start_time, object_type=object_type)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running model\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.run(duration=timedelta(hours=48), time_step=900, time_step_output=3600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print and plot results\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(o)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Animation illustrating effect of capsizing\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from matplotlib.colors import ListedColormap\no.animation(color='capsized', cmap=ListedColormap(['black','red']), fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reverse run, also with probability of (un)-capsizing\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = Leeway()\no.add_reader(reader_norkyst)\no.add_reader(reader_arome)\no.set_config('processes:capsizing', True)\no.seed_elements(lon=4.4, lat=61.0, radius=100, number=1000,\n capsized=1, # now we seed all objects as already capsized\n time=reader_arome.end_time, object_type=object_type)\no.run(time_step=-900, duration=timedelta(hours=48), time_step_output=timedelta(hours=1))\no.animation(color='capsized', cmap=ListedColormap(['black','red']), fast=True)" ] }, { "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 }