{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# xmitgcm llcreader demo\n", "\n", "This notebooks contains a demonstration of reading and visulizing data from the\n", "[NAS ECCO Data Portal](https://data.nas.nasa.gov/ecco/).\n", "It makes use of the following software libraries:\n", "\n", "- [xmitgcm](https://xmitgcm.readthedocs.io/en/latest/llcreader.html): provides the `llcreader` module which makes all of this work\n", "- [xarray](http://xarray.pydata.org/en/latest/): the basic data structures and computational library for the datasets \n", "- [dask](https://dask.org/): the parallel computing library which enables lazy representations of huge arrays\n", "- [holoviews](http://holoviews.org/): interactive visualizations\n", "\n", "We start by importing the necessary libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import xmitgcm.llcreader as llcreader\n", "%matplotlib inline\n", "import holoviews as hv\n", "from holoviews.operation.datashader import regrid\n", "hv.extension('bokeh')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Initialize Model Object\n", "\n", "[xmitgcm.llcreader]() contains pre-configured references to known LLC model configurations.\n", "We create one of these references as follows:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model = llcreader.ECCOPortalLLC2160Model()\n", "model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create Xarray Dataset\n", "\n", "The `model` object can generate xarray datasets for us.\n", "In this example, we generate a dataset which contains the SST for the full model integration.\n", "The `type='latlon'` keyword tells xmitgcm to just show us the \"Lat Lon\" (LL) part of the LLC grid." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds_sst = model.get_dataset(varnames=['Theta'], k_levels=[0], type='latlon')\n", "ds_sst" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This dataset is \"lazy\"; it doesn't actually load any data from the server until required for computation or plotting.\n", "That's a good thing, because it represents over 4 TB of data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds_sst.nbytes / 1e12" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dynamic Interactive Visualization\n", "\n", "Here we create an interactive map of SST which automatically resamples the fields at a resolution appropriate for our screen." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset = hv.Dataset(ds_sst.Theta.isel(k=0).astype('f4'))\n", "hv_im = (dataset.to(hv.Image, ['i', 'j'], dynamic=True)\n", " .options(cmap='Magma', width=950, height=600, colorbar=True))\n", "\n", "%output holomap='scrubber' fps=3\n", "regrid(hv_im, precompute=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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" } }, "nbformat": 4, "nbformat_minor": 2 }