{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Use a shapefile as landmask\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom opendrift.readers import reader_netCDF_CF_generic\nfrom opendrift.readers import reader_shape\nfrom opendrift.models.oceandrift import OceanDrift\n\no = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information\n\n# This example works better using hourly input from Thredds than the daily data from test folder\nreader_topaz = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use shapes from Cartopy as landmask. These shapefiles are less acurate than those\nprovided by the GSHHG dataset (available though the reader_global_landmask reader).\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import cartopy.io.shapereader as shpreader\nshpfilename = shpreader.natural_earth(resolution='110m',\n category='cultural',\n name='admin_0_countries')\nreader_natural = reader_shape.Reader.from_shpfiles(shpfilename)\n\no.add_reader([reader_natural, reader_topaz])\no.set_config('general:use_auto_landmask', False) # Disabling the automatic GSHHG landmask\no.set_config('general:coastline_action', 'stranding')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seeding elements on a grid\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "lons = np.linspace(12, 14.7, 30)\nlats = np.linspace(67.5, 68.5, 30)\nlons, lats = np.meshgrid(lons, lats)\nlon = lons.ravel()\nlat = lats.ravel()\n\ntime = reader_topaz.start_time\no.seed_elements(lon, lat, radius=0, number=30*30, time=time)\n\no.run(steps=48, time_step=3600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The custom landmask from shapefile, which is used for the simulation, is also shown in the map instead of the default GSHHG\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.plot()\n\no.animation()" ] }, { "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 }