GrADS+code

=Here we (together) build the code for GrADS to do the homework.=


 * In order to run this code, you need to copy it into another file and save the file as //filename//.gs (the file extension for GrADS script files). To run it in the GrADS command window, either type '//filename'// or 'run //filename//.gs'
 * I will fill in the fields with specific homework information once I've downloaded the dated and completed the assignment, but in case you need to get started, here are some basics.


 * Some basic information about plotting in GrADS. GrADS default is to plot by contours in a rainbow of colors, with purple for low values and hot pink with high values. To change the output type, 'set gxout shaded' for example to get filled in contours. You can see the Documentations Index for a full list of settings. Colorbars and contour intervals can all easily be defined to whatever you want, please see 'set clevs' and 'set ccols' in the Index. ([]) To display the colorbar, 'cbar' or 'cbarn'.


 * Yes, it really is this easy in GrADS!

Data Import
'sdfopen filename.nc'
 * To read in netCDF files.

Averaging over months & plotting result R(lat,lon)
'T_timemean =ave(//var//,t=1,t=2)' 'd T_timemean'

Averaging over longitude & plotting result R(lat,t)
'T_lonmean =ave(//var//,lon=0,lon=359)' 'd T_lonmean' ===Averaging over latitude -- WEIGHTED BY GRID CELL AREA --> R(lon,t)=== 'T_latmean =ave(//var//,lat=-90,lat=90)' 'd T_latmean'

Averaging over latitude and longitude: R(t)
'T_globalmean =aave(//var//,lon=0,lon=359,lat=-90,lat=90)' 'd T_globalmean'

Averaging squared value
'T_globalmean2=aave(//var//*//var//,lon=0,lon=359,lat=-90,lat=90)' 'meansquare =ave(T_globalmean2,t=1,t=2)'

Variance = meansquare - mean^2
'mean=ave(T_globalmean,t=1,t=2)' 'variance=meansquare-(mean*mean)' 'd variance'

Stdev = sqrt(variance)
'stdev=sqrt(variance)' 'd stdev'

For this particular HW, here is an example code (Angela Colbert version):

'reinit' 'set display color white' 'c'
 * To restart the program
 * To change default settings to have a white background/black text


 * QUESTION 1: Files are read in as needed through the questions. 'sdfopen'

'sdfopen precip.mon.ltm.nc' 'set t 1 12'
 * QUESTION 2
 * To include all times, set t 1 12, default is t set to time 1 only

'precipx=ave(precip,lon=0,lon=360)'
 * Average by longitude

'set lon -90' 'set gxout shaded' 'set xyrev on' 'set clevs 0 1 2 3 4 5 6 7 8 9' 'set grads off' 'd precipx' 'set gxout contour' 'set clevs 0 1 2 3 4 5 6 7 8 9' 'd precipx' 'draw title Preciption in mm/day (Averaged over Longitude)' 'draw ylab Latitude' 'draw xlab Month' 'printim precipx.jpeg' 'c'
 * Need to set lon to something to plot lat vs time, but it won't matter which one you choose
 * To reverse the axes so lat is y and time is x
 * Set contour levels to keep consistency
 * To remove the grads logo and time at the bottom

'set gxout shaded' 'set xyrev on' 'set clevs 0 1 2 3 4 5 6 7 8 9' 'set grads off' 'd precip' 'set gxout contour' 'set clevs 0 1 2 3 4 5 6 7 8 9' 'd precip' 'draw title Preciption in mm/day (at 90W)' 'draw ylab Latitude' 'draw xlab Month' 'printim precip90.jpeg' 'c' 'close 1'
 * Have to set axis shift and clevs everytime, cancels once you clear the screen
 * Since, lon is already set to -90, then just need to display unaveraged precip
 * Since precip is on a different grid (72, not 73), need to close precip file
 * before opening the new file)

'sdfopen vwnd.mon.ltm.nc' 'set t 1 12' 'vwndx=ave(vwnd,lon=0,lon=360)' 'set lon -90' 'set gxout shaded' 'set xyrev on' 'set clevs -4 -3 -2 -1 0 1 2 3 4' 'set grads off' 'd vwndx' 'set gxout contour' 'set clevs -4 -3 -2 -1 0 1 2 3 4' 'd vwndx' 'draw title Meridional printimnd in m/s (Averaged over Longitude)' 'draw ylab Latitude' 'draw xlab Month' 'printim vwndx.jpeg' 'c'
 * Open meridional printimnds file and follow same pattern as before

'set gxout shaded' 'set xyrev on' 'set clevs -4 -3 -2 -1 0 1 2 3 4' 'set grads off' 'd vwnd' 'set gxout contour' 'set clevs -4 -3 -2 -1 0 1 2 3 4' 'd vwnd' 'draw title Meridional printimnd in m/s (at 90W)' 'draw ylab Latitude' 'draw xlab Month' 'printim vwnd90.jpeg' 'c' 'close 1'

'sdfopen air.mon.ltm.nc' 'set t 1 12' 'airxy=aave(air,lon=0,lon=360,lat=-90,lat=90)' 'set lat 25' 'set lon -90' 'set grads off' 'd airxy' 'draw title Global Mean Temperature in Celcius' 'draw ylab Degrees Celcius' 'draw xlab Month' 'printim airxy.jpeg' 'c' 'close 1'
 * QUESTION 3
 * Note:aave requires lon boundaries then lat (x then y)
 * To get time plot, need to set lat and lon to something, since averaged it won't
 * matter what values

'sdfopen precip.mon.ltm.nc' 'precipt=ave(precip,t=1,t=12)' 'precipvar=(sum((precip-precipt)*(precip-precipt),t=1,t=12))/12' 'precipsd=sqrt(precipvar)' 'precipf=precipsd/precipt' 'set gxout shaded' 'set grads off' 'd precipf' 'cbarn' 'draw title Monsoonal Climate (Precipitation)' 'printim precipmonsoon.jpeg' 'close 1'
 * QUESTION 4
 * First calculate time average
 * Then variance, where (sum(x-xbar)^2)/n(time)
 * Squareroot to find the standard deviation
 * Last, divide by time average
 * Note: I did not change the color bar or map resolution, but you can easily.

'sdfopen air.mon.ltm.nc' 'airt=ave(air,t=1,t=12)' 'airtxy=aave(airt,lon=0,lon=360,lat=-90,lat=90)'
 * QUESTION 5
 * Time average and global average of air

'airt2=ave(air*air,t=1,t=12)' 'airtxy2=aave(airt2,lon=0,lon=360,lat=-90,lat=90)'
 * Time average and global average of air^2

'airvar=airtxy2-(airtxy*airtxy)' 'airsd=sqrt(airvar)' 'd airsd'
 * Calculate variance and standard deviation
 * Note: since this is just a number value, you printimll need to type it into the
 * command window yourself to see the value.