{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualization Control System Principles \n", "\n", "VCS Allows scientists to produce highly customized plots. Everything can be precisely and logically controlled.\n", "\n", "To [download this Jupyter Notebook](VCS_Principles.ipynb), right click on the link and choose \"Download Linked File As...\" or \"Save Link as...\". Remember where you saved the downloaded file, which should have an .ipynb extension. (You'll need to launch the Jupyter notebook or JupyterLab instance from the location where you store the notebook file.)" ] }, { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

Table of Contents

\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# VCS Object definitions\n", "import vcs\n", "import cdms2\n", "import os\n", "vcs.download_sample_data_files()\n", "with cdms2.open(os.path.join(vcs.sample_data,\"clt.nc\")) as f:\n", " clt = f(\"clt\")\n", " u = f(\"u\")\n", " v = f(\"v\")\n", "with cdms2.open(os.path.join(vcs.sample_data,\"sampleCurveGrid4.nc\")) as f:\n", " curv = f(\"sample\")\n", "with cdms2.open(os.path.join(vcs.sample_data,\"sampleGenGrid3.nc\")) as f:\n", " gen = f(\"sample\")\n", "\n", "x = vcs.init(geometry=(600,400),bg=True)\n", "\n", "# Styling for the notebook\n", "from IPython.core.display import HTML\n", "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\n", "\n", "[Back to Top](#top)\n", "\n", "Essentially a vcs plot can be broken down into three parts:\n", "\n", "**WHAT** is plotted (e.g data and labels) **HOW** it is rendered (isolines, boxfill, isofill, vectors, etc...) and **WHERE** (the location on the page where each element is to be plotted)\n", "\n", "## What\n", "\n", "[Back to Top](#top)\n", "\n", "This is the scientific piece of information that the user is trying to represent for others (or oneself) to understand. It can be as raw as a simple numpy object. It is recommended to use [CDMS](https://github.com/uv-cdat/cdms)'s transient variables. CDMS transient variables contain metadata such as name, units, and geospatial information that can be used by VCS to better represent the data.\n", "\n", "The [tutorials] section has many CDMS examples. The CDMS documentation can be found [here](http://readthedocs.org/projects/cdms/).\n", "\n", "## How\n", "\n", "[Back to Top](#top)\n", "\n", "This describes the data representation. At the highest level it is a `graphics method` i.e *boxfill*, *isofill*, *vectors*, *streamlines*, *line plot*, etc., but it also contains information to further control these plot types, e.g. which colors to use, which levels, line thickness, etc. \n", "\n", "Graphic methods also describe how axes and labels should be represented (e.g. which axis values to show and which text to use for the values. The user might want to show the `-20.` longitude represented as `20S` or the date `2020-01-15` shown as `Jan 2020`. \n", "\n", "Currently VCS supports the following graphic methods:\n", "\n", "### Boxfill\n", "\n", "[Back to Top](#top)\n", "\n", "Boxfill is used to represent 2-dimensional arrays, filling each array cell with a color representing its value. In the case of rectilinear grids where x and y axes can be represented by a 1-dimensional array, we use the axes **bounds** to determine the extent of each cell. This is especially useful if an axis is not increasing constantly (e.g. a gaussian grid or pressure levels).\n", "\n", "For more information on boxfill, please see the [dedicated tutorial](https://cdat.llnl.gov/Jupyter-notebooks/vcs/boxfill/boxfill.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gm = vcs.createboxfill()\n", "x.plot(clt, gm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Isoline\n", "\n", "[Back to Top](#top)\n", "\n", "An isoline is a line on a map, chart, or graph that connects points of equal value." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gm = vcs.createisoline()\n", "x.clear()\n", "x.plot(clt,gm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Isofill\n", "\n", "[Back to Top](#top)\n", "\n", "The isofill graphic method is similar to isolines (and usually plotted in conjounction with it) except that the area between two consecutive isolines is filled with a color representing the range of values in this area." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "gm = vcs.createisofill()\n", "x.plot(clt,gm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Meshfill\n", "\n", "[Back to Top](#top)\n", "\n", "Meshfill is very similar to boxfill, but is used to represent data on generic grids (a.k.a. native representation) based on the input data and a *mesh*." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "gm = x.createmeshfill()\n", "gm.mesh = True\n", "x.plot(gen, gm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Streamlines\n", "\n", "[Back to Top](#top)\n", "\n", "For more information on streamlines please see the [dedicated tutorial](https://cdat.llnl.gov/Jupyter-notebooks/vcs/streamlines/streamlines.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "gm = vcs.createstreamline()\n", "x.plot(u,v,gm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Vector Plots\n", "\n", "[Back to Top](#top)\n", "\n", "A vector plot is a collection of arrows with a given magnitude and direction, each attached to a point in the plane." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "gm = vcs.createvector()\n", "x.plot(u,v, gm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Line (1D) Plots\n", "\n", "[Back to Top](#top)\n", "\n", "A line plot is a graph that shows the frequency of data along a number line.\n", "\n", "For more information on 1D or line plots please see the [dedicated tutorial](https://cdat.llnl.gov/Jupyter-notebooks/vcs/1D_Multi_line_Plots/1D_Multi_line_Plots.html). \n", "\n", "Also of interest is the [EzPlot Example](https://cdat.llnl.gov/Jupyter-notebooks/vcsaddons/EzPlot_Example/EzPlot_Example.html) tutorial. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "gm = vcs.create1d()\n", "x.plot(clt[:,34,23]) # extract a time series at one point on the globe and plot it in 1D" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Taylor Diagrams\n", "\n", "[Back to Top](#top)\n", "\n", "Taylor diagrams are mathematical diagrams designed to graphically indicate which of several approximate representations (or models) of a system, process, or phenomenon is most realistic. \n", "\n", "Please see the [Taylor Diagrams](https://cdat.llnl.gov/Jupyter-notebooks/vcs/Taylor_Diagrams/Taylor_Diagrams.html) tutorial for more information." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Where\n", "\n", "[Back to Top](#top)\n", "\n", "Where each element of a plot is located on the page is the most complicated part of VCS but also one of the most powerful. Templates precisely control the location of every component on the plot. For detailed information on templates, please see the [VCS Templates](https://cdat.llnl.gov/Jupyter-notebooks/vcs/VCS_Templates/VCS_Templates.html) tutorial." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Useful Objects\n", "\n", "[Back to Top](#top)\n", "\n", "VCS uses the following objects to customize a plot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Text Objects\n", "\n", "[Back to Top](#top)\n", "\n", "Text objects allow you to insert text anywhere on the plot.\n", "Text objects are made by combining two different objects: text orientation objects and text table objects.\n", "\n", "For more details on text in vcs see this [dedicated tutorial](https://cdat.llnl.gov/Jupyter-notebooks/vcs/VCS_Text_Objects/VCS_Text_Objects.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "txt = vcs.createtext()\n", "txt.string=\"A Text Object\"\n", "txt.height=25\n", "txt.x = [.5]\n", "txt.y=[.5]\n", "txt.list()\n", "x.plot(txt)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Line/Polygon Objects\n", "\n", "[Back to Top](#top)\n", "\n", "Line objects allow you to draw lines on the plot. By closing the line you can draw a polygon." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "line = vcs.createline()\n", "line.x = [0.1, .5, 0.9]\n", "line.y = [0.1, .2, 0.9]\n", "x.plot(line)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Filled Polygon Objects\n", "\n", "[Back to Top](#top)\n", "\n", "The filled ploygon object allows you to draw a filled polygon on the plot." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "filled = vcs.createfillarea()\n", "filled.x = [0.1, .5, 0.9]\n", "filled.y = [0.1, .2, 0.9]\n", "x.plot(filled)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Marker Objects\n", "\n", "[Back to Top](#top)\n", "\n", "The marker object allows you to draw one or more markers on a plot." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "mrk = vcs.createmarker()\n", "mrk.type = \"hurricane\"\n", "mrk.x = [.5]\n", "mrk.y = [.5]\n", "mrk.size = 15\n", "x.plot(mrk)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Colormap Objects\n", "\n", "[Back to Top](#top)\n", "\n", "Colormap objects are used to control the colors on vcs plots. They can be attached to a secondary object, graphic methods, or canvases.\n", "\n", "For more details on existing color maps in VCS see the [Color Map](https://cdat.llnl.gov/Jupyter-notebooks/vcs/Colormap_Tutorial/Colormap_Tutorial.html) tutorial. For information on creating your own colormap, see [this tutorial](https://cdat.llnl.gov/Jupyter-notebooks/vcs/Colormap_Create/Color_map_create_own.html)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Projection Objects\n", "\n", "[Back to Top](#top)\n", "\n", "When plotting latitude/longitude plots (2d graphic methods) you can specifiy and control the projection associated with the plot. Projection objects are then attached to the graphic method." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x.clear()\n", "gm = vcs.createisofill()\n", "proj = vcs.createprojection()\n", "proj.type=\"lambert\"\n", "proj.list()\n", "proj.originlatitude=30.\n", "gm.projection = proj\n", "x.plot(clt(latitude=(10,50),longitude=(-130,-70)), gm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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", "If you have questions about this notebook, please email our [CDAT Support](cdat-support@llnl.gov) address, cdat-support@llnl.gov." ] } ], "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.6.7" }, "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 }