{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "Patrick BROCKMANN - LSCE (Climate and Environment Sciences Laboratory)
\n", "

\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Updated: 2019/11/13" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Load the ferret extension" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext ferretmagic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Get data from ferret and put data from python" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
! Enter_GO land\n",
       "! Exit_GO          \n",
       "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "set text/font=hershey\n", "use coads_climatology\n", "shade sst[l=10] ; go land" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Message: sstdict is now available in python as a dictionary containing the variable's metadata and data array.
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%ferret_getdata sstdict = sst" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['title', 'data', 'missing_value', 'data_unit', 'axis_types', 'axis_names', 'axis_units', 'axis_coords'])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sstdict.keys()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.ndarray" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sstdata = sstdict['data']\n", "type(sstdata)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['title', 'data', 'missing_value', 'data_unit', 'axis_types', 'axis_names', 'axis_units', 'axis_coords', 'name'])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy\n", "mask = numpy.abs(sstdata - sstdict['missing_value']) < 1.0E-5\n", "sstdata[mask] = -10.0\n", "sstdict['name'] = 'SSTCopy'\n", "sstdict['title'] = 'SST with miss vals set to -10'\n", "sstdict.keys()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Message: sstdict is now available in ferret as SSTCopy
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%ferret_putdata sstdict" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
     currently SET data sets:\n",
       "    1> /opt/ferret_dsets/data/coads_climatology.cdf  (default)\n",
       " name     title                             I         J         K         L\n",
       " SST      SEA SURFACE TEMPERATURE          1:180     1:90      ...       1:12\n",
       " AIRT     AIR TEMPERATURE                  1:180     1:90      ...       1:12\n",
       " SPEH     SPECIFIC HUMIDITY                1:180     1:90      ...       1:12\n",
       " WSPD     WIND SPEED                       1:180     1:90      ...       1:12\n",
       " UWND     ZONAL WIND                       1:180     1:90      ...       1:12\n",
       " VWND     MERIDIONAL WIND                  1:180     1:90      ...       1:12\n",
       " SLP      SEA LEVEL PRESSURE               1:180     1:90      ...       1:12\n",
       " ------ Python Variables ------\n",
       " SSTCOPY  SST with miss vals set to -10    1:180     1:90      ...       1:12      ...       ...\n",
       " \n",
       "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "show data\n", "shade sstcopy[l=1]" ] } ], "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" } }, "nbformat": 4, "nbformat_minor": 1 }