{ "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": [ "#### Install the ferret extension" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "ferretmagic extension is now a package you can install from pip\n", "\n", "`pip install ferretmagic`\n", "\n", "https://pypi.python.org/pypi/ferretmagic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### then load the extension" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext ferretmagic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Now use extension magic cell (%%ferret) or magic line (%ferret_run)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    GRID GMS1\n",
       " name       axis              # pts   start                end                 subset\n",
       " XAXLEVITR LONGITUDE          360mr   20.5E                19.5E(379.5)        full\n",
       " YAXLEVITR LATITUDE           180 r   89.5S                89.5N               full\n",
       " ZAXLEVITR DEPTH (m)           20 i-  0                    5000                full\n",
       " normal    T\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "use levitus_climatology\n", "show grid temp\n", "let a=12" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/html": [ "
             VARIABLE : 12\n",
       "          12.00\n",
       "     currently SET data sets:\n",
       "    1> /opt/ferret_dsets/data/levitus_climatology.cdf  (default)\n",
       " name     title                             I         J         K         L\n",
       " TEMP     TEMPERATURE                      1:360     1:180     1:20      ...\n",
       " SALT     SALINITY                         1:360     1:180     1:20      ...\n",
       " \n",
       "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "list a\n", "show data\n", "plot i[i=1:10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Usage and current options" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Control size of plot with option --size, -s width, heigh\n", "* Create a local pdf at the same time with option --pdf, -p\n", "* Do not display stdout with option --quiet, -q\n", "\n", "Discover usage by typing\n", "%ferret_run?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Plot are imbedded into directly into the notebook" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -b -q -s 800,600\n", "shade/lev=15 temp[k=@std]\n", "go land\n", "go text_put 50 50 \"aaaa\" 0 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### You can execute ferret commands from python with the line magic %ferret_run" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for i in range(1,10,2):\n", " %ferret_run -q -s 300,300 'shade temp[k=%(i)s] ; go land' % locals()\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "2\n" ] } ], "source": [ "def draw(i):\n", " %ferret_run -q -s 300,300 'shade temp[k=%d] ; go land' % i\n", " print(\"%d\" % (i))\n", " \n", "draw(2)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for i in [100,500,1000]:\n", " %ferret_run -b -s 300,300 'plot sin(i[i=1:%(i)s]*0.1)' % locals()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Display helps" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "%%ferret?" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "%ferret_run?" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
PPL$XPIXEL = \"756\"\n",
       "PPL$YPIXEL = \"612\"\n",
       "BYTEORDER = \"LITTLE\"\n",
       "FERRET_VERSION = \"7.5\"\n",
       "FERRET_PLATFORM = \"Linux 4.15.0-1059-azure\"\n",
       "FERRET_PRECISION = \"double\"\n",
       "NETCDF_VERSION = \"4.6.2 of Dec 17 2018 19:36:03 $\"\n",
       "FERRET_MEMORY = \"50\"\n",
       "SESSION_DATE = \"13-Nov-19\"\n",
       "SESSION_TIME = \"17:47\"\n",
       "SESSION_PID = \"30073\"\n",
       "DELTA_CPU = \"2.71272\"\n",
       "CLOCK_SECS = \"14.329\"\n",
       "CURRENT_DATE = \"13-Nov-19\"\n",
       "CURRENT_TIME = \"17:47:57\"\n",
       "N_OPEN_DSETS = \"1\"\n",
       "PROGRAM_NAME = \"PyFerret\"\n",
       "PEAK_MEMORY = \"1555201\"\n",
       "SPAWN_OK = \"1\"\n",
       "SPAWN_STATUS = \"0\"\n",
       "GO_FILE = \"n/a\"\n",
       "LAST_GO_FILE = \"/opt/Ferret-7.5.0-RHEL7-64/go/land.jnl\"\n",
       "WIN_TITLE = \"13-Nov-19:17:47\"\n",
       "PPL$FORMAT = \"(3F10.2)\"\n",
       "PPL$PLTNME = \"ferret.png\"\n",
       "PPL$TEKNME = \"/dev/tt\"\n",
       "PPL$XLEN = \"8.33000\"\n",
       "PPL$YLEN = \"5.72400\"\n",
       "PPL$XORG = \"1.20000\"\n",
       "PPL$YORG = \"1.40000\"\n",
       "PPL$WIDTH = \"10.5300\"\n",
       "PPL$HEIGHT = \"8.52400\"\n",
       "PPL$LINE_COUNT = \" 1\"\n",
       "PPL$XFACT1 = \"1.000000\"\n",
       "PPL$XOFF1 = \"0.000000\"\n",
       "PPL$YFACT1 = \"1.000000\"\n",
       "PPL$YOFF1 = \"0.000000\"\n",
       "PPL$VIEW_X = \"0.000\"\n",
       "PPL$VIEW_Y = \"0.000\"\n",
       "PPL$VIEW_Z = \"0.000\"\n",
       "PPL$COMMAND_FILE = \"$$MEMBUF$$\"\n",
       "VP_WIDTH = \"10.53\"\n",
       "VP_HEIGHT = \"8.524\"\n",
       "PPL$SCALE = \"1.0000\"\n",
       "VP_SCALE = \"1\"\n",
       "VP_RT_MARGIN = \"1\"\n",
       "VP_TOP_MARGIN = \"1.4\"\n",
       "VP_XLO = \"0\"\n",
       "VP_XHI = \"1\"\n",
       "VP_YLO = \"0\"\n",
       "VP_YHI = \"1\"\n",
       "LAB1 = \"PyFerret (optimized) Ver.7.5\"\n",
       "LAB2 = \"NOAA/PMEL TMAP\"\n",
       "LAB3 = \"13-NOV-2019 17:47:51\"\n",
       "PPL$XMIN1 = \"1.000000\"\n",
       "PPL$XMAX1 = \"1000.000\"\n",
       "PPL$YMIN1 = \"-0.9999902\"\n",
       "PPL$YMAX1 = \"0.9999965\"\n",
       "LEV_TEXT = \"15\"\n",
       "AX_VERT = \"Y\"\n",
       "LABX = \"X\"\n",
       "AX_HORIZ = \"X\"\n",
       "LABY = \"\"\n",
       "LABTIT = \"SIN(I[I=1:1000]*0.1)\"\n",
       "XAXIS_REVERSED = \"0\"\n",
       "YAXIS_REVERSED = \"0\"\n",
       "PPL$XFIRST1 = \"1.000000\"\n",
       "PPL$YFIRST1 = \"9.9833414E-02\"\n",
       "PPL$XLAST1 = \"500.0000\"\n",
       "PPL$YLAST1 = \"-0.2623748\"\n",
       "XAXIS_MIN = \"1.00000000\"\n",
       "XAXIS_MAX = \"1000.00000\"\n",
       "YAXIS_MIN = \"-1.000000\"\n",
       "YAXIS_MAX = \"1.000000\"\n",
       "LEV_MIN = \"-2\"\n",
       "LEV_MAX = \"30\"\n",
       "LEV_NUM = \"32\"\n",
       "LEV_DEL = \"1\"\n",
       "LEV_CENTERED_LABELS = \"off\"\n",
       "LEV_ALL = \"-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\"\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "show symb" ] } ], "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 }