[ncl-talk] Daily to weekly Rainfall data conversion

Ipshita Majhi ipmajhi at alaska.edu
Sat Jan 23 16:01:42 MST 2016


Dear NCL,

I have written a code to convert daily to weekly data and it does not match
the data set I have, the code I have written works. I was wondering where I
went wrong. If you could guide me on that it would be very helpful.

Here is the code
***********************************************************************
;This is to convert daily to weekly for precipitation data

;*******************************************
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"
;*******************************************

a= addfile("~/Documents/Snow_cover_IMS/NCL_codes/precp_daily_krishna.nc
","r")
precp=a->p
t=a->time


time_cd=cd_calendar(t,0)

;Since we are reading data from 1967-2013, we have 46 years
year_52=ispan(1901,2010,1)


;Writing a loop to process the xday information

xday=new((/110,365/),"float")
time_year=time_cd(:,0)

do i=0,109

matching=ind(year_52(i).eq.time_year)



day_size=(dimsizes(matching))

if (day_size.gt.365) then

d=matching(1:365)

else
d=matching
end if
precp_daily=precp(d)
xday(i,:)= precp_daily

delete(matching)
delete(precp_daily)

end do
print(xday)


; Now converting daily to weekly

;Now we want to convert the 365 days to weekly for each year

;Now just doing it for one year and checking the result

;pweek=new((/110,52/),"float")
x364=xday(:,0:363); This is to get 52 weeks
;print(x364)

printVarSummary(x364)
pweek=new((/110,52/),"float")


do i=0,109
do j=0,357,7
pweek(i,j/7)=avg(x364(i,j:j+6))
if(any(ismissing(pweek))) then
pweek at _FillValue =-9999.0  ; sets _FillValue to -9999.0
  end if
end do
end do


pweek = where(pweek.gt. 1e25, pweek at _FillValue, pweek)

printMinMax(pweek, 0)

opt = True
opt at fout = "weekly_mean_AIR_precp.txt"
write_matrix(pweek, "52f9.1", opt)

******************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160123/ad6b05b0/attachment.html 


More information about the ncl-talk mailing list