[ncl-talk] Issue with bounding boxes

Alyce Sala Tenna alsalte at gmail.com
Wed Mar 16 22:50:06 MDT 2016


Hi there,

I'm having trouble creating unity for my 3 panel plots.
Somewhere between having no label bar for the first panel, and adding 
one in the second, the label bar reduces the second panel entirely, then 
expands again on the third panel.
I've attached the script, do you think there are there any other 
measurements I should consider adding into the plot, or other options so 
I have evenly spaced rows?
I think between lines 218 - 248 is where the issue lies.

Many thanks in advance for your help.
Regards
Alyce
-------------- next part --------------
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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "/Users/alyce/Atmos-Lab-Scripts/murdoch_uni_atmos_lab_codes/NCL-Functions/cordex_grid_plot_functions.ncl"
;load "/Users/Alyce/Murdoch_atmos_lab_scripts/murdoch_uni_atmos_lab_codes/NCL-Functions/cordex_grid_plot_functions.ncl" ;lappy link

; File Name : diff_seasonal_plots.ncl

; Purpose : seasonal graphical plot of the SDI against BOM

; Creation Date : 29-01-2016

; Last Modified : Thu 17 Mar 12:39:59 2016

; Created By : Alyce (alsalte at gmail.com)

begin
;--------------------- Inputs -------------------------
;yrs to start and end
begyr = 1981
endyr=2010
model = "ERA-INT_"
stat= "_yseasmean"         ;yseasonal means

bom_cum_fi = addfile("/Users/alyce/FIRE/BOM/REGRID/OUTPUTS/cdo_calcs/BOM_rgrid_1981-2010_yseassumavg.nc","r")
era_cum_fi = addfile("/Users/alyce/FIRE/WRF_PROC_DATA/OUTPUTS/cdo_calcs/ERA-INT_clim_var_1981-2010_yseasum.nc","r")

wrfout=addfile("/Users/alyce/FIRE/wrfout_d03.nc", "r")     ;wrf ref file
 
;save plots for SDI and DF
diro = "/Users/alyce/FIRE/figs_out/"
filo_ppt = model+"ppt_"+begyr+"-"+endyr
f_write_ppt = diro + filo_ppt
;------------------------------------------------------
; start code here
type="pdf"
wks = gsn_open_wks(type,f_write_ppt)
col_map = (/"BlGrYeOrReVi200","BlGrYeOrReVi200","precip4_diff_19lev"/)
rows = 4
cols = 1

;titles for plots
txString = (/"WRF-ERA cumulative seasonal average preciptation",\
             "BOM cumulative seasonal average precipitation", \
              "Differences seasonal precipitation (ERA-Interim - BOM)"/)  
fig_strs = (/"DJF","MAM","JJA","SON","DJF","MAM","JJA","SON","DJF","MAM","JJA","SON"/)
lbTitleString = "(mm season~S~-1~N~)"

print("         Extract variables to plot")
era_ppt = era_cum_fi->rain 
bom_ppt = bom_cum_fi->bom_ppt
;calc discrepencies between 2 model
diff_ppt = era_ppt - bom_ppt
dsize = dimsizes(diff_ppt)

print("         Mask out ocean")
;get map info for later
truelat1 = wrfout at TRUELAT1
truelat2 = wrfout at TRUELAT2
cen_lon = wrfout at CEN_LON
cen_lat = wrfout at CEN_LAT
lat = wrfout->XLAT(0,:,:)
lon = wrfout->XLONG(0,:,:)

print("         take out relaxation points")
landmask = wrf_user_getvar(wrfout,"LANDMASK",0)     
landmask:= landmask(10:(dsize(1)-10),10:(dsize(2)-10))
era_ppt:= era_ppt(:,10:(dsize(1)-10),10:(dsize(2)-10))
bom_ppt:= bom_ppt(:,10:(dsize(1)-10),10:(dsize(2)-10))
diff_ppt:= diff_ppt(:,10:(dsize(1)-10),10:(dsize(2)-10))
lat:= lat(10:(dsize(1)-10),10:(dsize(2)-10))
lon:= lon(10:(dsize(1)-10),10:(dsize(2)-10))
nlat = dimsizes(lat)
nlon = dimsizes(lon)
delete(dsize)                 ;old dimensions

era_ppt= mask(era_ppt,landmask,1)            ;       mask sdi_lim
bom_ppt = mask(bom_ppt,landmask,1)
diff_ppt = mask(diff_ppt,landmask,1)

; convert lon to be 0->360 not -180->180
lon = where(lon.lt.0,360.+lon,lon)
pole_lat = wrfout at POLE_LAT-90.0
pole_lon = wrfout at POLE_LON-180.0

print("  set plot preferences")
;new dimension sizes
res = True
res at txString = txString(1)
;OK this is essential
res at sfXArray = lon
res at sfYArray = lat 
;define corners of plot as were out of the zone
res at mpLimitMode = "Corners"
res at mpLeftCornerLatF = lat(0,0)
res at mpLeftCornerLonF = lon(0,0)
res at mpRightCornerLatF = lat(nlat(0)-1,nlon(1)-1)
res at mpRightCornerLonF = lon(nlon(0)-1,nlon(1)-1)
res at mpProjection  = "CylindricalEquidistant"
res at mpCenterRotF = -3.
res at mpCenterLatF = pole_lat
res at mpCenterLonF = pole_lon
res at mpOutlineDrawOrder = "PostDraw"   ;force map tp be drawn 1st
res at mpGridLineDashPattern = 2      ;lat/lon lines as dashed
res at mpPerimOn              = True
res at mpPerimDrawOrder       = "PostDraw"
res at mpOutlineOn            = True
res at mpGridAndLimbOn = True
res at mpGridSpacingF = 10.
res at mpGridLineDashPattern = 2 ; make grid lines dash
res at mpGeophysicalLineThicknessF = 1.5
res at mpFillOn = True
res at pmTickMarkDisplayMode = "Always"
res at tmXTLabelsOn = False       ;we may turn this on later?
res at tmYRLabelsOn = False
res at tmXTOn = False            ; turn off top tick marks
res at tmYROn = False            ;turn off right tick marks
res at tmXBOn = False
res at tmXTOn = False
res at tmYLLabelFontHeightF = 0.02     ;height of the ticks
res at tmYLOn = False                ;left and right tick marks
;res at tmYROn = False                ;left and right tick marks

res at mpOutlineBoundarySets = "National"
res at mpGeophysicalLineThicknessF = 1.5
res at mpDataBaseVersion = "MediumRes"
res at mpDataSetName = "Earth..4"
res at mpOutlineSpecifiers = "Australia:states"

;some basic paramters
res at gsnDraw             = False      ;hold off on plotting
res at gsnFrame            = False
res at gsnAddCyclic       = False             ;coz we have non-global (e.g. regional) data
res at cnLineLabelsOn =  True
res at mpFillOn            = False            ; no need  
res at mpGridLatSpacingF = 10 ; grid line spacing on plot
res at mpGridLonSpacingF = 10 
res at mpGridLineDashPattern = 2 ; make grid lines dash
;contour spacing
res at cnLevelSelectionMode= "ManualLevels"   ;  set auto levels for now
res at cnMinLevelValF      = 40
res at cnMaxLevelValF      = 360.
res at cnLevelSpacingF     = 20.              ; 20 contour levels        
res at cnFillOn            = True             ; color fill plot
res at cnLinesOn           = False
res at cnLineLabelsOn      = False           ;no line labels
res at cnInfoLabelOn       = False
res at lbLabelBarOn        = False            ; turn off individual label bars
res at pmLabelBarOrthogonalPosF = 0.15
res at pmLabelBarParallelPosF = 1.
;res at gsnStringFontHeightF= 0.02
res at gsnLeftString       = " "
res at gsnRightString      = " "
res at cnFillPalette       = col_map(0)

;----resources for difference plots
bres = res
bres at cnMinLevelValF      = 40
bres at cnMaxLevelValF      = 380
bres at cnLevelSpacingF     = 20.              ; 20 contour levels        
;----resources for difference plots
dres = res
dres at cnMinLevelValF = -100
dres at cnMaxLevelValF = 100
dres at cnLevelSpacingF = 10.
dres at cnFillPalette = col_map(2)

;---resource for BOM plot
nplots = 12
era_plots = new(rows,graphic)     ;BOM + ERA seasons
bom_plots = new(rows,graphic)     ;BOM + ERA seasons
diff_plots = new(rows,graphic)        ;will hold your difference plots
ppt_plot = new((/nplots,nlat(0),nlon(0)/),float)

;place data in array for later
ppt_plot(0,:,:) = era_ppt(0,:,:)
ppt_plot(1,:,:) = era_ppt(1,:,:)
ppt_plot(2,:,:) = era_ppt(2,:,:)
ppt_plot(3,:,:) = era_ppt(3,:,:)
ppt_plot(4,:,:)= (/bom_ppt(0,:,:)/)
ppt_plot(5,:,:)= (/bom_ppt(1,:,:)/)
ppt_plot(6,:,:)= (/bom_ppt(2,:,:)/)
ppt_plot(7,:,:)= (/bom_ppt(3,:,:)/)
ppt_plot(8,:,:) = (/diff_ppt(0,:,:)/)
ppt_plot(9,:,:) = (/diff_ppt(1,:,:)/)
ppt_plot(10,:,:) = (/diff_ppt(2,:,:)/)
ppt_plot(11,:,:) = (/diff_ppt(3,:,:)/)

print("  start putting data away")
do i = 0,3      
  era_plots(i) = gsn_csm_contour_map_ce(wks,ppt_plot(i,:,:),res) 
  bom_plots(i) = gsn_csm_contour_map_ce(wks,ppt_plot(i+4,:,:),bres) 
  diff_plots(i) = gsn_csm_contour_map_ce(wks,ppt_plot(i+8,:,:),dres)
end do       ;ends i

;---Resources for paneling
;start up panel stuff
pres                   = True              ; modify the panel plot
pres at gsnDraw 	       = False
pres at gsnFrame          = False             ; don't advance frame yet
pres at txString          = txString(0)       ;txString 
pres at txFontHeightF = 0.015                 ;height of title font	
pres at pmLabelBarOrthogonalPosF = -.01       ;move whole bottom labelbar down
pres at gsnPanelBottom   =  0.7              ;distance from btm
pres at gsnPanelLabelBar  = False              ; add common colorbar

;---few box text labels
;pres at gsnPanelFigureStringsFontHeightF = 0.01  ;stuff that goes within the panel
pres at gsnPanelFigureStrings = fig_strs
pres at lbTitleString    = lbTitleString         ;should be mm/mth
pres at lbTitleFontHeightF = 0.01                ;titles (mm/mth font height)

print("   plot 1st row")
panelid1 = gsn_panel_return(wks,era_plots,(/cols,rows/),pres)     ;two rows, 4 seasons
;-------for the second row of plots
;-------calc loc for top of difference plots
pres at lbTitlePosition = "Bottom"      ;position of label bar
pres at lbTitleFontHeightF = 0.01
pres at gsnPanelLabelBar  = True
pres at txPosYF = 0.66
;get your bin size
bb     = NhlGetBB(panelid1)
bottom = min(bb(:,1))                     ;bottom area  - plotlid1
top = max(bb(:,0))                        ;is the topmost area all combined objects - plotid1
print("this is bottom top of panelid1 :" + bottom + " , " + top) 
height = (top-bottom)                     ;height of one row; also affects widtch
pres at gsnPanelTop = bottom - 0.05          ;gives us space for a titles
pres at gsnPanelBottom = pres at gsnPanelTop - height
pres at txString:= txString(1)               ;txString          ; title ontop

print("  plot 2nd row")
panelid2 = gsn_panel_return(wks,bom_plots,(/cols,rows/),pres)     ;two rows, 4 seasons

;----panel the difference plots at the btm (third row)
bb:= NhlGetBB(panelid2)
bottom:= min(bb(:,1))                    ;bottom area
top:= max(bb(:,0))                       ;is the topmost area all combined objects
height:= (top-bottom) 
pres at gsnPanelTop = bottom - 0.02         ;lower 1/3 & some white space
pres at gsnPanelBottom = pres at gsnPanelTop - height
pres at txString = txString(2)
pres at txPosYF = 0.35                     ;shifts the titles of each panel
print("this is bottom top of panelid2 :" + bottom + " , " + top)
print("  plot 3rd row")
panelid3 = gsn_panel_return(wks,diff_plots,(/cols,rows/),pres)

;---Using height value, now we can panel all sets of plots.
maximize_output(wks,True)
;draw(wks)
frame(wks)
print("Yay plotted")
end ; this ends begin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ERA-INT_ppt_1981-2010.pdf
Type: application/pdf
Size: 461532 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160317/260b9972/attachment-0001.pdf 


More information about the ncl-talk mailing list