overlaying slp contours and wind vectors?

From: Ed Martino <Ed.Martino_at_nyahnyahspammersnyahnyah>
Date: Sat Jan 08 2011 - 02:00:04 MST

Hi

I am a new user working with monthly slp and surface wind from NCEP
reanalysis netcdf data. I would like to plot composite anomalies for
both slp and surface wind on one map, as contour and vectors
respectively. I have calculated the anomalies for both slp and wind and
can plot either one as individual maps but cannot get the 'overlay'
function to plot slp and wind together. I suspect I am using the
overlay function incorrectly and would appreciate any suggestions. My
code is copied below.

Thanks

Ed

**** NCL CODE ****

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin
; open netcdf files
slp_file=addfile("slp.mon.mean.nc","r")
u_file=addfile("uwnd.mon.mean.nc", "r")
v_file=addfile("vwnd.mon.mean.nc", "r")

;NOTE the wind and slp files are both monthly mean files
;from the NCEP Reanalysis files thus no time/date conversions necessary

time=slp_file->time ;; read the variables from files
slp=slp_file->slp
slat=slp_file->lat
slon=slp_file->lon

u=u_file->uwnd
ulat=u_file->lat
ulon=u_file->lon

v=v_file->vwnd
vlat=v_file->lat
vlon=v_file->lon

utc_date = ut_calendar(time(12), -5) ;; use "ut_calender" to check
the date in year, month,
print(utc_date) ;; day format, given the the
index of the "time" variable.

; first calculate all winds

slp1966=dim_avg_n(slp(215:221,:,:),0) ;; average the Dec-June slp for
each year of interest
slp1967=dim_avg_n(slp(227:233,:,:),0)
slp1968=dim_avg_n(slp(239:245,:,:),0)
slp1969=dim_avg_n(slp(251:257,:,:),0)
slp1970=dim_avg_n(slp(263:269,:,:),0) ;; using the "dim_avg_n" function
slp1971=dim_avg_n(slp(275:281,:,:),0)
slp1972=dim_avg_n(slp(287:293,:,:),0)
slp1973=dim_avg_n(slp(299:305,:,:),0)
slp1974=dim_avg_n(slp(311:317,:,:),0)
slp1975=dim_avg_n(slp(323:329,:,:),0)
slp1976=dim_avg_n(slp(335:341,:,:),0)
slp1977=dim_avg_n(slp(347:353,:,:),0)
slp1978=dim_avg_n(slp(359:365,:,:),0)
slp1979=dim_avg_n(slp(371:377,:,:),0)
slp1980=dim_avg_n(slp(383:389,:,:),0)
slp1981=dim_avg_n(slp(395:401,:,:),0)
slp1982=dim_avg_n(slp(407:413,:,:),0)
slp1983=dim_avg_n(slp(419:425,:,:),0)
slp1984=dim_avg_n(slp(431:437,:,:),0)
slp1985=dim_avg_n(slp(443:449,:,:),0)
slp1986=dim_avg_n(slp(455:461,:,:),0)
slp1987=dim_avg_n(slp(467:473,:,:),0)
slp1988=dim_avg_n(slp(479:485,:,:),0)
slp1989=dim_avg_n(slp(491:497,:,:),0)
slp1990=dim_avg_n(slp(503:509,:,:),0)
slp1991=dim_avg_n(slp(515:521,:,:),0)
slp1992=dim_avg_n(slp(527:533,:,:),0)
slp1993=dim_avg_n(slp(539:545,:,:),0) ;; averaging months for all years
slp1994=dim_avg_n(slp(551:557,:,:),0) ;; for anomaly calculation
slp1995=dim_avg_n(slp(563:569,:,:),0)
slp1996=dim_avg_n(slp(575:581,:,:),0)
slp1997=dim_avg_n(slp(587:593,:,:),0)
slp1998=dim_avg_n(slp(599:605,:,:),0)
slp1999=dim_avg_n(slp(611:617,:,:),0)
slp2000=dim_avg_n(slp(623:629,:,:),0)
slp2001=dim_avg_n(slp(635:641,:,:),0)
slp2002=dim_avg_n(slp(647:653,:,:),0)
slp2003=dim_avg_n(slp(659:665,:,:),0)
slp2004=dim_avg_n(slp(671:677,:,:),0)
slp2005=dim_avg_n(slp(683:689,:,:),0)

u1966=dim_avg_n(u(215:221,:,:),0) ;; average the Dec-June u for each
year of interest
u1967=dim_avg_n(u(227:233,:,:),0)
u1968=dim_avg_n(u(239:245,:,:),0)
u1969=dim_avg_n(u(251:257,:,:),0)
u1970=dim_avg_n(u(263:269,:,:),0) ;; using the "dim_avg_n" function
u1971=dim_avg_n(u(275:281,:,:),0)
u1972=dim_avg_n(u(287:293,:,:),0)
u1973=dim_avg_n(u(299:305,:,:),0)
u1974=dim_avg_n(u(311:317,:,:),0)
u1975=dim_avg_n(u(323:329,:,:),0)
u1976=dim_avg_n(u(335:341,:,:),0)
u1977=dim_avg_n(u(347:353,:,:),0)
u1978=dim_avg_n(u(359:365,:,:),0)
u1979=dim_avg_n(u(371:377,:,:),0)
u1980=dim_avg_n(u(383:389,:,:),0)
u1981=dim_avg_n(u(395:401,:,:),0)
u1982=dim_avg_n(u(407:413,:,:),0)
u1983=dim_avg_n(u(419:425,:,:),0)
u1984=dim_avg_n(u(431:437,:,:),0)
u1985=dim_avg_n(u(443:449,:,:),0)
u1986=dim_avg_n(u(455:461,:,:),0)
u1987=dim_avg_n(u(467:473,:,:),0)
u1988=dim_avg_n(u(479:485,:,:),0)
u1989=dim_avg_n(u(491:497,:,:),0)
u1990=dim_avg_n(u(503:509,:,:),0)
u1991=dim_avg_n(u(515:521,:,:),0)
u1992=dim_avg_n(u(527:533,:,:),0)
u1993=dim_avg_n(u(539:545,:,:),0) ;; averaging months for all years
u1994=dim_avg_n(u(551:557,:,:),0) ;; for anomaly calculation
u1995=dim_avg_n(u(563:569,:,:),0)
u1996=dim_avg_n(u(575:581,:,:),0)
u1997=dim_avg_n(u(587:593,:,:),0)
u1998=dim_avg_n(u(599:605,:,:),0)
u1999=dim_avg_n(u(611:617,:,:),0)
u2000=dim_avg_n(u(623:629,:,:),0)
u2001=dim_avg_n(u(635:641,:,:),0)
u2002=dim_avg_n(u(647:653,:,:),0)
u2003=dim_avg_n(u(659:665,:,:),0)
u2004=dim_avg_n(u(671:677,:,:),0)
u2005=dim_avg_n(u(683:689,:,:),0)

v1966=dim_avg_n(v(215:221,:,:),0) ;; average the Dec-Jvne v for each
year of interest
v1967=dim_avg_n(v(227:233,:,:),0)
v1968=dim_avg_n(v(239:245,:,:),0)
v1969=dim_avg_n(v(251:257,:,:),0)
v1970=dim_avg_n(v(263:269,:,:),0) ;; vsing the "dim_avg_n" fvnction
v1971=dim_avg_n(v(275:281,:,:),0)
v1972=dim_avg_n(v(287:293,:,:),0)
v1973=dim_avg_n(v(299:305,:,:),0)
v1974=dim_avg_n(v(311:317,:,:),0)
v1975=dim_avg_n(v(323:329,:,:),0)
v1976=dim_avg_n(v(335:341,:,:),0)
v1977=dim_avg_n(v(347:353,:,:),0)
v1978=dim_avg_n(v(359:365,:,:),0)
v1979=dim_avg_n(v(371:377,:,:),0)
v1980=dim_avg_n(v(383:389,:,:),0)
v1981=dim_avg_n(v(395:401,:,:),0)
v1982=dim_avg_n(v(407:413,:,:),0)
v1983=dim_avg_n(v(419:425,:,:),0)
v1984=dim_avg_n(v(431:437,:,:),0)
v1985=dim_avg_n(v(443:449,:,:),0)
v1986=dim_avg_n(v(455:461,:,:),0)
v1987=dim_avg_n(v(467:473,:,:),0)
v1988=dim_avg_n(v(479:485,:,:),0)
v1989=dim_avg_n(v(491:497,:,:),0)
v1990=dim_avg_n(v(503:509,:,:),0)
v1991=dim_avg_n(v(515:521,:,:),0)
v1992=dim_avg_n(v(527:533,:,:),0)
v1993=dim_avg_n(v(539:545,:,:),0) ;; averaging months for all years
v1994=dim_avg_n(v(551:557,:,:),0) ;; for anomaly calcvlation
v1995=dim_avg_n(v(563:569,:,:),0)
v1996=dim_avg_n(v(575:581,:,:),0)
v1997=dim_avg_n(v(587:593,:,:),0)
v1998=dim_avg_n(v(599:605,:,:),0)
v1999=dim_avg_n(v(611:617,:,:),0)
v2000=dim_avg_n(v(623:629,:,:),0)
v2001=dim_avg_n(v(635:641,:,:),0)
v2002=dim_avg_n(v(647:653,:,:),0)
v2003=dim_avg_n(v(659:665,:,:),0)
v2004=dim_avg_n(v(671:677,:,:),0)
v2005=dim_avg_n(v(683:689,:,:),0)

slp_sbass =
(slp1966+slp1970+slp1993+slp1994+slp1996+slp1998+slp1999+slp2000+slp2001+slp2003+slp2005)/11
;; average the Dec-June slp for the 11 years
slp_all_years=(slp1968+slp1969+slp1970+slp1971+slp1972+slp1973+slp1974+slp1975+slp1976+slp1977+slp1978+slp1979+slp1980+slp1981+slp1982+slp1983+slp1984+slp1985+slp1986+slp1987+slp1988+slp1989+slp1990+slp1991+slp1992+slp1993+slp1994+slp1995+slp1996)/29
slp_anom = (slp_sbass - slp_all_years)

u_sbass =
(u1966+u1970+u1993+u1994+u1996+u1998+u1999+u2000+u2001+u2003+u2005)/11
;; average the Dec-June u wind
u_all_years=(u1968+u1969+u1970+u1971+u1972+u1973+u1974+u1975+u1976+u1977+u1978+u1979+u1980+u1981+u1982+u1983+u1984+u1985+u1986+u1987+u1988+u1989+u1990+u1991+u1992+u1993+u1994+u1995+u1996)/29
u_anom=(u_sbass - u_all_years)

v_sbass =
(v1966+v1970+v1993+v1994+v1996+v1998+v1999+v2000+v2001+v2003+v2005)/11
;; average the Dec-Jvne v wind
v_all_years=(v1968+v1969+v1970+v1971+v1972+v1973+v1974+v1975+v1976+v1977+v1978+v1979+v1980+v1981+v1982+v1983+v1984+v1985+v1986+v1987+v1988+v1989+v1990+v1991+v1992+v1993+v1994+v1995+v1996)/29
v_anom=(v_sbass - v_all_years)

slp_anom!0="lat" ;; Assign lat and lon coordinates to slp_anom
to enable plotting
slp_anom!1="lon"
slp_anom&lat=slat
slp_anom&lon=slon

u_anom!0="lat"
u_anom!1="lon"
u_anom&lat=ulat
u_anom&lon=ulon

v_anom!0="lat"
v_anom!1="lon"
v_anom&lat=vlat
v_anom&lon=vlon

wks = gsn_open_wks("X11","slp_anom") ; Open graphic workstation for
xwindow or file output

; ******** Define RGB triplet colors
colors = (/ (/255, 255,255/),
(/5,10,80/),(/5,10,80/),(/5,10,80/),(/5,10,80/),
(/15,10,120/),(/20,30,155/),(/25,55,180/),(/27,58,193/),(/28,60,195/),(/28,65,197/),(/29,75,200/),
\
                  
(/28,78,200/),(/28,80,210/),(/30,85,210/),(/30,95,215/),(/32,100,220/),(/32,102,220/),(/35,105,228/),(/35,115,228/),
\
                  
(/37,125,230/),(/37,135,230/),(/37,155,230/),(/38,165,231/),(/38,175,231/),(/39,180,233/),(/39,185,233/),(/40,190,233/),
\
                  (/50,205,232/),(/120,230,245/),(/180,240,255/), \
                  (/255, 255,255/),(/255, 255,255/), (/255, 255,255/), \
                  (/250,
245,175/),(/250,235,165/),(/245,235,165/),(/245,225,155/),(/244,225,150/),(/244,220,145/),(/243,220,140/),
\
                  (/243,
218,135/),(/242,215,130/),(/242,212,125/),(/240,210,118/),(/240,205,115/),(/238,204,112/),(/238,200,108/),
\
                  (/235,
200,108/),(/235,185,105/),(/225,180,103/),(/225,175,100/),(/220,175,85/),(/220,150,75/),(/215,130,60/),
\
                  
(/215,125,55/),(/215,100,45/),(/218,90,45/),(/218,80,40/),(/210,70,35/),(/200,60,15/),(/190,50,10/),(/190,30,10/),(/190,30,10/),(/190,30,10/),(/190,30,10/)
\
                   /) * 1.0 ; we
multiply by 1.0 to make colors float
colors = colors/255. ;
normalize (required by NCL)

gsn_define_colormap(wks, colors) ;
; gsn_define_colormap(wks,"nrl_sirkes")

res = True
res@cnFillOn = True ; turn on color fill
res@lbLabelAutoStride = True ; automatically choose best stride
res@cnLevelSpacingF = 0.2
res@gsnSpreadColors = True
res@lbLabelAngleF = 45
res@tiMainString = "Dec-Jun SLP anomaly"
res@mpMinLatF = 0.
res@mpMaxLatF = 90.
res@mpMinLonF = -180.
res@mpMaxLonF = 0.
  res@cnLevelSelectionMode = "ExplicitLevels" ; set explicit
contour levels
  res@cnLevels = (/ -1.50,
-1.45,-1.4,-1.35,-1.30,-1.25,-1.20,-1.15,-1.10,-1.05,-1.0,-0.95,-0.90,-0.85,-0.80,-0.75,-0.70,-0.65,-0.60,-0.55,-0.50,-0.45,-0.40,
\
                     -0.35,-0.30,-0.25,-0.20,-0.15,-0.10,-0.05, 0,
0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70,0.75,0.80,0.85,
\
                      
0.90,0.95,1.0,1.05,1.10,1.15,1.20,1.25,1.30,1.35,1.40,1.45, 1.50 /) ;
set levels
res@cnLinesOn = False ; turn off the contour lines
res@cnFillDrawOrder = "Predraw"

; note res2 variable used for vector thus some attributes here only
valid for vectors
res2 = True
res2@mpMinLatF = 0.
res2@mpMaxLatF = 90.
res2@mpMinLonF = -180.
res2@mpMaxLonF = 0.
; Make sure vectors are drawn in "predraw" phase.
res2@vcVectorDrawOrder = "Predraw"

; Use "overlay" to overlay anomalies for slp and wind
slpanom = gsn_csm_contour_map(wks,slp_anom,res)
windanom = gsn_csm_vector(wks,u_anom, v_anom,res2)
overlay(slpanom, windanom)

end

-- 
Edward J. Martino, Ph.D.
NOAA-JHT
Cooperative Oxford Laboratory
904 S Morris St
Oxford, MD 21654
Ph: (410) 226 5193   ext: 179
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Jan 9 19:12:45 2011

This archive was generated by hypermail 2.1.8 : Thu Jan 13 2011 - 09:24:21 MST