;================================================ ; lb_14.ncl ;================================================ ; Concepts illustrated: ; - Generating dummy data using "generate_2d_array" ; - Centering labels with respect to labelbar boxes ; - Adding labels to both ends of a labelbar ; - Changing the font height of labelbar labels ; - Using "getvalues" to retrieve the size of a plot ; - Using "getvalues" to retrieve contour levels ; - Making the labelbar be vertical ; - Using "sprintf" to create nicely formatted text strings ; - Forcing the paper orientation to be "portrait" ;================================================ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" begin ;---Read Saturated Water Vapor Path data nx=256 ny=256 nz=64 fnames=systemfunc("ls *.nc") data = addfiles(fnames,"r") SWVP = data[:]->SWVP x = data[:]->x y = data[:]->y time1= data[:]->time ; xnew=new((/nx/),float) xnew=x(0:255) ynew=new((/ny/),float) ynew=y(0:255) printVarSummary(xnew) printVarSummary(ynew) SWVP@long_name = "Water Vapor Path: Specific Humidity Weighted vertical average" SWVP@units="mm" SWVP!0="time" SWVP&time=time1 SWVP!1="xnew" SWVP&xnew=xnew SWVP!2="ynew" SWVP&ynew=ynew ; printVarSummary(SWVP) ; ;*************************************************** diri = "/data/SAM-CSU/RCE_IDEAL_256x256x64_302aggr/OUT_3D_12/data/data1" fils = systemfunc ("csh -c 'cd " + diri + ";ls *.nc '") print(fils) ; relative path to files ; ;*************************************************** ;read data ffnames=systemfunc("ls "+diri+"/*.nc") data1 = addfiles(ffnames,"r") p = data1[:]->p*100. p@units="Pa" z = data1[:]->z time= data1[:]->time PP = data1[:]->PP QV= data1[:]->QV QN= data1[:]->QN QP= data1[:]->QP ; printVarSummary(x) printVarSummary(y) printVarSummary(z) printVarSummary(p) printVarSummary(time) printVarSummary(PP) printVarSummary(QV) printVarSummary(QN) printVarSummary(QP) ; znew=new((/nz/),float) znew=z(0:63) ; pres=p(0:63) psfc=p(0) ptop=p(63) dp=dpres_plevel(pres, psfc, ptop, 0) ; p2d = onedtond(p,(/dimsizes(time),nz/)) p2d!0="time" p2d&time=time p2d!1="z" p2d&z=pres p2d@long_name = "pressure" ; attach some attributes p2d@units = "Pa" ; punits=0 ; p2d@positive = "up" ; p2d0 = p2d(0,:) p2d0!0="z" p2d0&z=pres p2d0@long_name = "surface pressure" ; attach some attributes p2d0@units = "Pa" ; punits=0 ; print(pres) ; print(psfc) ; print(dp) printVarSummary(p2d) ; print(p2d) ; ;compute the vertical integral of QV specific humidity (WVP) ; QVLev=QV(time|:,x|:,y|:,z|:) copy_VarAtts(QV, QVLev) copy_VarCoords_1(QV,QVLev) QVLev!0="time" QVLev&time=time QVLev!1="xnew" QVLev&xnew=xnew QVLev!2="ynew" QVLev&ynew=ynew QVLev!3="znew" QVLev&znew=znew ; printVarSummary(QVLev) QVInt = dim_sum( QVLev*conform(QVLev, dp, 3 )) ; QVInt(ntim,nlat,mlon) delete (QVLev) ; only needed on a temporary basis ; PSFC1= PP(time|:,z|:,x|:,y|:) PSFCC =conform_dims(dimsizes(PSFC1),p2d0,1) PSFC= PP(:,0,:,:)+PSFCC(:,0,:,:) printVarSummary(PSFC) ; print(PSFC) ; QVLev=QV(time|:,z|:,x|:,y|:) copy_VarAtts(QV, QVLev) copy_VarCoords_1(QV,QVLev) QVLev!0="time" QVLev&time=time QVLev!1="znew" QVLev&znew=znew QVLev!2="xnew" QVLev&xnew=xnew QVLev!3="ynew" QVLev&ynew=ynew ; WVP = QVInt/(1000*9.81) ; WVP@long_name = "Water Vapor Path: Specific Humidity Weighted vertical average" WVP@units="mm" WVP!0="time" WVP&time=time WVP!1="xnew" WVP&xnew=xnew WVP!2="ynew" WVP&ynew=ynew ; printVarSummary(WVP) ; lat=dimsizes(x) lon=dimsizes(y) lev=dimsizes(z) ; x_new=fspan(0,768000,16) y_new=fspan(0,768000,16) ; printVarSummary(x_new) printVarSummary(y_new) ; print(x_new) print(y_new) ; nlat=dimsizes(x_new) nlon=dimsizes(y_new) ;compute the ; ; WVPAvg=new( (/ny,nx/), "float" ) WVPAvg=dim_avg_n(WVP,0) WVPAvg!0="xnew" WVPAvg&xnew=xnew WVPAvg!1="ynew" WVPAvg&ynew=ynew ; printVarSummary(WVPAvg) ; ; WVPo = area_hi2lores_Wrap (WVP&xnew,WVP&ynew, WVP , False, 1, x_new, y_new, False) ; (ntime,16,16) printVarSummary(WVPo) ; WVPoAvg=new( (/nlat,nlon/), "float" ) WVPoAvg=dim_avg_n(WVPo,0) ; printVarSummary(WVPoAvg) ; SWVPo = area_hi2lores_Wrap (SWVP&xnew,SWVP&ynew, SWVP , False, 1, x_new, y_new, False) ; (ntime,16,16) printVarSummary(SWVPo) ; SWVPoAvg=new( (/nlat,nlon/), "float" ) SWVPoAvg=dim_avg_n(SWVPo,0) ; printVarSummary(WVPoAvg) printVarSummary(SWVPoAvg) ; CRH = WVPoAvg/SWVPoAvg ; ; print( CRH) printVarSummary(CRH) ;********************************************************************************* wks = gsn_open_wks("ps","BM-256x256x64_3km_SWVP") gsn_define_colormap(wks,"WhBlGrYeRe") ; gsn_define_colormap(wks,"BlWhRe") ; Change colormap plot = new(2,graphic) res = True res@gsnDraw = False ; Don't draw plot res@gsnFrame = False ; Don't advance frame ; Set up resources. res@gsnMaximize = False res@gsnSpreadColors = True ; Span full color map res@cnFillOn = True ; Turn on contour fill res@lbOrientation = "Vertical" ; vertical labelbar res@lbLabelFontHeightF = 0.01 res@gsnSpreadColors = True ; use full range of colors res@lbLabelAutoStride = True ; let NCL determine label spacing res@lbOrientation = "vertical" ; vertical label bar res@cnLevelSelectionMode = "Levels" res@cnLinesOn = False ; turn off contour lines res@tmXBMode = "Explicit" ; explicit labels res@tmXBValues = (/ 0,460800,768000/) ; location of labels res@tmXBLabels = (/ "0","460","768"/) ; labels themselves res@tmYLMode = "Explicit" ; explicitly set the Y-axis labels res@tmYLValues = (/ 0,460800,768000/) res@tmXBLabels = (/ "0","460","768"/) ; res@tiMainString = "Saturated Water Vapor Path [mm]" res@tiXAxisString = "X (km)" res@tiYAxisString = "Y (km)" ;---Use default labelbar. ; plot(0) = gsn_csm_contour(wks,SWVPoAvg(:,:),res) ;---- res@gsnMaximize = False res@gsnSpreadColors = True ; Span full color map res@cnFillOn = True ; Turn on contour fill res@lbLabelFontHeightF = 0.01 res@gsnSpreadColors = True ; use full range of colors res@lbLabelAutoStride = True ; let NCL determine label spacing res@lbOrientation = "vertical" ; vertical label bar ; res@cnLinesOn = False ; turn off contour lines res@cnLevelSelectionMode = "Levels" ; manually set the contour levels with the following 3 resources ; res@tmXBMode = "Explicit" ; explicit labels res@tmXBValues = (/ 0,460800,768000/) ; location of labels res@tmXBLabels = (/ "0","460","768"/) ; labels themselves res@tmYLMode = "Explicit" ; explicitly set the Y-axis labels res@tmYLValues = (/ 0,460800,768000/) res@tmXBLabels = (/ "0","460","768"/) ; labels themselves res@tiMainString = " RCE_IDEAL_16x16x64 regrid CRH" res@tiXAxisString = "X (km)" res@tiYAxisString = "Y (km)" ; plot(1) = gsn_csm_contour(wks,CRH(:,:),res) ;---- ; Make panel plot resP = True resP@txString ="RCE_IDEAL_256x256x64_3000m REGRID 16x16 " ; add title ; resP@gsnMaximize = False gsn_panel(wks,plot,(/2,1/),resP) ; end