<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000">Thanks a lot, I'll check it out. <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 21, 2022 at 8:54 PM Buzan, Jonathan <<a href="mailto:jbuzan@purdue.edu">jbuzan@purdue.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;">
Hi Lekshmi,
<div><br>
</div>
<div>The month_to_annual function can be found in the:</div>
<div>
<pre style="color:rgb(0,0,0)">$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl</pre>
<div><span style="color:rgb(0,0,0)">I recommend looking at how the function behaves, and then creating your own function that mimics the month_to_annual but specifically for the season that you are focused on.</span></div>
<div><span style="color:rgb(0,0,0)"><br>
</span></div>
<div><span style="color:rgb(0,0,0)">For example, a 3D variable, T(</span><font color="#000000"><span>time,lat,lon) uses the rankx.eq.3:</span></font></div>
<div><span style="color:rgb(0,0,0)">contributed.ncl</span></div>
<div><br>
</div>
<div><font color="#000000"><span> if (rankx.eq.3) then<br>
ny = dimx(1) ; nlat<br>
mx = dimx(2) ; mlon<br>
nyr = -1<br>
xAnnual= new ( (/nyrs,ny,mx/), typeof(x), getFillValue(x)) ; contributed.ncl<br>
do nt=0,ntim-1,NMOS<br>
xTemp = x(nt:nt+NMOS1,:,:) ; cleaner code only<br>
nyr = nyr+1<br>
<br>
if (opt.eq.0) then<br>
xAnnual(nyr,:,:) = dim_sum_n ( xTemp, 0 )<br>
else<br>
xAnnual(nyr,:,:) = dim_avg_n ( xTemp, 0 )<br>
end if<br>
<br>
nMsg = 0 ; number of missing for current year (nyr)<br>
if (isatt(x,"_FillValue")) then<br>
nMsg = num (ismissing(xTemp) ) ; for all grid points<br>
end if<br>
<br>
if (nMsg.gt.0) then<br>
nGood = dim_num_n(.not.ismissing(xTemp), 0 ) ; (lat,lon)<br>
xAnnual(nyr,:,:) = mask( xAnnual(nyr,:,:), nGood.ge.nmos, True) ; ?False<br>
print("month_to_annual: some grid points have missing data: nt="+nt \<br>
+" nyr="+nyr+" num(nGood)="+num(nGood.gt.0))<br>
end if<br>
end do<br>
<br>
copy_VarAtts (x, xAnnual)<br>
xAnnual@NCL = "month_to_annual"<br>
xAnnual!0 = "year"<br>
copy_VarCoords_skipDim0 (x, xAnnual)<br>
return(xAnnual)<br>
end if<br>
</span></font><br>
</div>
<div><span style="color:rgb(0,0,0)"><br>
</span></div>
<div><span style="color:rgb(0,0,0)">Cheers,</span></div>
<div><span style="color:rgb(0,0,0)">-Jonathan</span></div>
<div><span style="color:rgb(0,0,0)"><br>
</span></div>
<div><span style="color:rgb(0,0,0)"><br>
</span></div>
<div><br>
<blockquote type="cite">
<div>On Apr 21, 2022, at 16:52, Lekshmi M S via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div class="gmail_default" style="font-family:tahoma,sans-serif">
<p>I would like to modify the following script to spatially plot the JJAS precipitation trend plot for 70years. Instead of using "month_to_annual", I think I have to use "month_to _season" here. But JJAS is not defined as a season here. Please help
me to do this for JJAS months.</p>
<pre>;*************************************************
; regress_4.ncl
;
; Concepts illustrated:
; - Drawing color-filled contours over a cylindrical equidistant map
; - Calculating the regression coefficient (slope) at each grid point
; - Copying attributes from one variable to another
;
;*************************************************
;
; 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
;************************************************
; Specify geographical region and time span (year-month start and end
;************************************************
latS = -90
latN = 90
lonL = 0
lonR = 360
ymStrt = 195101
ymLast = 201012
pltTitle = "Globe: "+(ymStrt/100)+"-"+(ymLast/100)
;************************************************
; Read from netCDF file: variable is type short...unpack
;************************************************
diri = "./"
fili = "<a href="http://air.sig995.mon.mean.nc/" target="_blank">air.sig995.mon.mean.nc</a>"
f = addfile(diri+fili,"r")
YYYYMM = cd_calendar( f->time, -1)
iStrt = ind(YYYYMM.eq.ymStrt)
iLast = ind(YYYYMM.eq.ymLast)
x = short2flt( f->air(iStrt:iLast,{latS:latN},{lonL:lonR}) )
x = x-273.15
x@units= "degC"
printVarSummary(x) ; [time| 720]x[lat| 91]x[lon| 180]
yyyymm = cd_calendar(x&time, -1)
yyyy = yyyymm/100
dimx = dimsizes(x)
ntim = dimx(0) ; all years and months
nlat = dimx(1)
mlon = dimx(2)
year = ispan(yyyy(0), yyyy(ntim-1), 1)
nyrs = dimsizes(year)
;************************************************
; Areal averages: cos(lat) is good enough
;************************************************
xann = month_to_annual(x , 1) ; [year| 60]x[lat| 91]x[lon| 180]
xann&year = year
printVarSummary(xann)
;************************************************
; Calculate the regression coefficients (slopes)
;************************************************
rc = regCoef(year,xann(lat|:,lon|:,year|:))
rc@long_name = "Trend"
rc@units = xann@units+"/year"
copy_VarCoords(xann(0,:,:), rc) ; copy lat,lon coords
printVarSummary(rc)
;************************************************
; for illustration: change units to degC/period-used
;************************************************
rc = rc*nyrs ; (C/year)*(nyrs)
rc@units = "degC/"+nyrs+"_year"
;************************************************
; plotting parameters
;************************************************
wks = gsn_open_wks("png","regress") ; send graphics to PNG file
res = True
res@gsnMaximize = True ; make large
res@cnFillOn = True ; turn on color
res@cnLinesOn = False ; turn off contour lines
res@cnLineLabelsOn = False ; turn off contour line labels
;;res@cnFillMode = "RasterFill"
res@cnLevelSelectionMode = "ManualLevels<a href="mailto:;setmanualcontourlevelsres@cnMinLevelValF=-2.0;setmincontourlevelres@cnMaxLevelValF=2.0;setmaxcontourlevelres@cnLevelSpacingF=0.2;setcontourintervalres@mpFillOn=False;turnoffdefaultbackgroundgray;res@mpCenterLonF=180res@gsnCenterString=year(0)+" target="_blank">" ; set manual contour levels
res@cnMinLevelValF = -2.0 ; set min contour level
res@cnMaxLevelValF = 2.0 ; set max contour level
res@cnLevelSpacingF = 0.2 ; set contour interval
res@mpFillOn = False ; turn off default background gray
;res@mpCenterLonF = 180
res@gsnCenterString = year(0)+"</a>-"+year(nyrs-1)
res@tiMainString = "20th Century Reanalysis: sig995" ; fili
plot = gsn_csm_contour_map_ce(wks,rc,res)
end<br>
</pre>
</div>
</div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote></div>