{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Model landmask\n\nComparing two simulation runs, with landmask from ocean model and GSHHG\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from datetime import timedelta\n\nfrom opendrift.readers import reader_ROMS_native\nfrom opendrift.models.oceandrift import OceanDrift\n\nlon = 14.75; lat = 68.1\n\no = OceanDrift(loglevel=20)\n\nreader_nordic = reader_ROMS_native.Reader(o.test_data_folder() +\n '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First run, with default GSHHG vector landmask\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.add_reader([reader_nordic])\ntime = reader_nordic.start_time\no.set_config('general:use_auto_landmask', True)\no.seed_elements(lon, lat, radius=3000, number=1000, time=time)\no.run(end_time=reader_nordic.end_time, time_step=1800, time_step_output=3*3600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Second run, with landmask from ocean model\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o2 = OceanDrift(loglevel=20)\no2.add_reader([reader_nordic])\nlon = 14.75; lat = 68.1\no2.set_config('general:use_auto_landmask', False)\no2.seed_elements(lon, lat, radius=3000, number=1000, time=time)\no2.run(end_time=reader_nordic.end_time, time_step=1800, time_step_output=3*3600)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from matplotlib.colors import ListedColormap\nimport cartopy.feature as cfeature\ncmap = ListedColormap([cfeature.COLORS['water'],\n cfeature.COLORS['land']])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nTo only show the landmask from the model, hide the coastline landmask by doing:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o2.plot(background='land_binary_mask', hide_landmask=True, cmap=cmap)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Animation illustrating that red particles strand at ocean model land cells, and black particles strand at GSHHG land polygons\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.animation(compare=o2, background='land_binary_mask', cmap=cmap,\n legend=['Default GSHHG landmask', 'Ocean model landmask'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o.plot(compare=o2, background='land_binary_mask', cmap=cmap,\n legend=['Default GSHHG landmask', 'Ocean model landmask'])" ] } ], "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 }