<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
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;">Hi All
<br>
<br>
Please ignore previous email below. I have managed to figure the area-averaging out but have some concerns regarding the overall code. I am happy that the code does what I would like for dP but not for the other components?<br>
<br>
My overall aim is to: <br>
<br>
1. mask out all ocean regions<br>
2. mask out all the wetting regions<br>
3. area average these changes over southern africa<br>
4. create boxplots of dP and 6 decomposed precipitation components<br>
<br>
I feel the code does this correctly for dP, but not convinced for the other components.<br>
<br>
Any advice would very much be appreciated regarding this issue. Below is the full code to tackle task 1 -4<br>
<br>
Many thanks in advance!<br>
<br>
Kindest Regards<br>
Melissa<br>
<br>
;*********************************************<br>
; boxplot.ncl<br>
;<br>
; Concepts illustrated:<br>
;&nbsp;&nbsp; - Drawing box plots<br>
;&nbsp;&nbsp; - Setting the color of individual boxes in a box plot<br>
;&nbsp;&nbsp; - Setting the width of individual boxes in a box plot<br>
;<br>
;*********************************************<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl&quot;<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl&quot;<br>
;*********************************************<br>
begin<br>
;**********************************************<br>
; Add data in text format and sort in ascending order<br>
;**********************************************<br>
<br>
&nbsp; latS&nbsp;&nbsp; =&nbsp; -30. <br>
&nbsp; latN&nbsp;&nbsp; =&nbsp; 0.&nbsp; <br>
&nbsp; lonL&nbsp;&nbsp; =&nbsp; 10. <br>
&nbsp; lonR&nbsp;&nbsp; =&nbsp; 40.<br>
<br>
&nbsp;model = (/&quot;bcc-csm1-1-m&quot;,&quot;BNU-ESM&quot;,&quot;CanESM2&quot;,&quot;CCSM4&quot;,&quot;CESM1-BGC&quot;,&quot;CESM1-CAM5&quot;,&quot;CSIRO-Mk3-6-0&quot;,&quot;FIO-ESM&quot;,&quot;GFDL-CM3&quot;,&quot;GFDL-ESM2G&quot;,&quot;GFDL-ESM2M&quot;,&quot;GISS-E2-H&quot;,&quot;HadGEM2-CC&quot;,&quot;HadGEM2-ES&quot;,&quot;IPSL-CM5A-LR&quot;,&quot;IPSL-CM5A-MR&quot;,&quot;MIROC5&quot;,&quot;MRI-CGCM3&quot;,&quot;NorESM1-M&quot;,&quot;NorESM1-ME&quot;/)<br>
<br>
<br>
do gg = 0,dimsizes(model)-1<br>
<br>
;dP<br>
&nbsp; in1=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadprfutureOND/Delta_pr_&quot;&#43;model(gg)&#43;&quot;.nc&quot;,&quot;r&quot;)&nbsp;
<br>
<br>
;dPShift<br>
in2=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPSpat_&quot;&#43;model(gg)&#43;&quot;_safrica_PSpat.nc&quot;,&quot;r&quot;)<br>
;dPT<br>
in3=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPT_&quot;&#43;model(gg)&#43;&quot;_safrica_PT.nc&quot;,&quot;r&quot;)<br>
;dPWeak<br>
in4=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPDiv_&quot;&#43;model(gg)&#43;&quot;_safrica_PDiv.nc&quot;,&quot;r&quot;)<br>
;dPTWRH<br>
in5=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPDiv&#43;PT&#43;PRH_&quot;&#43;model(gg)&#43;&quot;.nc&quot;,&quot;r&quot;)<br>
;dPCross<br>
in6=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPNL_&quot;&#43;model(gg)&#43;&quot;_safrica_PNL.nc&quot;,&quot;r&quot;)<br>
;dPRH<br>
in7=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPRH_&quot;&#43;model(gg)&#43;&quot;_safrica_PRH.nc&quot;,&quot;r&quot;)<br>
<br>
<br>
&nbsp; lat&nbsp;&nbsp;&nbsp; = in1-&gt;lat <br>
&nbsp; lon&nbsp;&nbsp;&nbsp; = in1-&gt;lon <br>
&nbsp; time&nbsp;&nbsp; = in1-&gt;time<br>
<br>
if ((gg.eq.0) .or. (gg.eq.9) .or. (gg.eq.10) .or. (gg.eq.11)) then<br>
dP = dble2flt(in1-&gt;pr(:,:,:))<br>
dPShift = in2-&gt;huss(:,:,:)<br>
dPtwrh = in5-&gt;huss(:,:,:)<br>
dPcross = in6-&gt;huss(:,:,:)<br>
dPT = in3-&gt;es2(:,:,:)<br>
dPweak = in4-&gt;huss(:,:,:)<br>
dPrh = in7-&gt;huss(:,:,:)<br>
<br>
else<br>
<br>
dP = in1-&gt;pr(:,0,:,:)<br>
;dPShift = in2-&gt;huss(:,0,:,:)<br>
;dPtwrh = in5-&gt;huss(:,0,:,:)<br>
;dPcross = in6-&gt;huss(:,0,:,:)<br>
;dPT = in3-&gt;es2(:,0,:,:)<br>
;dPweak = in4-&gt;huss(:,0,:,:)<br>
;dPrh = in7-&gt;huss(:,0,:,:)<br>
<br>
end if<br>
<br>
&nbsp;&nbsp;&nbsp; ;Land mask<br>
<br>
&nbsp;&nbsp;&nbsp; b=addfile(&quot;$NCARG_ROOT/lib/ncarg/data/cdf/landsea.nc&quot;,&quot;r&quot;)<br>
&nbsp;&nbsp;&nbsp; lsm_dP = landsea_mask(b-&gt;LSMASK,dP&amp;lat,dP&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsm_dPShift = landsea_mask(b-&gt;LSMASK,dPShift&amp;lat,dPShift&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsm_dPtwrh = landsea_mask(b-&gt;LSMASK,dPtwrh&amp;lat,dPtwrh&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
&nbsp;&nbsp;&nbsp; lsm_dPcross = landsea_mask(b-&gt;LSMASK,dPcross&amp;lat,dPcross&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
&nbsp;&nbsp;&nbsp; lsm_dPT = landsea_mask(b-&gt;LSMASK,dPT&amp;lat,dPT&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
&nbsp;&nbsp;&nbsp; lsm_dPweak = landsea_mask(b-&gt;LSMASK,dPweak&amp;lat,dPweak&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
&nbsp;&nbsp;&nbsp; lsm_dPrh = landsea_mask(b-&gt;LSMASK,dPrh&amp;lat,dPrh&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
<br>
&nbsp;&nbsp;&nbsp; dP = mask(dP,lsm_dP.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
&nbsp;&nbsp;&nbsp; dPShift = mask(dPShift,lsm_dPShift.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
&nbsp;&nbsp;&nbsp; dPtwrh = mask(dPtwrh,lsm_dPtwrh.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
&nbsp;&nbsp;&nbsp; dPcross = mask(dPcross,lsm_dPcross.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
&nbsp;&nbsp;&nbsp; dPT = mask(dPT,lsm_dPT.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
&nbsp;&nbsp;&nbsp; dPweak = mask(dPweak,lsm_dPweak.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
&nbsp;&nbsp;&nbsp; dPrh = mask(dPrh,lsm_dPrh.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
<br>
<br>
&nbsp;&nbsp;&nbsp; ;Drymask<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dP_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dP))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dP_dry = mask(dP,dP.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
<br>
&nbsp;&nbsp;&nbsp; dPShift_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dPShift))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPShift_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPShift_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPShift_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPShift_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPShift_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPShift_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPShift_dry = mask(dPShift,dPShift.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
<br>
&nbsp;&nbsp;&nbsp; dPtwrh_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dPtwrh))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPtwrh_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPtwrh_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPtwrh_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPtwrh_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPtwrh_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPtwrh_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPtwrh_dry = mask(dPtwrh,dPtwrh.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
<br>
&nbsp;&nbsp;&nbsp; dPcross_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dPcross))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPcross_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPcross_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPcross_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPcross_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPcross_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPcross_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPcross_dry = mask(dPcross,dPcross.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
<br>
&nbsp;&nbsp;&nbsp; dPT_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dPT))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPT_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPT_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPT_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPT_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPT_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPT_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPT_dry = mask(dPT,dPT.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
<br>
&nbsp;&nbsp;&nbsp; dPweak_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dPweak))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPweak_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPweak_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPweak_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPweak_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPweak_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPweak_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPweak_dry = mask(dPweak,dPweak.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
<br>
&nbsp;&nbsp;&nbsp; dPrh_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dPrh))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPrh_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPrh_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPrh_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPrh_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPrh_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dPrh_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPrh_dry = mask(dPrh,dPrh.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; <br>
;if ((gg.eq.0) .or. (gg.eq.9) .or. (gg.eq.10) .or. (gg.eq.11)) then<br>
<br>
dP_fldmean = wgt_areaave(dP_dry(:,{-30:0},{10:40}),1.0, 1.0, 0)<br>
dPShift_fldmean = wgt_areaave(dPShift_dry(:,{-30:0},{10:40}),1.0, 1.0, 0)<br>
dPtwrh_fldmean = wgt_areaave(dPtwrh_dry(:,{-30:0},{10:40}),1.0, 1.0, 0)<br>
dPcross_fldmean = wgt_areaave(dPcross_dry(:,{-30:0},{10:40}),1.0, 1.0, 0)<br>
dPT_fldmean = wgt_areaave(dPT_dry(:,{-30:0},{10:40}),1.0, 1.0, 0)<br>
dPweak_fldmean = wgt_areaave(dPweak_dry(:,{-30:0},{10:40}),1.0, 1.0, 0)<br>
dPrh_fldmean = wgt_areaave(dPrh_dry(:,{-30:0},{10:40}),1.0, 1.0, 0)<br>
<br>
;else<br>
<br>
;dP_fldmean = wgt_areaave(dP_dry(:,0,{-30:0},{10:40}),1.0, 1.0, 0)<br>
;dPShift_fldmean = wgt_areaave(dPShift_dry(:,0,{-30:0},{10:40}),1.0, 1.0, 0)<br>
;dPtwrh_fldmean = wgt_areaave(dPtwrh_dry(:,0,{-30:0},{10:40}),1.0, 1.0, 0)<br>
;dPcross_fldmean = wgt_areaave(dPcross_dry(:,0,{-30:0},{10:40}),1.0, 1.0, 0)<br>
;dPT_fldmean = wgt_areaave(dPT_dry(:,{-30:0},0,{10:40}),1.0, 1.0, 0)<br>
;dPweak_fldmean = wgt_areaave(dPweak_dry(:,0,{-30:0},{10:40}),1.0, 1.0, 0)<br>
;dPrh_fldmean = wgt_areaave(dPrh_dry(:,0,{-30:0},{10:40}),1.0, 1.0, 0)<br>
<br>
<br>
;end if <br>
<br>
print(dP_fldmean)<br>
print(dPShift_fldmean)<br>
<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Create new arrays of 20x40x240<br>
<br>
&nbsp; if (gg.eq.0) then<br>
&nbsp;&nbsp;&nbsp;&nbsp; dPfldavg = new ((/20/), typeof(dP_fldmean))<br>
<br>
&nbsp;&nbsp;&nbsp; dPfldavg!0=&quot;model&quot;<br>
&nbsp;&nbsp;&nbsp; dPfldavg&amp;model=model<br>
<br>
&nbsp; end if<br>
<br>
&nbsp;dPfldavg(gg) = dP_fldmean(0)<br>
<br>
&nbsp;if (gg.eq.0) then<br>
&nbsp;&nbsp;&nbsp;&nbsp; dPfldavgShift = new ((/20/), typeof(dPShift_fldmean))<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPfldavgShift!0=&quot;model&quot;<br>
&nbsp;&nbsp;&nbsp; dPfldavgShift&amp;model=model<br>
<br>
&nbsp; end if<br>
<br>
&nbsp;dPfldavgShift(gg) = dPShift_fldmean(0)<br>
<br>
if (gg.eq.0) then<br>
&nbsp;&nbsp;&nbsp;&nbsp; dPfldavgtwrh = new ((/20/), typeof(dPtwrh_fldmean))<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPfldavgtwrh!0=&quot;model&quot;<br>
&nbsp;&nbsp;&nbsp; dPfldavgtwrh&amp;model=model<br>
<br>
&nbsp; end if<br>
<br>
&nbsp;dPfldavgtwrh(gg) = dPtwrh_fldmean(0)<br>
<br>
if (gg.eq.0) then<br>
&nbsp;&nbsp;&nbsp;&nbsp; dPfldavgcross = new ((/20/), typeof(dPcross_fldmean))<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPfldavgcross!0=&quot;model&quot;<br>
&nbsp;&nbsp;&nbsp; dPfldavgcross&amp;model=model<br>
<br>
&nbsp; end if<br>
<br>
&nbsp;dPfldavgcross(gg) = dPcross_fldmean(0)<br>
<br>
if (gg.eq.0) then<br>
&nbsp;&nbsp;&nbsp;&nbsp; dPfldavgT = new ((/20/), typeof(dPT_fldmean))<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPfldavgT!0=&quot;model&quot;<br>
&nbsp;&nbsp;&nbsp; dPfldavgT&amp;model=model<br>
<br>
&nbsp; end if<br>
<br>
&nbsp;dPfldavgT(gg) = dPT_fldmean(0)<br>
<br>
if (gg.eq.0) then<br>
&nbsp;&nbsp;&nbsp;&nbsp; dPfldavgweak = new ((/20/), typeof(dPweak_fldmean))<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPfldavgweak!0=&quot;model&quot;<br>
&nbsp;&nbsp;&nbsp; dPfldavgweak&amp;model=model<br>
<br>
&nbsp; end if<br>
<br>
&nbsp;dPfldavgweak(gg) = dPweak_fldmean(0)<br>
<br>
if (gg.eq.0) then<br>
&nbsp;&nbsp;&nbsp;&nbsp; dPfldavgrh = new ((/20/), typeof(dPrh_fldmean))<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dPfldavgrh!0=&quot;model&quot;<br>
&nbsp;&nbsp;&nbsp; dPfldavgrh&amp;model=model<br>
<br>
&nbsp; end if<br>
<br>
&nbsp;dPfldavgrh(gg) = dPrh_fldmean(0)<br>
<br>
;end do<br>
&nbsp;<br>
<br>
&nbsp;dimt = dimsizes(dPfldavg)&nbsp;&nbsp; ; should be 20<br>
&nbsp;x25&nbsp; = round(.25*dimt,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; -1 to account for NCL indexing starting<br>
&nbsp;x75&nbsp; = round(.75*dimt,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; at 0 <br>
&nbsp;qsort(dPfldavg)<br>
&nbsp;print(dPfldavg)&nbsp;&nbsp;&nbsp;&nbsp; ; Print the values<br>
<br>
dimt1 = dimsizes(dPfldavgShift)&nbsp;&nbsp; ; should be 20<br>
&nbsp;x25&nbsp; = round(.25*dimt1,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; -1 to account for NCL indexing starting<br>
&nbsp;x75&nbsp; = round(.75*dimt1,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; at 0 <br>
&nbsp;qsort(dPfldavgShift)<br>
&nbsp;print(dPfldavgShift)&nbsp;&nbsp;&nbsp;&nbsp; ; Print the values<br>
<br>
dimt2 = dimsizes(dPfldavgtwrh)&nbsp;&nbsp; ; should be 20<br>
&nbsp;x25&nbsp; = round(.25*dimt2,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; -1 to account for NCL indexing starting<br>
&nbsp;x75&nbsp; = round(.75*dimt2,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; at 0 <br>
qsort(dPfldavgtwrh)<br>
&nbsp;print(dPfldavgtwrh)&nbsp;&nbsp;&nbsp;&nbsp; ; Print the values<br>
<br>
dimt3 = dimsizes(dPfldavgT)&nbsp;&nbsp; ; should be 20<br>
&nbsp;x25&nbsp; = round(.25*dimt3,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; -1 to account for NCL indexing starting<br>
&nbsp;x75&nbsp; = round(.75*dimt3,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; at 0 <br>
qsort(dPfldavgT)<br>
&nbsp;print(dPfldavgT)&nbsp;&nbsp;&nbsp;&nbsp; ; Print the values<br>
<br>
dimt4 = dimsizes(dPfldavgcross)&nbsp;&nbsp; ; should be 20<br>
&nbsp;x25&nbsp; = round(.25*dimt4,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; -1 to account for NCL indexing starting<br>
&nbsp;x75&nbsp; = round(.75*dimt4,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; at 0 <br>
qsort(dPfldavgcross)<br>
&nbsp;print(dPfldavgcross)&nbsp;&nbsp;&nbsp;&nbsp; ; Print the values<br>
<br>
dimt5 = dimsizes(dPfldavgweak)&nbsp;&nbsp; ; should be 20<br>
&nbsp;x25&nbsp; = round(.25*dimt5,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; -1 to account for NCL indexing starting<br>
&nbsp;x75&nbsp; = round(.75*dimt5,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; at 0 <br>
qsort(dPfldavgweak)<br>
&nbsp;print(dPfldavgweak)&nbsp;&nbsp;&nbsp;&nbsp; ; Print the values<br>
<br>
&nbsp;dimt6 = dimsizes(dPfldavgrh)&nbsp;&nbsp; ; should be 20<br>
&nbsp;x25&nbsp; = round(.25*dimt6,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; -1 to account for NCL indexing starting<br>
&nbsp;x75&nbsp; = round(.75*dimt6,3)-1&nbsp;&nbsp;&nbsp;&nbsp; ; at 0 <br>
qsort(dPfldavgrh)<br>
&nbsp;print(dPfldavgrh)&nbsp;&nbsp;&nbsp;&nbsp; ; Print the values<br>
<br>
end do<br>
<br>
&nbsp;iarr=new((/7,5/),&quot;float&quot;,-999.) ;&nbsp; fill with minimum, 25th absile, median, 75th absile, maximum of each timeseries<br>
&nbsp; iarr(0,:) = (/min(dPfldavg),dPfldavg(x25),dim_avg(dPfldavg),dPfldavg(x75),max(dPfldavg)/)&nbsp;
<br>
&nbsp; iarr(1,:) = (/min(dPfldavgShift),dPfldavgShift(x25),dim_avg(dPfldavgShift),dPfldavgShift(x75),max(dPfldavgShift)/)<br>
&nbsp; iarr(2,:) = (/min(dPfldavgtwrh),dPfldavgtwrh(x25),dim_avg(dPfldavgtwrh),dPfldavgtwrh(x75),max(dPfldavgtwrh)/)&nbsp;
<br>
&nbsp; iarr(3,:) = (/min(dPfldavgcross),dPfldavgcross(x25),dim_avg(dPfldavgcross),dPfldavgcross(x75),max(dPfldavgcross)/)<br>
&nbsp; iarr(4,:) = (/min(dPfldavgT),dPfldavgT(x25),dim_avg(dPfldavgT),dPfldavgT(x75),max(dPfldavgT)/)<br>
&nbsp; iarr(5,:) = (/min(dPfldavgweak),dPfldavgweak(x25),dim_avg(dPfldavgweak),dPfldavgweak(x75),max(dPfldavgweak)/)&nbsp;
<br>
&nbsp; iarr(6,:) = (/min(dPfldavgrh),dPfldavgrh(x25),dim_avg(dPfldavgrh),dPfldavgrh(x75),max(dPfldavgrh)/)<br>
&nbsp;<br>
print(iarr)<br>
&nbsp; <br>
&nbsp; x = (/-9.,-6.,-3.,0.,3.,6.,9./)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
;**********************************************<br>
; create plot<br>
;**********************************************<br>
&nbsp; wks = gsn_open_wks(&quot;X11&quot;,&quot;NCL_JOC_Boxplot_Land_Drying_abs_20_OND&quot;)<br>
;**********************************************<br>
; resources for plot background<br>
;**********************************************<br>
&nbsp; res&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; plot mods desired<br>
&nbsp; res@tmXBLabels = (/&quot;~F8~D~F21~P&quot;,&quot;~F8~D~F21~P~B~Shift&quot;,&quot;~F8~D~F21~P~B~twrh&quot;,&quot;~F8~D~F21~P~B~Cross&quot;,&quot;~F8~D~F21~P~B~T&quot;,&quot;~F8~D~F21~P~B~Weak&quot;,&quot;~F8~D~F21~P~B~RH&quot;/) ; labels for each box&nbsp;&nbsp; ;<br>
&nbsp; res@tiMainString = &quot;OND Box Plot over SA Drying (Land-Only) (10-40E 0S-30S)&quot;<br>
&nbsp; res@trYMinF = -0.6&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ; set minimum Y-axis value<br>
&nbsp; res@trYMaxF =&nbsp; 0.6&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ; set maximum Y-axis value<br>
&nbsp; res@tiXAxisString&nbsp;&nbsp; = &quot;Precipitation Components&quot;&nbsp; <br>
&nbsp; res@tiYAxisString&nbsp;&nbsp; = &quot;Absolute Change (mm/day/K)&quot;<br>
&nbsp; res@tmXBLabelFontHeightF = 0.015 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
;**********************************************<br>
; resources for polylines that draws the boxes<br>
;**********************************************&nbsp; <br>
&nbsp; llres&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = True&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp; llres@gsLineThicknessF&nbsp; = 2.5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; line thickness <br>
;**********************************************<br>
; resources that control color and width of boxes<br>
;**********************************************&nbsp; <br>
&nbsp; opti&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = True&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp; opti@boxWidth = 2.0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ; Width of box (x units)<br>
&nbsp; ;colors = (/&quot;red&quot;,&quot;blue&quot;,&quot;green&quot;,&quot;yellow&quot;,&quot;magenta&quot;,&quot;orange&quot;,&quot;cyan&quot; /)<br>
&nbsp; opti@boxColors = (/&quot;red&quot;,&quot;blue&quot;,&quot;green&quot;,&quot;yellow&quot;,&quot;purple&quot;,&quot;orange&quot;,&quot;cyan&quot; /)&nbsp; &nbsp;&nbsp;&nbsp; ; Color of box(es);<br>
&nbsp; ;gsn_define_colormap(wks, colors)&nbsp; <br>
;***********************************************<br>
&nbsp; plot = boxplot(wks,x,iarr,opti,res,llres)&nbsp;&nbsp;&nbsp; ; All 3 options used...<br>
&nbsp; draw(wks)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; box plot does not call<br>
&nbsp; frame(wks)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; these for you<br>
&nbsp; <br>
;end do<br>
<br>
<br>
end<br>
&nbsp;<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF244188"><font face="Tahoma" color="#000000" size="2"><b>From:</b> Melissa Lazenby<br>
<b>Sent:</b> 21 March 2017 12:41<br>
<b>To:</b> ncl-talk@ucar.edu<br>
<b>Subject:</b> Masking, area averaging and box whisker plots<br>
</font><br>
</div>
<div></div>
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Dear NCL Users<span class="Apple-tab-span" style="white-space:pre">
</span>
<div><br>
</div>
<div>I am currently trying to create box whisker plots of drying regions over land regions.</div>
<div><br>
</div>
<div>I have tried creating the masks and field averages in CDO however there seems to be a bug in the CDO code I am running so I am trying to do all the masking and area averaging in an NCL script.</div>
<div><br>
</div>
<div>Essentially what I would like to do is:</div>
<div><br>
</div>
<div>1. Mask out the land regions&nbsp; (DONE)<br>
</div>
<div>2. Mask out the wetting regions (i.e. only have the drying regions) (DONE)<br>
</div>
<div>3. Area average the change in precipitation over a particular domain over the southern African continent (NOT SURE?? area average or dim_avg?)<br>
</div>
<div>4. Create a box whisker plot of the change in precipitation over that region for 20 different CMIP5 models to determine the robustness and spread.</div>
<div><br>
</div>
<div>Below is my code in NCL attempting to do 1-4<br>
<br>
I have managed to do steps 1 and 2 without problems, however I am struggling to complete step 3 i.e. create an field mean using the area average function.
<br>
Essentially I would like 20 output values from my 20 models of the area averages and currently I am only obtaining 1 value not 20.<br>
<br>
;*********************************************<br>
; boxplot.ncl<br>
;<br>
; ;*********************************************<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl&quot;<br>
load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl&quot;<br>
;*********************************************<br>
begin<br>
;**********************************************<br>
; Add data in text format and sort in ascending order<br>
;**********************************************<br>
<br>
&nbsp;<br>
&nbsp;model = (/&quot;bcc-csm1-1-m&quot;,&quot;BNU-ESM&quot;,&quot;CanESM2&quot;,&quot;CCSM4&quot;,&quot;CESM1-BGC&quot;,&quot;CESM1-CAM5&quot;,&quot;CSIRO-Mk3-6-0&quot;,&quot;FIO-ESM&quot;,&quot;GFDL-CM3&quot;,&quot;GFDL-ESM2G&quot;,&quot;GFDL-ESM2M&quot;,&quot;GISS-E2-H&quot;,&quot;HadGEM2-CC&quot;,&quot;HadGEM2-ES&quot;,&quot;IPSL-CM5A-LR&quot;,&quot;IPSL-CM5A-MR&quot;,&quot;MIROC5&quot;,&quot;MRI-CGCM3&quot;,&quot;NorESM1-M&quot;,&quot;NorESM1-ME&quot;/)<br>
<br>
<br>
do gg = 0,dimsizes(model)-1<br>
;dP<br>
&nbsp; in1=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadprfutureOND/Delta_pr_&quot;&#43;model(gg)&#43;&quot;.nc&quot;,&quot;r&quot;)&nbsp;
<br>
<br>
;dPShift<br>
in2=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPSpat_&quot;&#43;model(gg)&#43;&quot;_safrica_PSpat.nc&quot;,&quot;r&quot;)<br>
;dPT<br>
in3=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPT_&quot;&#43;model(gg)&#43;&quot;_safrica_PT.nc&quot;,&quot;r&quot;)<br>
;dPWeak<br>
in4=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPDiv_&quot;&#43;model(gg)&#43;&quot;_safrica_PDiv.nc&quot;,&quot;r&quot;)<br>
;dPTWRH<br>
in5=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPDiv&#43;PT&#43;PRH_&quot;&#43;model(gg)&#43;&quot;.nc&quot;,&quot;r&quot;)<br>
;dPCross<br>
in6=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPNL_&quot;&#43;model(gg)&#43;&quot;_safrica_PNL.nc&quot;,&quot;r&quot;)<br>
;dPRH<br>
in7=addfile(&quot;/research/geog/data2/DATA/mlazenby/Chadwick_Analysis/ChadDeltaPComponentsOND/DeltaPRH_&quot;&#43;model(gg)&#43;&quot;_safrica_PRH.nc&quot;,&quot;r&quot;)<br>
<br>
<br>
&nbsp; lat&nbsp;&nbsp;&nbsp; = in1-&gt;lat <br>
&nbsp; lon&nbsp;&nbsp;&nbsp; = in1-&gt;lon <br>
&nbsp; time&nbsp;&nbsp; = in1-&gt;time<br>
<br>
if ((gg.eq.0) .or. (gg.eq.9) .or. (gg.eq.10) .or. (gg.eq.11)) then<br>
dP = dble2flt(in1-&gt;pr(:,:,:))<br>
dPShift = in2-&gt;huss(:,:,:)<br>
dPtwrh = in5-&gt;huss(:,:,:)<br>
dPcross = in6-&gt;huss(:,:,:)<br>
dPT = in3-&gt;es2(:,:,:)<br>
dPweak = in4-&gt;huss(:,:,:)<br>
dPrh = in7-&gt;huss(:,:,:)<br>
<br>
else<br>
<br>
dP = in1-&gt;pr(:,0,:,:)<br>
dPShift = in2-&gt;huss(:,0,:,:)<br>
dPtwrh = in5-&gt;huss(:,0,:,:)<br>
dPcross = in6-&gt;huss(:,0,:,:)<br>
dPT = in3-&gt;es2(:,0,:,:)<br>
dPweak = in4-&gt;huss(:,0,:,:)<br>
dPrh = in7-&gt;huss(:,0,:,:)<br>
<br>
end if<br>
<br>
&nbsp;&nbsp;&nbsp; ;Land mask<br>
<br>
&nbsp;&nbsp;&nbsp; b=addfile(&quot;$NCARG_ROOT/lib/ncarg/data/cdf/landsea.nc&quot;,&quot;r&quot;)<br>
&nbsp;&nbsp;&nbsp; lsm_dP = landsea_mask(b-&gt;LSMASK,dP&amp;lat,dP&amp;lon)&nbsp;&nbsp;&nbsp; ; read in land sea mask<br>
&nbsp;&nbsp;&nbsp; dP = mask(dP,lsm_dP.eq.0,False)&nbsp;&nbsp;&nbsp; ;mask out all ocean points)<br>
<br>
&nbsp;&nbsp;&nbsp; ;Drymask<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dP_dry = new ((/dimsizes(time),dimsizes(lat),dimsizes(lon)/), typeof(dP))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry!0=&quot;time&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry&amp;time=time<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry!1=&quot;lat&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry&amp;lat=lat<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry!2=&quot;lon&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dP_dry&amp;lon=lon<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; dP_dry = mask(dP,dP.gt.0, False)&nbsp; ; mask out all the wetting regions i.e. any values above 0 for dP<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; <br>
printVarSummary(dP)<br>
printVarSummary(dP_dry)<br>
<br>
dP_fldmean = wgt_areaave(dP_dry((gg),{-30:0},{10:40}),1.0, 1.0, 0)<br>
&nbsp;;dP_fldmean = dim_avg(dP_dry(0,{-30:0},{10:40}))<br>
<br>
print(dP_dry)<br>
printVarSummary(dP_fldmean)<br>
print(dP_fldmean)<br>
<br>
end do <br>
&nbsp;<br>
end <br>
</div>
<div><br>
</div>
<div>Any advice regarding this code would very much be appreciated.&nbsp;</div>
<div><br>
Kindest Regards<br>
Melissa<br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>