{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Redecorate Transient Variable \n", "\n", "This Jupyter Notebook shows how to redecorate a transient variable that became a numpy array\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", "\n", "\n", "[Download the Jupyter Notebook](Redecorate%2BTransient%2BVariable.ipynb)" ] }, { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

Table of Contents

\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Import Modules\n", "[Back to Top](#top)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# import modules\n", "import MV2\n", "import cdms2\n", "import numpy\n", "import cdat_info # for sample data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Open Data\n", "[Back to Top](#top)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# open some data\n", "f=cdms2.open(cdat_info.get_sampledata_path()+\"/clt.nc\")\n", "s=f(\"clt\")\n", "print(type(s))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Run Data\n", "[Back to Top](#top) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Now run an operation on this MV2 that turns it to munpy array\n", "fft_s = numpy.fft.fft(s)\n", "print(type(fft_s)) # numpy array" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Put Back Dimensions\n", "[Back to Top](#top) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# now put back dimensions on it\n", "fft_s = MV2.array(fft_s)\n", "fft_s.setAxisList(s.getAxisList())\n", "\n", "# Dimensions are back\n", "print(fft_s.getAxisIds())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Put Attributes On It\n", "[Back to Top](#top) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# now puts the attributes on it\n", "for a in s.attributes:\n", " setattr(fft_s,a,getattr(s,a))\n", "fft_s.info()" ] } ], "metadata": { "anaconda-cloud": {}, "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": 1 }