{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Seed demonstration\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from datetime import datetime, timedelta\nimport numpy as np\nfrom opendrift.models.oceandrift import OceanDrift\nfrom opendrift.models.openoil import OpenOil\n\no = OceanDrift(loglevel=50)\n\ntime=datetime(2016, 1, 20, 12, 30, 0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding a single element at a point\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('\\n' + '='*70)\nprint('Seeding a single element at a point:')\nprint('o.seed_elements(lon=4, lat=60, time=time)')\nprint('='*70)\no.seed_elements(lon=4, lat=60, time=time)\n#o.run(steps=1)\no.plot(buffer=.7, fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding 100 elements within a radius of 1000 m\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = OceanDrift(loglevel=50)\nprint('\\n' + '='*70)\nprint('Seeding 100 elements within a radius of 1000 m:')\nprint('o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time)')\nprint('='*70)\no.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time)\n#o.run(steps=1)\no.plot(buffer=.7, fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding 100 elements within a radius of 1000 m and specifying a property (here z/depth) as an array\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('\\n' + '='*70)\nprint('Seeding 100 elements within a radius of 1000 m\\n and specifying a property (here z/depth) as an array:')\nprint('o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z)')\nprint('='*70)\no = OceanDrift(loglevel=50)\nz = np.linspace(0, -50, 100) # Linearly increasing depth\no.set_config('environment:fallback:y_sea_water_velocity', 3) # Adding some current to be able to visualise depth as color of trajectories\no.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z)\no.run(steps=1)\no.plot(linecolor='z', buffer=.7, fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding 100 elements at user defined locations (here along line between two points)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('\\n' + '='*70)\nprint('Seeding 100 elements at user defined locations\\n (here along line between two points):')\nprint('lats = np.linspace(60, 61, 100)\\n' \\\n 'lons = np.linspace(4, 4.8, 100)\\n' \\\n 'o.seed_elements(lon=lons, lat=lats, time=time)')\nprint('='*70)\no = OceanDrift(loglevel=50)\nlats = np.linspace(60, 61, 100)\nlons = np.linspace(4, 4.8, 100)\no.seed_elements(lon=lons, lat=lats, time=time)\no.run(steps=1)\no.plot(buffer=.2, fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding 100 elements between two points with seed_cone() (achieving the same as previous example)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('\\n' + '='*70)\nprint('Seeding 100 elements between two points with seed_cone() (achieving the same as previous example):')\nprint('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time)')\nprint('='*70)\no = OceanDrift(loglevel=50)\no.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time)\no.run(steps=1)\no.plot(buffer=.2, fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding 1000 elements along cone with radius/uncertainty increasing linearly from 0 to 5000 m\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('\\n' + '='*70)\nprint('Seeding 1000 elements along cone with radius/uncertainty\\n increasing linearly from 0 to 5000 m:')\nprint('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time)')\nprint('='*70)\no = OceanDrift(loglevel=50)\no.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time)\no.run(steps=1)\no.plot(buffer=.2, fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If specifying time as a two element list (start and end, here +5 hours), elements are seeded linearly in time\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('\\n' + '='*70)\nprint('If specifying time as a two element list (start and end,\\n here +5 hours), elements are seeded linearly in time:')\nprint('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)])')\nprint('='*70)\no = OceanDrift(loglevel=50)\no.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)])\no.run(steps=5*4, time_step=900)\no.animation(fast=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('\\n' + '='*70)\nprint('Any model/module may provide specialised seeding-functions, such as \\n seeding oil within contours read from a GML file:')\nprint('o.seed_from_gml(o.test_data_folder() + \"radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml\", num_elements=2000)')\nprint('='*70)\no = OpenOil(loglevel=50)\no.set_config('environment:fallback:x_wind', 0)\no.set_config('environment:fallback:y_wind', 0)\no.set_config('environment:fallback:x_sea_water_velocity', 0)\no.set_config('environment:fallback:y_sea_water_velocity', 0)\no.seed_from_gml(o.test_data_folder() + 'radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml', num_elements=2000)\no.run(steps=1, time_step=1800, time_step_output=1800)\no.plot(buffer=.03, 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 }