{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Streamlines Tutorial \n", "\n", "This tutorial demonstrates VCS streamline support\n", "We show randomly seeded and evenly spaced streamlines.\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "import vcs\n", "import cdms2\n", "\n", "The CDAT software was developed by LLNL. This tutorial was written by Charles Doutriaux. This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344.\n", "\n", "[Download the Jupyter Notebook](streamlines.ipynb)\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

Table of Contents

\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Streamlines\n", "\n", "[Back to Top](#top)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import cdms2\n", "import vcs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Download the sample data if needed\n", "# vcs.download_sample_data_files()\n", "# read clt.nc\n", "f=cdms2.open(vcs.sample_data+\"/clt.nc\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# read two variables\n", "u = f(\"u\")\n", "v = f(\"v\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# initialize vcs\n", "x=vcs.init()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# create the streamline graphics method\n", "gm = x.createstreamline()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# we set parameters for randomly seeded streamlines\n", "gm.evenlyspaced = False # only available on releases after 2.10 or on the nightly packages.\n", "# streamlines are colored by vector magnitude\n", "gm.coloredbyvector = True\n", "# We want 10 glyphs(arrows) per streamline\n", "gm.numberofglyphs = 10\n", "gm.filledglyph = True\n", "# we place 400 random seeds in a circle that covers the data. This means fewer seeds will be inside the data.\n", "# The number of seeds inside the data will result in streamlines.\n", "gm.numberofseeds = 400" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# use the robinson projection for the data.\n", "p = x.createprojection()\n", "p.type = 'robinson'\n", "gm.projection = p" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# we plot randomly seeded streamlines\n", "x.plot(u, v, gm, bg=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# we plot evenly spaced streamlines\n", "x.clear()\n", "gm.evenlyspaced = True # only available only on releases > 2.10 or on the nightly packages\n", "# We want the streamline to be about one cell apart from each other\n", "gm.separatingdistance = 1\n", "# The seed for the first streamline. All other seeds are generated automatically\n", "gm.startseed = [0, 0, 0]\n", "# create an evenly spaced streamline plot\n", "x.plot(u, v, gm, bg=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# we plot randomly seeded streamlines with a red color map\n", "x.clear()\n", "#create a red colormap with low values mapped to low opacity\n", "cmap = x.createcolormap()\n", "for i in range(256):\n", " cmap.setcolorcell(i,100.,0,0,i/2.55)\n", "x.setcolormap(cmap)\n", "gm.evenlyspaced=False # attribute available only on releases > 2.10 or on the nightly packages\n", "x.plot(u, v, gm, bg=1)" ] } ], "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.7.3" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }