Re: diurnal cycle over a subregion

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 14 Dec 2007 14:11:50 -0700

Maybe this is what you mean:

iyStrt = 71
iyLast = 92
ixStrt = 43
ixLast = 61

RAIN = rain(iyStrt:iyLast, ixStrt:ixLast) ; subset and copy meta data
RAIN = where(RAIN.gt.0, RAIN, RAIN@_FillValue)
nRAIN = num( .not. ismissing(RAIN) ) ; total number of rain events in
region
nDAYS = 31
nHR = 24
nTim = nDAYS*nHR
rdc = new( nHR, typeof(RAIN) , RAIN@_FillValue)
cnt = new( nHR, "integer", -999)

do hr=0,nHR-1
rdc(hr) = sum( RAIN(:,:,hr:nTIM-1:nHR) )
cnt(hr) = num( .not.ismissing(RAIN(:,:,hr:nTIM-1:nHR) ) )
end do

jimmyc_at_iastate.edu wrote:
> Sorry I should have been clearer:
>
> My file has 744 time steps (31 days times 24 hours).
> So the n=n+1 statement was to try to relate the time step to the hour.
> Perhaps this changes the code you provided.
>
> Thanks for taking a look at this issue.
> jimmyc
>
> On Fri, 14 Dec 2007, Dennis Shea wrote:
>
>> Some approaches that might help.
>> Caveat: I have not really looked at this in detail.
>> I'm not sure how days fits into this.
>>
>> I always suggest using variables for subscripts. I makes changing
>> regions easier.
>>
>> iyStrt = 71
>> iyLast = 92
>> ixStrt = 43
>> ixLast = 61
>>
>> RAIN = rain(iyStrt:iyLast, ixStrt:ixLast) ; subset and copy meta data
>> RAIN = where(RAIN.gt.0, RAIN, RAIN@_FillValue)
>> nRAIN = num( .not. ismissing(RAIN) ) ; total number of rain events in
>> region
>> nDAYS = 31
>> nHR = 8
>> rdc = new( nHR, typeof(RAIN) , RAIN@_FillValue)
>> cnt = new( nHR, "integer", -999)
>>
>> rdc = 0.0
>> cnt = 0.0
>>
>> n = 0
>> do days=0,nDAYS-1
>> do hr=0,nHR-1
>> n=n+1
>> rdc(hr) = sum( RAIN(:,:,hr) ) + rdc(hr)
>> cnt(hr) = num( .not.ismissing( RAIN(:,:,hr) ) ) ) cnt(hr)
>> end do
>> end do
>>
>>
>> Please note that the dim_cumsum function could possibly be used
>>
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_cumsum.shtml
>>
>>
>>
>> Mary Haley wrote:
>>> On Wed, 12 Dec 2007 jimmyc_at_iastate.edu wrote:
>>>
>>>> All I have a 3 dimensional array (i,j,time) of 3-hrly rain rate and
>>>> want to compute the diurnal cycle.
>>>>
>>>> I attempted to do a loop like this
>>>> n=0
>>>> do days=0,30
>>>> do hr=0,7
>>>> n=n+1
>>>> do ix=43,61
>>>> do iy=71,92
>>>> if(rain(iy,ix,hr) .gt. 0.0000)then
>>>> rdc(hr) = rain(iy,ix,hr) + rdc(hr)
>>>> cnt(hr) = cnt(hr) + 1
>>>> end if
>>>> end do
>>>> end do
>>>> end do
>>>> end do
>>>
>>> All,
>>>
>>> James figured out the problem using WRAPIT and Fortran code, but I just
>>> wanted to point out that you usually can avoid nested loops like this,
>>> by using NCL's array syntax, and the "ind" or "where" functions.
>>>
>>> For example, the above loop can be partially improved by
>>> removing the "hr" loop. (BTW, I'm not sure what the "days" loop
>>> is doing here, because "days" is not referenced by anybody,
>>> so it appears that the exact same calculations are being
>>> done 31 times).
>>>
>>> Anyway, here's a slight (untested) code change that would help:
>>>
>>> do days=0,30
>>> n=n+1
>>> do ix=43,61
>>> do iy=71,92
>>> ihr = ind(rain(iy,ix,:).gt.0.0000)
>>> if(.not.any(ismissing(ihr))) then
>>> rdc(ihr) = rain(iy,ix,ihr) + rdc(ihr)
>>> cnt(ihr) = cnt(ihr) + 1
>>> end if
>>> delete(ihr) ; necessary as it may be different size next time
>>> end do
>>> end do
>>> end do
>>>
>>>
>>> --Mary
>>>
>>>> Now the code gets into the if block but the value of rdc is the
>>>> _FillValue of -999 . So, the documentation states that when
>>>> asigning one variable to another they need to be the same shape. Is
>>>> there a way to do the sum either more simply than with loops or am
>>>> I stuck in Fortran language techniques?
>>>>
>>>> I do define the rdc,cnt,rain arrays prior to the loop.
>>>> And I can printVarSummary all of them, just no values accumulate in
>>>> the rdc array.
>>>>
>>>> Thanks for your time.
>>>>
>>>> --
>>>> James Correia, Jr. PhD.
>>>> Email: jimmyc @ iastate.edu
>>>> Email: jimmyc42 @ gmail.com
>>>> Web: http://bruce.agron.iastate.edu/jimmyc/
>>>> *********************************************
>>
>>
>

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Dec 14 2007 - 14:11:50 MST

This archive was generated by hypermail 2.2.0 : Mon Dec 17 2007 - 08:25:02 MST