;---------------------------------------------------------------------- ; panel_33.ncl ; ; Concepts illustrated: ; - Combining two sets of paneled plots on one page ; - Maximizing paneled plots after they've been created ; - Drawing two labelbars in a combined panel plot ; - Using lbBoxEndCapStyle to draw triangles at the end of a labelbar ;---------------------------------------------------------------------- ; ; These files are loaded by default in NCL V6.2.0 and newer ; 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 ;---Open file fname = "mon_sel_GPCC_1971.2000.nc" f = addfile(fname, "r") fname2 = "mon_INT_cru_ts4.01.1971.2000.pre.dat.nc" f2 = addfile(fname2, "r") fname3 = "mon_INT_rcm_pr_AFR-44_1971.2000.nc" f3 = addfile(fname3, "r") gpcc = f->p(:, ::-1, {4:35}) cru = f2->pre(:, ::-1, {4:35}) rcm = f3->pr(:, ::-1, {4:35}) lat = gpcc&lat lon = gpcc&lon time = gpcc&time nlat = dimsizes(lat) mlon = dimsizes(lon) Avg_gpcc = dim_avg_n_Wrap(gpcc, 0) Avg_cru = dim_avg_n_Wrap(cru, 0) Avg_rcm = dim_avg_n_Wrap(rcm, 0) Var_gpcc = dim_variance_n_Wrap(gpcc, 0) Var_cru = dim_variance_n_Wrap(cru, 0) Var_rcm = dim_variance_n_Wrap(rcm, 0) avdiff_gpcc_rcm = Avg_gpcc - Avg_rcm avdiff_cru_rcm = Avg_cru - Avg_rcm copy_VarCoords(Avg_gpcc, avdiff_gpcc_rcm) copy_VarCoords(Avg_cru, avdiff_cru_rcm) Eqv_gpcc = equiv_sample_size (gpcc, 0.1, 0) ; critical sig lvl of 0.1 (equiv sample size) Eqv_cru = equiv_sample_size (cru, 0.1, 0) Eqv_rcm = equiv_sample_size (rcm, 0.1, 0) N1 = wgt_areaave (Eqv_gpcc, dimsizes(time), 1., 0) N2 = wgt_areaave (Eqv_cru, dimsizes(time), 1., 0) N3 = wgt_areaave (Eqv_rcm, dimsizes(time), 1., 0) prob45_1 = ttest(Avg_gpcc, Var_gpcc, N1, Avg_rcm, Var_rcm, N3, True, True) ; t-test prob45_2 = ttest(Avg_cru, Var_cru, N2, Avg_rcm, Var_rcm, N3, True, True) ; t-test ;aveX = where(prob.lt.95., prob@_FillValue, prob) prob45_1!0 = "var" prob45_1!1 = "lat" prob45_1!2 = "lon" prob45_1&lat = lat prob45_1&lon = lon copy_VarCoords(prob45_1, prob45_2) ;---Start the graphics wks = gsn_open_wks("pdf", "panel") ; send graphics to PNG file res = True res@gsnDraw = False res@gsnFrame = False res@mpFillOn = False ; no need res@cnLevelSelectionMode= "ManualLevels" ; manual set levels res@cnMinLevelValF = 1.0 res@cnMaxLevelValF = 15.0 res@cnLevelSpacingF = 1.0 ; 20 contour levels res@cnFillOn = True ; color fill plot res@cnLinesOn = False res@cnLineLabelsOn = False res@cnInfoLabelOn = False res@cnFillPalette = "MPL_YlGnBu" res@mpDataBaseVersion = "Ncarg4_1" ; use finer database res@pmTickMarkDisplayMode = "Always" ; turn on tickmarks res@mpFillOn = False ; turn off gray fill res@mpOutlineBoundarySets = "National" ; turn on country boundaries res@mpGeophysicalLineColor = "black" ; color of cont. outlines res@mpGeophysicalLineThicknessF = 2.0 ; thickness of outlines res@tmXBTickSpacingF = 5 res@tmYLTickSpacingF = 5 res@gsnAddCyclic = False ; regional data, don't add pt res@mpProjection = "CylindricalEquidistant" ; projection res@mpLimitMode = "Corners" ; method to zoom res@mpLeftCornerLatF = min(lat) res@mpLeftCornerLonF = min(lon) res@mpRightCornerLatF = max(lat) res@mpRightCornerLonF = max(lon) res@tfDoNDCOverlay = True ; do no res@lbLabelBarOn = False ; turn off individual label bars ;---Resources for diff plots dres = res dres@cnMinLevelValF = -3. dres@cnMaxLevelValF = 3. dres@cnLevelSpacingF = 0.5 dres@cnFillPalette = "MPL_RdBu" ;---Create arrays to hold series of plots plots = new(3,graphic) diff_plots = new(2,graphic) res@gsnLeftString = "GPCC" ; add the gsn titles res@gsnCenterString = " " res@gsnRightString = "mm/day" res@gsnStringFont = "helvetica-bold" res@gsnLeftStringFontHeightF = 0.025 ; instead of using txFontHeightF or gsnStringFontHeightF ;res@gsnCenterStringFontHeightF = 0.02 ; to set the gsnLeft/Center/RightString font heights, res@gsnRightStringFontHeightF = 0.025 ; individu plots(0) = gsn_csm_contour_map_ce(wks, dim_avg_n_Wrap(gpcc, 0), res) res@gsnLeftString = "CRU" plots(1) = gsn_csm_contour_map_ce(wks, dim_avg_n_Wrap(cru, 0), res) res@gsnLeftString = "Ens" plots(2) = gsn_csm_contour_map_ce(wks, dim_avg_n_Wrap(rcm, 0), res) dres@gsnRightString = "mm/day" dres@gsnStringFont = "helvetica-bold" dres@gsnLeftStringFontHeightF = 0.025 ; instead of using txFontHeightF or gsnStringFontHeightF ;res@gsnCenterStringFontHeightF = 0.02 ; to set the gsnLeft/Center/RightString font heights, dres@gsnRightStringFontHeightF = 0.025 ; individu dres@gsnLeftString = "GPCP-ENS" resa = True ; res2 probability plots resa@gsnDraw = False ; Do not draw plot resa@gsnFrame = False ; Do not advance frome resa@gsnAddCyclic = False resa@cnInfoLabelOn = False resa@cnLinesOn = False ; do not draw contour lines resa@cnLineLabelsOn = False ; do not draw contour labels resa@cnFillScaleF = 0.9 ; add extra density ;resa@cnFillDotSizeF = 0.002 ; increase dot size of contours plota = gsn_csm_contour_map_ce(wks, dim_avg_n_Wrap(gpcc, 0)-dim_avg_n_Wrap(rcm, 0) ,dres) plota1 = gsn_csm_contour(wks, prob45_1(0, :, :), resa) plota1 = ShadeLtContour(plota1, 0.9, 17) ; shade signif <.95 overlay (plota1, plota) diff_plots(0) = plota1 dres@gsnLeftString = "CRU-ENS" plotb = gsn_csm_contour_map_ce(wks, dim_avg_n_Wrap(cru, 0)-dim_avg_n_Wrap(rcm, 0) ,dres) plotb1 = gsn_csm_contour(wks, prob45_2(0, :, :), resa) plotb1 = ShadeLtContour(plota1, 0.9, 17) ; shade signif <.95 overlay (plotb1, plotb) diff_plots(1) = plotb1 ;---Resources for paneling pres = True ; modify the panel plot pres@gsnPanelMainString= " " pres@gsnFrame = False ; don't advance frame yet pres@gsnDraw = False ; draw later, in maximize mode pres@gsnPanelBottom = 0.33 ; top 2/3 of frame pres@pmLabelBarHeightF = 0.050 pres@gsnPanelLabelBar = True ; add common colorbar pres@lbOrientation = "vertical" pres@pmLabelBarWidthF = 0.085 ; make thinner pres@pmLabelBarHeightF = 0.50 pres@lbBoxEndCapStyle = "TriangleBothEnds" ; Added in NCL V6.4.0 ; ; It is necessary to return the id of the paneled plots, ; so they can "live" for the rest of this script, for ; when we maximize them later. ; panelid1 = gsn_panel_return(wks,plots,(/1, 3/),pres) ;---Calculate location for top of difference plots bb = NhlGetBB(panelid1) bottom = min(bb(:,1)) top = max(bb(:,0)) height = (top-bottom)/2. ; Height of one row ;---Panel the diff plots at the bottom delete(pres@gsnPanelMainString) pres@gsnPanelTop = bottom-0.01 ; lower 1/3 plus some white space pres@gsnPanelBottom = pres@gsnPanelTop - height pres@lbBoxEndCapStyle = "TriangleBothEnds" ; Added in NCL V6.4.0 pres@pmLabelBarHeightF = 0.20 panelid2 = gsn_panel_return(wks,diff_plots,(/1, 2/),pres) ;---This will maximize the size of all the paneled stuff. maximize_output(wks,True) end