{ "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": [ "
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": [ "
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": [ "
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": [ "
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": [ "
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", " 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": [ "