{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Show dominating source\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\nfrom datetime import datetime\nimport xarray as xr\nimport opendrift\nfrom opendrift.models.oceandrift import OceanDrift\n\nof = 'test.nc'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seed elements at 5 different locations/longitudes\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "lons = [4, 4.2, 4.3, 4.32, 4.6]\nt = datetime.now()\n\no = OceanDrift(loglevel=20)\no.set_config('environment:constant:y_sea_water_velocity', .1)\n\nfor i, lon in enumerate(lons):\n o.seed_elements(lon=lon, lat=60, radius=3000, number=2000, time=t, origin_marker_name='Lon %f' % lon)\no.run(steps=15, outfile=of)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate spatial density of elements at 1500m grid spacing\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "oa = opendrift.open_xarray(of)\noa.ds = oa.ds.where(oa.ds.status==0)\nd = oa.get_histogram(pixelsize_m=1500, weights=None)\ndom = d.argmax(dim='origin_marker', skipna=True)\ndom = dom.where(d.sum(dim='origin_marker')>0)\ndom.name = 'Dominating source'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Show which of the 5 sources are dominating within each grid cell\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "oa.animation(background=dom, show_elements=False, bgalpha=1,\n legend=oa.origin_marker, colorbar=False, vmin=0, vmax=4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "os.remove(of)" ] } ], "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 }