<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Dear NCL Users
<br>
<br>
I am wanting to create 1 plot of averaged spatial correlations.<br>
I currently have 40 global spatial correlation plots but would like to average those all out to 1 global plot with the overall average spatial correlations at each gridpoint.<br>
<br>
I am not sure whether to use the average function or to sum them up first and divide by 40.<br>
<br>
Your help would be very much appreciated.<br>
<br>
Below is the code I am trying to create this average plot from.<br>
<br>
Kindest Regards<br>
Melissa<br>
<br>
; ==============================================================<br>
; eof_1.ncl<br>
; ==============================================================<br>
<br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"<br>
<br>
begin<br>
; ==============================================================<br>
; User defined parameters that specify region of globe and<br>
; ==============================================================<br>
latS = -40.<br>
latN = 0. <br>
lonL = 10.<br>
lonR = 60.<br>
<br>
yrStrt = 1975<br>
yrLast = 2004<br>
<br>
season = "DJF" ; choose Dec-Jan-Feb seasonal mean<br>
<br>
neof = 1 ; number of EOFs<br>
optEOF = True <br>
optEOF@jopt = 0 ; This is the default; most commonly used; no need to specify.<br>
optETS = False<br>
<br>
model = (/"ACCESS1-0","ACCESS1-3","bcc-csm1-1","bcc-csm1-1-m","BNU-ESM","CanESM2","CCSM4","CESM1-BGC","CESM1-CAM5","CESM1-FASTCHEM","CESM1-WACCM","CMCC-CESM","CMCC-CM","CMCC-CMS","CNRM-CM5","CSIRO-Mk3-6-0","EC-EARTH","FGOALS-g2","GFDL-CM3","GFDL-ESM2G","GFDL-ESM2M","GISS-E2-H","GISS-E2-H-CC","GISS-E2-R","GISS-E2-R-CC","HadGEM2-AO","HadGEM2-CC","HadGEM2-ES","inmcm4","IPSL-CM5A-LR","IPSL-CM5A-MR","IPSL-CM5B-LR","MIROC5","MIROC-ESM","MIROC-ESM-CHEM","MPI-ESM-LR","MPI-ESM-MR","MPI-ESM-P","MRI-CGCM3","NorESM1-M","NorESM1-ME"/)<br>
<br>
<br>
wks = gsn_open_wks("X11","ALL_40_MMM_Eof_cor_SST") ; specifies a plot<br>
gsn_define_colormap(wks,"ncl_default") ; choose color map<br>
plot = new (dimsizes(model),"graphic")<br>
do gg = 0,dimsizes(model)-1<br>
<br>
; read in model data<br>
<br>
in=addfile("/mnt/geog/ml382/melphd/eof_sicz/eof90models/pr_"+model(gg)+"_eof_DJF_Anom.nc","r")
<br>
<br>
lat = in->lat<br>
lon = in->lon<br>
time = in->time<br>
YYYY = cd_calendar(time,-1)/100 ; entire file<br>
iYYYY = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)<br>
<br>
if((gg.eq.19) .or. (gg.eq.20)) then ;(gg.eq.17) .or. <br>
PR = in->pr(iYYYY,:,:)<br>
else<br>
PR = in->pr(iYYYY,0,:,:)<br>
end if<br>
; <br>
nyrs = dimsizes(PR&time)<br>
; =================================================================<br>
; normalize data at each gridpoint by local standard deviation at each grid pt<br>
; =================================================================<br>
PR = dim_standardize_n(PR,1,0)<br>
<br>
; =================================================================<br>
; Reorder (lat,lon,time) the *weighted* input data<br>
; Access the area of interest via coordinate subscripting<br>
; =================================================================<br>
x = PR({lat|latS:latN},{lon|lonL:lonR},time|:)<br>
<br>
eof = eofunc_Wrap(x, neof, optEOF) <br>
eof_ts = eofunc_ts_Wrap (x, eof, optEOF)<br>
<br>
printVarSummary( eof ) ; examine EOF variables<br>
printVarSummary( eof_ts )<br>
<br>
; =================================================================<br>
; Extract the YYYYMM from the time coordinate <br>
; associated with eof_ts [same as SLP&time] <br>
; =================================================================<br>
<br>
yyyymm = cd_calendar(eof_ts&time,-2)/100 <br>
<br>
; ==============================================================<br>
; Open the file: Read only the user specified period<br>
; ==============================================================<br>
s = addfile ("/mnt/nfs2/geog/ml382/melphd/global/sstmodel90/tos_Omon_"+model(gg)+"_historical_safrica_climDJF.nc", "r")
<br>
<br>
<br>
TIME1 = s->time<br>
YYYYZ = cd_calendar(TIME1,-1)/100 ; entire file<br>
iYYYYZ = ind(YYYYZ.ge.yrStrt .and. YYYYZ.le.yrLast)<br>
<br>
sst = s->tos(iYYYYZ,:,:)<br>
printVarSummary(sst) <br>
<br>
sst1 =sst(:,:,:)<br>
<br>
<br>
printVarSummary(eof_ts) ; variable overview<br>
eof1 = eof_ts(0,:)<br>
<br>
sst1 = lonFlip(sst1)<br>
; =================================================================<br>
; Reorder (latitude,longitude,time) the *weighted* input data<br>
; Access the area of interest via coordinate subscripting<br>
; =================================================================<br>
<br>
q = eof_ts(0,:)<br>
<br>
y = sst1(lat|:,lon|:,time|:)<br>
<br>
y&lat@units = "degrees_north"<br>
y&lon@units = "degrees_east"<br>
<br>
x&lat@units = "degrees_north"<br>
x&lon@units = "degrees_east"<br>
<br>
printVarSummary(q)<br>
printVarSummary(y)<br>
<br>
<br>
ccr = escorc(q, y)<br>
<br>
printVarSummary(ccr)<br>
<br>
ccr!0 = "lat" ; name dimensions <br>
ccr!1 = "lon" <br>
ccr&lat = y&lat ; assign coordinate values and <br>
ccr&lon = y&lon ; units attributes <br>
<br>
printVarSummary(ccr)<br>
<br>
<br>
;ensccrdimavg = dim_avg_Wrap( ccr(lat|:, lon|:)<br>
ensccr = new((/dimsizes(lat),dimsizes(lon)/), typeof(ccr))<br>
;ensccr!0="lat"<br>
;ensccr&lat=lat<br>
;ensccr!1="lon"<br>
;ensccr&lon=lon<br>
;ensccr(gg) = ensccrsum<br>
<br>
;ensccrsum(gg) = sum( ccr(lat|:, lon|: ))<br>
;ensccr = ensccrsum / 40<br>
<br>
ensccr = dim_avg_n_Wrap(ccr,0)<br>
<br>
<br>
ensccr!0 = "lat" ; name dimensions <br>
ensccr!1 = "lon" <br>
ensccr&lat = lat ; assign coordinate values and <br>
ensccr&lon = lon ; units attributes <br>
<br>
printVarSummary(ensccr)<br>
;============================================================<br>
; PLOT<br>
;============================================================<br>
<br>
<br>
;*******************************************<br>
; first plot<br>
;*******************************************<br>
<br>
rescn = True<br>
rescn@cnFillOn = True <br>
rescn@cnLinesOn = False ; True is default <br>
rescn@gsnDraw = False ; don't draw<br>
rescn@gsnFrame = False ; don't advance frame<br>
rescn@cnLineLabelsOn = False ; True is default<br>
rescn@lbLabelBarOn = False ; turn off individual lb's<br>
<br>
rescn@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels<br>
rescn@cnMinLevelValF = -0.5 ; set min contour level<br>
rescn@cnMaxLevelValF = 0.5 ; set max contour level<br>
rescn@cnLevelSpacingF = 0.1 ; set contour spacing<br>
<br>
;rescn@lbOrientation = "Vertical" ; vertical label bar<br>
rescn@tiMainString = ""+model(gg)+""<br>
;---This resource defaults to True in NCL V6.1.0<br>
rescn@lbLabelAutoStride = True ; optimal label stride<br>
<br>
rescn@gsnSpreadColors = True ; use full range of colors<br>
rescn@mpCenterLonF = 180. ; center plot at 180<br>
rescn@lbLabelFontHeightF = 0.015 <br>
<br>
rescn@gsnAddCyclic = True <br>
; reverse the first two colors<br>
setvalues wks <br>
"wkColorMap" : "ncl_default" <br>
"wkForegroundColor" : (/0.,0.,0./) <br>
"wkBackgroundColor" : (/1.,1.,1./) <br>
end setvalues<br>
<br>
<br>
end do<br>
<br>
plot = gsn_csm_contour_map(wks,ensccr,rescn)<br>
<br>
<br>
draw(plot)<br>
frame(wks)<br>
<br>
end<br>
<br>
<br>
</div>
</body>
</html>