Posts

Showing posts from December, 2021

Fortran: "Hello world!"

FORTRAN: (Found in 1950s, latest version released: 2018) (.F90 is the extension mostly used in modern Fortran scripts) (Fortran is CASE INSENSITIVE ) ( SAVE the below script as " hello.f90" , then COMPILE using " gfortran hello.f90 -o hello ", then RUN the file "hello" as " ./hello ") The script: Program Hello     Print *, "Hello World!" End Program

Python: How to plot grouped bar graph?

The script: (SAVE this below script with ".py" or ".ipynb" extensions) import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import numpy as np sns.set() departure=pd.read_csv('file.csv') departure df = pd.DataFrame(departure, columns = ['year', 'var1', 'var2', 'var3']) print(df) plt.figure(figsize=(9,6)) pos = list(range(len(df['var1']))) width = 0.25 N=35 ind = np.arange(N) fig, ax = plt.subplots(figsize=(40,15)) plt.bar(pos, df['var1'], width, alpha=0.5, color='#059C1E') plt.bar([p + width for p in pos], df['var2'], width, alpha=0.5, color='#1032E0') plt.bar([p + width*2 for p in pos], df['var3'], width, alpha=0.5, color='#000000') ax.set_ylabel('Y-AXIS',fontweight='bold') plt.xlabel('Year', fontweight='bold') ax.set_title('Title') plt.xlim(min(pos)-width, max(pos)+width*4) plt.ylim([-42, max(df['var1'...

GrADS: How to draw a Hovmoller (or Hovmuller) diagram?

Image
Output image The script: *********HOVMOLLER********** 'reinit' 'set display color white' 'c' 'set grads off' 'set grid off' 'run colors.gs' 'set xlint 6' 'set xlopts 1 6 0.13' 'set ylopts 1 6 0.13' 'sdfopen file9.nc' 'set t 1 68' 'define plon1=ave(uas,lon=70,lon=90)' 'set lat 0 37' 'set grads off' 'set clab off' 'set x 1' 'set ylabs 1989 | 1990 | 1991 | 1992 | 1993 | 1994 | 1995 | 1996 | 1997 | 1998 | 1999 | 2000 | 2001 | 2002 | 2003 | 2004 | 2005 ' *'set parea 0.7 3.7 0.81 7.81' 'set display color white' 'set gxout shaded' 'color 0 10 1 -kind grainbow' 'd plon1' 'run cbar' *'xcbar 0.69 6.97 0.35 0.51 -fw 0.08 -fh 0.09 -fs 1 -line on -edge triangle -dir h' 'set string 1 l 6' 'set strsiz 0.11' 'draw title Hovmoller diagram' *'draw string 0.7 7.93 ERA' 'printim ou...

GrADS: Some useful prerequisite scripts - vec.gs

Save the below script as " vec.gs " in a text editor: The script: function vec (args) variable=subwrd(args,1) autopl  = 'on' scl = 0 strlast='' hdsz=0.15 * examine options are set or not n=2 while(n<10000) idx=subwrd(args,n) opt=subwrd(args,n+1) if(idx='');break;endif if(idx='-P')  cxleft =subwrd(args,n+1)  cylow  =subwrd(args,n+2)  autopl ='off'  n=n+3 endif if(idx='-SCL')  size=subwrd(args,n+1)  magni=subwrd(args,n+2)  scl=1  n=n+3 endif if(idx='-SL')  strlast=subwrd(args,n+1)  n=n+2 endif if(idx='-HDSZ')  hdsz=subwrd(args,n+1)  n=n+2 endif endwhile *** set default arrow labeling off 'set arrlab on' if(autopl='off');'set arrlab off';endif *** set arrow scale if(scl=1); 'set arrscl 'size ' 'magni;endif *** draw the vector 'display 'variable *** draw the vector arrow label if(autopl='off')  if(scl=0)   say '!! CANNOT PLOT Arrow Label: Set allow scale...

GrADS: How to plot a wind circulation pattern at a particular atmospheric pressure level with "u" and "v" wind vector components?

Image
The script: ********wind_at_870hPa****for_2007JJAS***** 'reinit' *'set display color white' *'c' 'set xlopts 4 8 .2' 'set ylopts 3 6 .2' 'set xlint 6' 'set ylint 5' *'set grads off' 'set grid off' 'run colors' ***************** 'open file8.nc.ctl' 'set z 18' *'set mpdset rupres' *'set cthick 3' *'set ccolor 1' *'set mpt 0 15 1 1' *'set csmooth on' *'set arrowhead 0.03' 'define uavg=ave(ua,t=101,t=104)' 'define vavg=ave(va,t=101,t=104)' *'color 1 19 3 -kind rainbow' *'set clevs  2 4 6 8 10 12 14 16' *'set ccols 0 48 47 46 45 44 43 42 41' 'define magw=mag(uavg,vavg)' *'set ccolor 1' 'set gxout shaded' 'd magw' 'run vec.gs skip(uavg,10);vavg -SCL 0.25 15 -P 7.7 9' 'run cbarn' 'draw title Wind at 870hPa for 2007 JJAS' *'printim output.eps' 'p...

GrADS: Plotting multiple variables and panelling of figures (Multiple plots on a single page)

Image
Output image The script: (For this script to be run, you have to have " rupres " file in your present working directory as a prerequisite ) 'reinit' *'set display color white' *'c' 'set grads off' 'set grid off' 'set xlint 7' 'set ylint 5' 'set xlopts 1 6 0.13' 'set ylopts 1 6 0.13' 'run colors.gs' 'run basemap.gs' 'set mpdset rupres' *************temperature**************** 'set parea 2 6 6 10' 'open file6.nc.ctl' 'set lon 60 104' 'set lat 5 37' 'set gxout shaded' 'set clevs -5 0 5 10 15 20 25 30 35' 'set ccols 45 46 51 52 53 54 55 56 57 58' 'd ts-273.15' 'run cbarn 0.85 8 6.5 8' 'basemap o 0 1' **************relative_humidity******************** 'set parea 2 6 1 5' 'open file7.nc.ctl' 'define hum=ave(rh,t=101,t=104)' 'set lon 60 104' 'set lat 5 37' 'set gxou...

GrADS: Some useful prerequisite scripts - basemap.gs

Save the below script as " basemap.gs " in a text editor: The script: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * basemap.gs * * This script overlays a land or ocean mask that exactly matches  * the coastal outlines.  *  * Usage:  *   basemap L(and)/O(cean) <fill_color> <outline_color> <L(owres)/M(res)/H(ires)>' * * Example: *   ga-> set mpdset mres *   ga-> display sst *   ga-> basemap L 7 2 M *  * Usage Notes:  * * The default values for the optional arguments are:  *   fill_color 15, outline_color 0, and lowres.  * * The land and ocean masks are composed of hundreds of  * polygons that are specified in accompanying ascii files.  * The ascii files must be downloaded from the GrADS script library: *   ftp://grads.iges.org/grads/scripts/lpoly_lowres.asc *   ftp://grads.iges.org/grads/scripts/lpoly_mres.a...

GrADS: A spatial plot of temperature

Image
Output image The script: 'reinit' *'set display color white' *'c' 'set grads off' 'set grid off' 'set xlint 7' 'set ylint 5' 'set xlopts 2 6 0.13' 'set ylopts 2 6 0.13' 'run colors.gs' 'run basemap.gs' 'sdfopen file5.nc' 'set lon 60 104' 'set lat 5 37' 'set gxout shaded' 'set clevs -5 0 5 10 15 20 25 30 35' 'set ccols 45 46 51 52 53 54 55 56 57 58' 'd tas-273.15' 'run cbarn' 'basemap o 0 1' *'set string 1 l 7' *'set strsiz 0.12' *'draw string 0.7 10 Temperature(JJAS)-2002' 'draw title TEMPERATURE-2002' *'gxprint output.png x1200 y1600 white' 'printim output.pdf'

GrADS: Some formatting with a spatial plot (viz., axes' tick colouring, tick spacing, etc.)

Image
Output image The script: 'reinit' *'set display color white' *'c' 'set grads off' 'set grid off' 'set xlint 7' 'set ylint 5' 'set xlopts 2 6 0.13' 'set ylopts 2 6 0.13' 'run colors.gs' 'sdfopen file4.nc' 'set gxout shaded' 'set clevs 6 9 12 18' 'set ccols 55 53 45 44 42' 'd rf' 'run cbarn' 'set string 1 l 7' 'set strsiz 0.12' 'draw string 0.7 10 Rainfall(JJAS)-1994' *'gxprint output.png x1200 y1600 white' *'draw title RAINFALL-1994' 'printim output.pdf'

GrADS: How to save an output image in "EPS" format?

Image
The output image here is for a specific selected area as given in the below script (lat 5 21, lon 69 81) The script: (Here in GrADS commenting is done by '*') 'reinit' *'set display color white' *'c' 'run colors.gs' 'sdfopen  file3.nc' 'set lon 69 81' 'set lat 5 21' 'set gxout shaded' 'set clevs 6 9 12 18' 'set ccols 55 53 45 44 42' 'd rf' 'run cbarn' 'draw title RAINFALL-1994' 'printim output.eps'

GrADS: Some useful prerequisite scripts - colors.gs

Save  the below script as " colors.gs " in a text editor: The script: 'set grads off' 'set gxout shaded' * brown-green pallete *brown 'set rgb 21 255 255 255' 'set rgb 22 125 130 105' 'set rgb 23 130 145 120' 'set rgb 24 140 155 135' 'set rgb 25 160 165 150' 'set rgb 26 180 175 165' 'set rgb 27 195 185 180' 'set rgb 28 210 200 195' 'set rgb 70 225 220 210' 'set rgb 71 240 235 225' 'set rgb 72 245 240 235' 'set rgb 73 250 245 240' *green 'set rgb 30 235 250 235' 'set rgb 31 220 235 220' 'set rgb 32 205 215 205' 'set rgb 33 185 195 180' 'set rgb 34 170 175 160' 'set rgb 35 155 160 140' 'set rgb 36 135 145 115' 'set rgb 37 115 125 100' 'set rgb 38 95 105 85' 'set rgb 39 75 90 70' 'set rgb 29 55 70 50' * blue-red pallete *blue 'set rgb 40  0  0 50' 'set rgb 41  0  0 100...

GrADS: How to define a particular colour scale by importing "colors.gs" script?

Image
Output image The script: 'reinit' 'set display color black' 'c' 'set grads off' 'set grid off' 'run colors.gs' 'sdfopen file2.nc' 'set gxout shaded' 'set clevs 6 9 12 18' 'set ccols 55 53 45 44 42' 'd rf' 'run cbarn' 'draw title RAINFALL-1994' 'printim output.pdf'

GrADS: Some useful prerequisite scripts - cbarn.gs

Save the below script as " cbarn.gs " in a text editor: The script: * *  Script to plot a colorbar * *  The script will assume a colorbar is wanted even if there is  *  not room -- it will plot on the side or the bottom if there is *  room in either place, otherwise it will plot along the bottom and *  overlay labels there if any.  This can be dealt with via  *  the 'set parea' command.  In version 2 the default parea will *  be changed, but we want to guarantee upward compatibility in *  sub-releases. * * * modifications by mike fiorino 940614 * * - the extreme colors are plotted as triangles * - the colors are boxed in white * - input arguments in during a run execution: *  * run cbarn sf vert xmid ymid * * sf   - scale the whole bar 1.0 = original 0.5 half the size, etc. * vert - 0 FORCES a horizontal bar = 1 a vertical bar * xmid - the x position on the virtual page the center the bar * ymi...

GrADS: How to plot rainfall using a NetCDF data?

Image
Output image  The script: 'reinit' 'set display color white' 'c' 'sdfopen file1.nc' 'set gxout shaded' 'd rf' 'run cbarn' 'draw title IMD Obs Rain 1994' 'printim output.png'