[ncl-talk] Get hourly values from cumulative 24hr sum

Guido Cioni guidocioni at gmail.com
Tue Jun 6 08:17:06 MDT 2017


No, just do a printVarSummary on ACCUM_HOURLY and see whether the attributes and dimensions make sense. 
It is more a "style" thing. For the purpose of plotting you shouldn't worry about that, especially since your variables are almost the same.
Cheers 

P.S.In order to be as efficient as possible I would move the if statement outside of the do loop and use it as a single condition, i.e. 

ACCUM_HOURLY (0,:,:) = ACUM (0,:,:)

Otherwise at every iteration the if statement has to check whether the condition is either true or false and this could take a long time if you have a large dataset. But needless to say it shouldn't make a big difference. 

> On 06 Jun 2017, at 16:10, Orestis <ospeyer at meteo.noa.gr> wrote:
> 
> Dear Guido and all,
> following Guido's  instructions I managed to break down the cumulative variable in each timestep. I put the code here for anybody that could find it handy:
>  
>  
>  
> ACUM = f1[0:ndata]->cum_var(a:adata,lvl,{nbeglat:nendlat},{nbeglon:nendlon})   ; This retrieves the cumulative variable from the files
>  
> ACCUM_HOURLY=new(dimsizes(ACUM),float)                   ;This creates an array with the same dimension sizes of the cumulative variablethat will be filled with the right values
>  
> do nt =0,dimsizes(time)     ;This is the do loop that subtracts the value of the previous time-step from the current one
>  
>                 if (nt.eq.0) then
>                         ACCUM_HOURLY (nt,:,:) = ACUM (nt,:,:)             ;This only applies for the first time-step as then the two values are the same
>                 else
>                        ACCUM_HOURLY (nt,:,:) = ACUM (nt,:,:)-kohlert(nt-1,:,:)  ;This applies for the rest of the timesteps
>                 end if
> end do
>  
> copy_VarMeta(ACCUM_HOURLY, ACUM)             ;This metadata function brings back the attributes of ACCUM to ACCUM_HOURLY , named dimensions and coordinate variables  which were lost because of the use of the right side (expression) inside the do loop 
>  
>  
> Guido, should I be aware of something tricky of the copy_VarMeta function?
>  
> Thanks a million,
> Orestis
>  
>  
>  
>  
> Orestis Speyer, MSc
> 
> Research Fellow, National Observatory of Athens
> Institute for Environmental Research and Sustainable Development
>  
>  
>  
> From: Guido Cioni [mailto:guidocioni at gmail.com] 
> Sent: Tuesday, May 30, 2017 5:59 PM
> To: Orestis
> Cc: ncl-talk at ucar.edu
> Subject: Re: [ncl-talk] Get hourly values from cumulative 24hr sum
>  
> Orestis, 
> look carefully at your code. 
> You have written 
>  
>  ACUM_HOURLY= ACUM(nt+1,:,:)- ACUM (nt,:,:)
>  
> Since you haven't defined ACUM_HOURLY before NCL will try to guess the type and dimension based on the right-hand side of the assignment. Thus, ACUM_HOURLY will have dimensions 32x31 (note the lack of attributes given that you are doing a mathematical operation without retaining metadata) and type float. 
>  
> At every loop iteration you are basically defining and overwriting ACUM_HOURLY again, thus the lack of a time dimension. You can define the variable in the same way as ACUM, that is 
>  
> ACUM_HOURLY=new(dimsizes(ACUM), typeof(ACUM))
>  
> and then perform the loop as 
>  
> do nt =0,dimsizes(time)-1 ; the 1 is not important
>            ACUM_HOURLY(nt, :, :)= ACUM(nt+1, :, :)- ACUM (nt,: , :)        
> end do
>  
> Good luck 
>  
>> On 30 May 2017, at 16:51, Orestis <ospeyer at meteo.noa.gr <mailto:ospeyer at meteo.noa.gr>> wrote:
>>  
>>  
>> Hi everyone,
>>  
>> I have a variable ACUM that is accumulated every hour for a total of 24 hours (like accumulated rainfall to give an example).
>> I would like to get the variable's value for each hour.
>>  
>> Variable: ACUM
>> Type: float
>> Total Size: 95232 bytes
>>             23808 values
>> Number of Dimensions: 3
>> Dimensions and sizes:   [time | 24] x [rlat | 32] x [rlon | 31]
>>  
>> I want to use something like this:
>> do nt =0,22,1
>>            ACUM_HOURLY= ACUM(nt+1,:,:)- ACUM (nt,:,:)               ;For example hour 5th hourly value  is hour 5th value minus hour 4th value
>> end do
>>  
>> but in this way I do not get an array for ACUM_HOURLY but only one time dimension:
>>  
>> Variable: ACUM_HOURLY
>> Type: float
>> Total Size: 3968 bytes
>>             992 values
>> Number of Dimensions: 2
>> Dimensions and sizes:   [32] x [31]
>>  
>> Do you have any suggestions?
>>  
>>  
>> Thank you,
>> Orestis
>>  
>>  
>>  
>>  
>>  
>> Orestis Speyer, MSc
>> 
>> Research Fellow, National Observatory of Athens
>> Institute for Environmental Research and Sustainable Development
>>  
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>  
> 
> Guido Cioni
> http://guidocioni.altervista <http://guidocioni.altervista/>.org


Guido Cioni
http://guidocioni.altervista <http://guidocioni.altervista/>.org

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


More information about the ncl-talk mailing list