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

ferret

\n", "\n", "I wish to acknowledge use of the **ferret** and **pyferret** programs for analysis and graphics in this notebook.
\n", "Ferret is a product of NOAA's Pacific Marine Environmental Laboratory.\n", "\n", "Information is available at http://ferret.pmel.noaa.gov/Ferret/\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Installation

\n", "\n", "Install ferret\n", " http://ferret.pmel.noaa.gov/Ferret/downloads/downloading_ferret\n", " \n", "or\n", "\n", "Install pyferret\n", " http://ferret.pmel.noaa.gov/Ferret/downloads/pyferret/\n", "\n", "To use pyferret inside a notebook, please install the extension ferretmagic from https://github.com/PBrockmann/ipython_ferretmagic\n", "\n", " pip install ferretmagic\n", " \n", "Other extension can be found from https://github.com/ipython/ipython/wiki/Extensions-Index" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Classic start

\n", "\n", "Launch a ferret session by typing:\n", "\n", " $ ferret\n", "\n", "You get a ferret prompt starting by:\n", "\n", " yes?\n", "\n", "In a ferret sessions, the command history is available from up/down arrow keys.
\n", "Remember also that **CTRL+a** goes to the beginning of the line and **CTR+e** to the end.\n", "\n", "Note that ferret is not case sensitive\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Minimal survivor kit

\n", "\n", "#### Commands\n", "
\n", "\n", "
\n", "\n", "#### Common qualifiers\n", "\n", "
\n", "\n", "
\n", " \n", "#### Variables\n", "\n", "
\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

The magic extension

\n", "\n", "This will let you call pyferret from your notebook and embed all output in it" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext ferretmagic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remember jupyter notebook shortcuts (https://www.cheatography.com/weidadeyue/cheat-sheets/jupyter-notebook/)\n", "\n", "* CTRL+z to undo\n", "* CTRL+y to redo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

A first map

" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
     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" } ], "source": [ "%%ferret\n", "\n", "cancel data/all\n", "use levitus_climatology\n", "show data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q\n", "\n", "shade temp[k=1] ; go land" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Access to the help of the ferretmagic extension" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "%%ferret?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Plot a profile

" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -s 600,400\n", "\n", "cancel mode logo\n", "plot temp[x=@ave,y=@ave]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Transforms

" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
variable transforms e.g.SST[T=1-jan:15-mar@DDC]\n",
       "   code        description                  code        description\n",
       "   ----        -----------                  ----        -----------\n",
       "   @ITP        interpolated                 @FAV        ave-filled\n",
       "   @AVE        averaged                     @FLN        linear-filled\n",
       "   @VAR        variance                     @FNR        nearest-filled\n",
       "   @SUM        summed                       @NGD        number of valid\n",
       "   @RSU        running sum                  @NBD        number flagged bad\n",
       "   @SHF        shifted                      @LOC        location\n",
       "   @MIN        minimum                      @WEQ        weighted equal\n",
       "   @MAX        maximum                      @CDA        closest dist above\n",
       "   @DDC        centered derivative          @CDB        closest dist below\n",
       "   @DDF        forward derivative           @CIA        closest index above\n",
       "   @DDB        backwards derivative         @CIB        closest index below\n",
       "   @DIN        integrated                   @EVN        event mask\n",
       "   @IIN        indef. integ.                @MED        median smoothed\n",
       "   @SBX        box smoothed                 @SMX        maximum smoothed\n",
       "   @SBN        binomial smoothed            @SMN        minimum smoothed\n",
       "   @SWL        Welch smoothed               @STD        standard deviation\n",
       "   @SHN        Hanning smoothed             @WGT        weights for avg,int\n",
       "   @SPZ        Parzen smoothed              @SPX        box smooth w/missing\n",
       " \n",
       "regridding transforms e.g.SST[GX=x5deg@AVE]\n",
       "   code        description                  code        description\n",
       "   ----        -----------                  ----        -----------\n",
       "   @LIN        lin. interp.                 @MODVAR     modulo var\n",
       "   @AVE        area-wgtd avgd               @MODNGD     # gd mod pts\n",
       "   @XACT       exact match                  @MODNBD     #bad mod pts\n",
       "   @ASN        index assn                   @MODSUM     modulo sum\n",
       "   @VAR        variance                     @MODMIN     modulo min\n",
       "   @MIN        minimum                      @MODMAX     modulo max\n",
       "   @MAX        maximum                      @NRST       nearst coord\n",
       "   @SUM        area-wgtd sum                @BIN        unwgtd avg\n",
       "   @NGD        #gd pts, area wgtd           @NBIN       #good in bin\n",
       "   @MOD        modulo ave                   @IIN        #indef integral\n",
       " \n",
       "auxiliary varible regridding transforms e.g.TEMP[GZ(depth)=zax@AVE]\n",
       "   code        description                  code        description\n",
       "   ----        -----------                  ----        -----------\n",
       "   @LIN        lin. interp.                 @PLAVE      pc-wise linear ave\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "\n", "show transforms" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 600,500\n", "\n", "shade/lev=20v temp[k=@var] ; go land" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Variable definition

\n", "\n", "In addition to all variables read from open datasets, you can define your own variables with the let command by typing for example:\n", "\n", " yes? let temp1 = temp - 273.15\n", "\n", "It will defined a new variable temp1 but will only set the relation. No calcul is made at this time.\n", "\n", "Define a recursive variable like\n", "\n", " yes? let temp = temp + 20.\n", "\n", "has no sens in ferret.\n", "\n", "You can of course combine variables from different datasets by specifying its dataset number [d=...]\n", "\n", " yes? let var1 = varA[d=1] + varB[d=2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Conditionnal variables

\n", "\n", "You can define conditionnal variable with the following syntax:\n", "\n", " yes? let var3= if varA gt varB then varA else varC\n", "\n", "The locigal condition can be gt, ge, eq, lt, le and several expressions can be combined using boolean operators (and, or). \n", "\n", "For example:\n", " \n", " yes? let tempselect = if (temp ge 10) and (temp lt 20) then 1\n", " yes? shade tempselect[k=1]\n", "\n", "define a mask with the condition 10 <= temp < 20\n", " \n", "or:\n", "\n", " yes? let saltselect = if temp gt 20 then salt\n", " yes? shade saltselect[k=1] ; go land\n", "\n", "produces a map of salinity only for water warmer than 20 degrees." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 1000,500\n", "\n", "\n", "set viewport left; shade salt[k=1] ; go land\n", "\n", "let saltselect = if temp gt 20 then salt\n", "set viewport right; shade/lev=20v saltselect[k=1] ; go land\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Domain selection

\n", "\n", "You may want to work only on a sub-domain of a variable. For this you can define limits on the different dimensions of the variable by using the syntax\n", "\n", "* X= ,Y=, Z=, T=, E=, F=\n", "\n", "or with indices notations \n", "\n", "* I=, J=, K=, L=, M=, N=\n", "\n", "Using this:\n", "\n", " yes? shade salt[X=30:120, Y=-40:30, K=1] ; go land\n", "\n", "will plot a map centered on the Indian Ocean (longitudes from 30° to 120° degrees East and latitudes from 40° South to 30° North)." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 400,400\n", "\n", "shade salt[X=30:120, Y=-40:30, K=1] ; go land" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We reduce the X axis and let free the vertical axis to get a slice of the Indian Ocean." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 600,500\n", "\n", "shade temp[X=30:120@AVE, Y=-40:30]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can apply transformation to any of the dimensions of the variable and reduce it to a single scalar." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
             VARIABLE : SALINITY (PPT)\n",
       "             FILENAME : levitus_climatology.cdf\n",
       "             FILEPATH : /opt/ferret_dsets/data/\n",
       "             LONGITUDE: 30E to 120E (XY ave)\n",
       "             LATITUDE : 40S to 30N (XY ave)\n",
       "             DEPTH (m): 0 to 5000 (maximum)\n",
       "          35.28\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -s 400,400\n", "\n", "plot/grat=(dash)/line/symbol salt[X=30:120@ave, Y=-40:30@ave]\n", "\n", "list salt[X=30:120@ave, Y=-40:30@ave, Z=@max]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Selections on physical axis are expressed in the units of the axis (express time with DD-MMM-YYYY format).\n", "East longitudes and North latitudes are defined to be positive.\n", "\n", "Note that transformations are sequentially applied from X to N axis except for the @AVE transformation that is applied simultaneously on X and Y.\n", "\n", " salt[X=30:120@ave, Y=-40:30@ave, Z=@max]\n", " \n", "represents well the maximum of the average and not the average of the maximum.\n", "\n", "\n", "The following plot represents the wind module from 1985 to 1989 years. Overlaid the same field smoothed with a running mean over 12 time steps." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -s 600,400\n", "\n", "cancel data/all\n", "use monthly_navy_winds.cdf\n", "\n", "ppl color 6, 70, 70, 70\n", "\n", "let/title=\"wind module\"/units=\"m/s\" module=(UWND^2+VWND^2)^0.5\n", "let/title=\"North Atlantic Wind module\"/units=\"m/s\" module_AN=module[x=260:360@ave,y=30:60@ave]\n", "plot/grat=(dash, color=6) module_AN[t=\"01-JAN-1985\":\"01-JAN-1989\"]\n", "plot/over/thick=3/title=\"Smooth on 12 months\" module_AN[t=\"01-JAN-1985\":\"01-JAN-1989\"@SBX:12]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Definition strategy

\n", "\n", "The definitions of the variables should as generic as possible, ie without domain specification. It is only when the plot or calculation commands are used that the limits must be specified. Do not hesitate to multiply the number of variable definitions, from the most general to the most limited and also for the sake of clarity.\n", "\n", "In the same idea, operations on variables can only be done if the variables are compatible in dimension. Adding a vector defined on a longitude (X) to a vector defined on time (T) will have no meaning.\n", "\n", "Note that you can specify a domain as a qualifier of a command to avoid repetitions inside variables. So\n", "\n", " yes? plot varA[i=20:40,d=1], varB[i=20:40,d=1], varC[i=20:40,d=2]\n", "\n", "could be written\n", "\n", " yes? plot/i=20:40 varA[d=1], varB[d=1], varC[d=2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Interpolation on domain

\n", "\n", "The transformation @ITP provides the same functionality as MODE INTERPOLATE with a greater level of control." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 1000,500\n", "\n", "cancel data/all\n", "use levitus_climatology\n", "\n", "set viewport left; shade/lev=20v temp[z=2450] ; go land\n", "! use of the @itp to interpolate between layer (by default ferret will select the nearest layer)\n", "set viewport right; shade/lev=20v temp[z=2450@itp] ; go land" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Grid

\n", "\n", "Grid is the structure that hosts the data values. The grid is composed of axis.\n", "You can access to the underlaying grid of a variable by typing:\n", "\n", " yes? show grid temp\n", " yes? show grid/z temp\n" ] }, { "cell_type": "code", "execution_count": 14, "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",
       " \n",
       "       K     Z                       ZBOX          ZBOXLO\n",
       "       1>  0                         5          0\n",
       "       2>  10                        10         5\n",
       "       3>  20                        10         15\n",
       "       4>  30                        15         25\n",
       "       5>  50                        22.5       40\n",
       "       6>  75                        25         62.5\n",
       "       7>  100                       37.5       87.5\n",
       "       8>  150                       50         125\n",
       "       9>  200                       75         175\n",
       "      10>  300                       100        250\n",
       "      11>  400                       150        350\n",
       "      12>  600                       200        500\n",
       "      13>  800                       200        700\n",
       "      14>  1000                      200        900\n",
       "      15>  1200                      250        1100\n",
       "      16>  1500                      400        1350\n",
       "      17>  2000                      750        1750\n",
       "      18>  3000                      1000       2500\n",
       "      19>  4000                      1000       3500\n",
       "      20>  5000                      500        4500\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "\n", "show grid/z temp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Dynamic regridding

\n", "\n", "You can do dynamic regridding to pass from one axis to another one. This is a very powerfull feature of ferret and you should read the official documentation to better understand those capacities (http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/Grids-Regions/GRIDS#Chapter4-Regridding).\n", "\n", "Let's make a very simple example. Imagine you would like to regrid the previons temp variable over a new vertical axis, regulary spaced." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
 name       axis              # pts   start                end\n",
       " MYNEWZAXIS Z (METERS)         25 r   100                  4900\n",
       "   Axis span (to cell edges) = 5000\n",
       " \n",
       "       K     Z                       ZBOX          ZBOXLO\n",
       "       1>  100                       200        0\n",
       "       2>  300                       200        200\n",
       "       3>  500                       200        400\n",
       "       4>  700                       200        600\n",
       "       5>  900                       200        800\n",
       "       6>  1100                      200        1000\n",
       "       7>  1300                      200        1200\n",
       "       8>  1500                      200        1400\n",
       "       9>  1700                      200        1600\n",
       "      10>  1900                      200        1800\n",
       "      11>  2100                      200        2000\n",
       "      12>  2300                      200        2200\n",
       "      13>  2500                      200        2400\n",
       "      14>  2700                      200        2600\n",
       "      15>  2900                      200        2800\n",
       "      16>  3100                      200        3000\n",
       "      17>  3300                      200        3200\n",
       "      18>  3500                      200        3400\n",
       "      19>  3700                      200        3600\n",
       "      20>  3900                      200        3800\n",
       "      21>  4100                      200        4000\n",
       "      22>  4300                      200        4200\n",
       "      23>  4500                      200        4400\n",
       "      24>  4700                      200        4600\n",
       "      25>  4900                      200        4800\n",
       "    GRID (G004)\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",
       " MYNEWZAXIS Z (METERS)         25 r   100                  4900                full\n",
       " normal    T\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "\n", "def axis/z=0:5000:200/edges/units=\"meters\" myNewZaxis\n", "show axis/z myNewZaxis\n", "\n", "let newTemp = temp[gz=myNewZaxis] ! @lin is applied by default\n", "show grid newTemp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let make a time regredding to pass from a monthly variable to a yearly variable (read http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/Grids-Regions/GRIDS#_VPID_199)\n", "\n", "The @AVE—averaging should be used here by typing:\n", "\n", " let uwndYearly = uwnd[gt=yearsAxis@ave]\n", "\n", "Computes the length-weighted average of all points on the source grid that lie partly or completely within each grid cell of the destination grid. If any portion of a source grid cell containing data overlaps a given destination grid cell, then data from that source cell contributes to the destination cell, weighted by the fraction of the destination cell overlapped by the source cell. The source data are treated as continuous, extending to the edges of the grid cells.\n", "\n", "See the difference with other regriddings based on @lin or @nrst" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    GRID GDN1\n",
       " name       axis              # pts   start                end                 subset\n",
       " FNOCX     LONGITUDE          144mr   20E                  17.5E(377.5)        full\n",
       " FNOCY     LATITUDE            73 r   90S                  90N                 full\n",
       " normal    Z\n",
       " TIME      TIME               132 r   16-JAN-1982 20:00    17-DEC-1992 03:30   full\n",
       " name       axis              # pts   start                end\n",
       " YEARSAXIS TIME                11 r   02-JUL-1982 14:54    02-JUL-1992 01:06\n",
       "T0 = 15-JAN-1901\n",
       "   Axis span (to cell edges) = 11\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret\n", "\n", "ppl color 6, 70,70,70\n", "\n", "cancel data/all\n", "use monthly_navy_winds\n", "\n", "show grid uwnd\n", "\n", "def axis/t=\"01-JAN-1982\":\"31-DEC-1992\":1/edges/units=year yearsAxis\n", "show axis yearsAxis\n", "\n", "let uwndYearly = uwnd[gt=yearsAxis@ave]\n", "let uwndYearly2 = uwnd[gt=yearsAxis@lin]\n", "let uwndYearly3 = uwnd[gt=yearsAxis@nrst]\n", "plot/grat=(dash, color=6)/line/symb uwnd[i=@ave,j=@ave], uwndYearly[i=@ave,j=@ave], uwndYearly2[i=@ave,j=@ave], uwndYearly3[i=@ave,j=@ave]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's go further and compute the 12-month climatology from the initial monthly variable" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 800,800\n", "\n", "ppl color 6, 70,70,70\n", "\n", "cancel data/all\n", "use monthly_navy_winds\n", "\n", "let uwnd_clim = uwnd[gt=month_reg@mod]\n", "\n", "def viewport/x=0:1/y=0.66:1 third1; set viewport third1\n", "go margins 0.4 0.6 1 1 ! reduce the margins\n", "plot/nolab/grat=(dash, color=6)/line/symb uwnd[i=@ave,j=@ave]\n", "\n", "def viewport/x=0:1/y=0.33:0.66 third2; set viewport third2\n", "go margins 0.4 0.6 1 1\n", "plot/nolab/grat=(dash, color=6)/line/symb uwnd_clim[i=@ave,j=@ave]\n", "\n", "def viewport/x=0:1/y=0:0.33 third3; set viewport third3\n", "go margins 0.4 0.6 1 1\n", "plot/nolab/grat=(dash, color=6)/T=\"01-JAN-1982\":\"31-DEC-1992\" uwnd[i=@ave,j=@ave], uwnd_clim[i=@ave,j=@ave]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now plot the difference between climatology and the variable by filling in red when it is over 0 and in blue when lower." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 800,400\n", "\n", "ppl color 6, 70,70,70\n", "\n", "cancel data/all\n", "use monthly_navy_winds\n", "\n", "let uwnd_clim = uwnd[gt=month_reg@mod]\n", "\n", "set viewport upper\n", "go margins 0.4 0.6 1 1\n", "plot/nolab/grat=(dash, color=6)/T=\"01-JAN-1982\":\"31-DEC-1992\" uwnd[i=@ave,j=@ave], uwnd_clim[i=@ave,j=@ave]\n", "\n", "set viewport lower\n", "go margins 0.4 0.6 1 1\n", "\n", "let a0 = uwnd[i=@ave,j=@ave]-uwnd_clim[i=@ave,j=@ave,T=\"01-JAN-1982\":\"31-DEC-1992\"]\n", "\n", "! regrid on a fine grid to have fills nicely done\n", "def axis/t=\"01-JAN-1982\":\"31-DEC-1992\":1/edges/units=days timeDays\n", "let a = a0[gt=timeDays]\n", "\n", "let a_pos = if a ge 0 then a else 0\n", "let a_neg = if a le 0 then a else 0\n", "plot/nolab/grat=(dash, color=6) a\n", "\n", "go fill_between poly/nolab/over/palette=red a_pos timeDays\n", "go fill_between poly/nolab/over/palette=blue a_neg timeDays\n", "\n", "plot/nolab/over/line/color=1/thick=2 a\n", "plot/nolab/over/line/color=1/dash=(0.1,0.1,0.1,0.1)/thick=2 a*0\n", "\n", "!frame/file=fill_between.pdf" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Missing values

\n", "\n", "ferret takes care of missing values.\n", "\n", "This can be seen with the stat command" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
 \n",
       "             ZONAL WIND\n",
       "             LONGITUDE: 18.8E to 18.8E(378.8)\n",
       "             LATITUDE: 91.2S to 91.2N\n",
       "             Z:  N/A\n",
       "             TIME: 01-JAN-1982 14:45 to 01-JAN-1993 08:45\n",
       "             E:  N/A\n",
       "             F:  N/A\n",
       "             DATA SET: /opt/ferret_dsets/data/monthly_navy_winds.cdf\n",
       " \n",
       " Total # of data points: 1387584 (144*73*1*132*1*1)\n",
       " # flagged as bad  data: 0\n",
       " Minimum value: -25.548\n",
       " Maximum value: 18.545\n",
       " Mean    value: 0.026499 (unweighted average)\n",
       " Standard deviation: 4.4884\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret \n", "\n", "stat uwnd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can replace missing values from the nearest point by using the @FNR (pour fill nearest) or more simply replace them by a choosen value. " ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
             X: 0.5 to 5.5\n",
       " Column  1: A is {23,45,,12,90}\n",
       " Column  2: EX#2 is MISSING(A,0)\n",
       "             A   EX#2\n",
       "1   / 1:  23.00  23.00\n",
       "2   / 2:  45.00  45.00\n",
       "3   / 3:   ....   0.00\n",
       "4   / 4:  12.00  12.00\n",
       "5   / 5:  90.00  90.00\n",
       "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret \n", "let a={23,45,,12,90}\n", "list a, missing(a,0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Save image in file

\n", "\n", "You can save the display as png or pdf by typing the frame command\n", "\n", " yes? shade temp[k=@min] ; go land\n", " yes? frame/file=myImage.png\n", " yes? frame/file=myImage.pdf\n", " \n", "Note that png format is available only with pyferret (and with ferretmagic), use gif format when using ferret." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Locate palettes, scripts

\n", "\n", "Please choose carefully your levels and palette to focus on what you want to highlight.\n", "\n", "You can locate a predefined palette by typing:\n", "\n", " $ Fpalette red\n", "\n", "An interesting proposition have been made to give up the rainbow palette (the default in ferret) by remplacing it by more appropriate ones to better represent your data, easier to read by those with colorblindness, and print well in grey scale. Please read https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html\n", "\n", " $ Fpalette div\n", " \n", "to look to divergente palette.\n", "\n", "Visiting http://matplotlib.org/examples/color/colormaps_reference.html can help to choose the right one." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -q -s 1000,500\n", "\n", "cancel data/all\n", "use monthly_navy_winds\n", "let/title=\"wind module\"/units=\"m/s\" module=(UWND^2+VWND^2)^0.5\n", "\n", "set viewport left\n", "contour/fill/pal=mpl_PSU_plasma/lev=(-INF)(0,12,0.5)(INF) module[l=1] ; go land\n", "\n", "set viewport right\n", "! levels are specified using 20C = 20 levels centered\n", "contour/fill/lev=20C/pal=mpl_Div_BrBG vwnd[l=1] ; go land" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Control color lines

" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%ferret -s 800,800\n", "\n", "cancel mode logo\n", "\n", "! increase the default number of colors (6)\n", "set mode linecolors:20\n", "\n", "cancel data/all\n", "\n", "use monthly_navy_winds\n", "\n", "! keep color black as 1\n", "ppl color 2, 0, 50, 100, 50\n", "ppl color 3, 100, 50, 0, 50\n", "ppl color 4, 80, 0, 80, 50\n", "ppl color 20, 70, 70, 70\n", "\n", "! Define Wind Speed\n", "let WND = (UWND^2 + VWND^2)^0.5\n", "\n", "let/title=\"Wind Speed (global)\" var1 = WND[i=@ave,j=@ave,d=1]\n", "let/title=\"Wind Speed (North Hemisphere)\" var2 = WND[i=@ave,y=0:90@ave,d=1]\n", "let/title=\"Wind Speed (South Hemisphere)\" var3 = WND[i=@ave,y=-90:0@ave,d=1]\n", "\n", "\n", "! plot line(s) will be drawn starting with color 2\n", "plot/color/thick=3/grat=(dash,color=20)/key=title var1, var2, var3\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Scripting

\n", "\n", "ferret is a complete software that can perfeclty be used to build your own library of scripts.\n", "\n", "Remember that with a classic ferret session, a journal is recorded with all your commands. This file named ferret.jnl, once cleaned from your different tries can be run by a simple: \n", "\n", " yes? go monscript.jnl\n", "\n", "You can also generalize the script by adding arguments. Read http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/introduction/GO-FILES#Chapter1-Writing_GO_tools\n", "\n", "\n", "Then pyferret could be used to run your script:\n", "\n", " $ pyferret -nodisplay -script monscript.jnl arg1 arg2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Ready ?

\n", "\n", "" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }