# Re: a simple way to calculate monthly mean from 6-hourly data for calandar month?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Oct 15 2009 - 01:47:13 MDT

For averages use

To do what you want efficiently, you should use
the 'time' variable to partition the data into
year and month segments.

If your 'time' varaiable is (say) "{seconds/hours/days} since ...", use

utc_date = ut_calendar(time, 0)
;
; Store return information into more meaningful variables.
;
year = floattointeger(utc_date(:,0)) ; Convert to integer for
month = floattointeger(utc_date(:,1)) ; use sprinti
day = floattointeger(utc_date(:,2))
hour = floattointeger(utc_date(:,3))
;minute = floattointeger(utc_date(:,4))
;second = utc_date(:,5)

ntim = dimsizes( time )

yrStrt = year(0)
yrLast = year(ntim-1)
nyrs = yrLast-yrStrt+1

nTIME = 12*nyrs

xAvg = new ( (/nTime,nlat,mlon/), typeof(p))

NT = -1
do yr=yrStrt,yrLast
do nmo=0,11

NT = NT+1
ii = ind(yr.eq.year .and. (nmo+1).eq.month)
if (.not.ismissing(ii(0))) then
xAvg(NT,:,:) = dim_avg_n(p(ii,:,:) , 0)
end if
end do
end do

Wei Huang wrote:
> Yang Yang,
>
> You may check:
> http://www.ncl.ucar.edu/Document/Functions/Contributed/dim_sum_n_Wrap.shtml
>
> to see how to do the monthly mean.
>
> Wei Huang
> huangwei@ucar.edu
> VETS/CISL
> National Center for Atmospheric Research
> P.O. Box 3000 (1850 Table Mesa Dr.)
> Boulder, CO 80307-3000 USA
> (303) 497-8924
>
>
>
>
>
> On Oct 14, 2009, at 9:03 PM, Yang Yang wrote:
>
>> Hello:
>>
>> I have 6-hourly data for 30 years. Each file has one year data in a
>> dimension like (time,lat,lon). For some years, the total number of
>> days in Feb. is 29 instead of 28.
>>
>> I would like to calculate monthly mean from the 6-hourly data for
>> Jan., Feb., ..., Dec., respectively, for each year.
>>
>> Is there a simple way in NCL to do the monthly mean?
>>
>> Thank you very much!
>>
>> Ed
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu, 15 Oct 2009 01:47:13 -0600

This archive was generated by hypermail 2.1.8 : Thu Oct 22 2009 - 12:22:52 MDT