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

Orestis ospeyer at meteo.noa.gr
Tue Jun 6 08:10:44 MDT 2017


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> 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
 <mailto:ncl-talk at ucar.edu> 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.org

 

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


More information about the ncl-talk mailing list