[Thread Prev][Thread Next][Index]

[ferret_users] count consecutive events



Hi all,

Is there a way to count consecutive events ?
From climate indice variables, I would like to have the number
of continuous events, for 1, 2, 3, 4, ..., n events.

              B   C1EVN  C2EVN  C3EVN  C4EVN
1    /  1:  0.000   ....   ....   ....   ....
2    /  2:  1.000  1.000   ....   ....   ....
3    /  3:  0.000   ....   ....   ....   ....
4    /  4:  1.000  1.000   ....   ....   ....
5    /  5:  0.000   ....   ....   ....   ....
6    /  6:  1.000  1.000   ....   ....   ....
7    /  7:  0.000   ....   ....   ....   ....
8    /  8:  1.000  1.000   ....   ....   ....
9    /  9:  0.000   ....   ....   ....   ....
10   / 10:  0.000   ....   ....   ....   ....
11   / 11:  0.000   ....   ....   ....   ....
12   / 12:  1.000   ....  1.000   ....   ....
13   / 13:  1.000   ....   ....   ....   ....
14   / 14:  0.000   ....   ....   ....   ....
15   / 15:  1.000   ....  1.000   ....   ....
16   / 16:  1.000   ....   ....   ....   ....
17   / 17:  0.000   ....   ....   ....   ....
18   / 18:  0.000   ....   ....   ....   ....
19   / 19:  1.000   ....  1.000   ....   ....
20   / 20:  1.000   ....   ....   ....   ....
21   / 21:  0.000   ....   ....   ....   ....
22   / 22:  0.000   ....   ....   ....   ....
23   / 23:  1.000  1.000   ....   ....   ....
24   / 24:  0.000   ....   ....   ....   ....
25   / 25:  0.000   ....   ....   ....   ....
26   / 26:  1.000   ....   ....   ....  1.000
27   / 27:  1.000   ....   ....   ....   ....
28   / 28:  1.000   ....   ....   ....   ....
29   / 29:  1.000   ....   ....   ....   ....
30   / 30:  0.000   ....   ....   ....   ....
...

C1EVN represents events for 1 period at 1
C2EVN represents events for 2 consecutive periods at 1
C3EVN represents events for 3 consecutive periods at 1
C4EVN represents events for 4 consecutive periods at 1
...

Attached is a exemple I have scripted. It works well for a 52 points variable
when I look for for 1 to 4 consecutive events.

As the real case is to compute this over a year of 360 days looking for
consecutive events of 30 days, I need to define variables from very long expressions.
and in this case I get the message :
**ERROR: expression too complex

Let me know if there a solution to this.
Patrick

--
LSCE/IPSL, Laboratoire CEA-CNRS-UVSQ
Data Analysis and Visualization Engineer
IPSL Global Climate Modelling Group
--

!========================================================
def axis/x=1:52:1/modulo xaxis
let a0 = randu(i[i=1:52])
let a=a0[gx=xaxis@asn]

let b = If a gt 0.45 then 1 else 0

let c1evn = if b[i=@shf:-1] eq 0 and b[i=@shf:0] eq 1 and b[i=@shf:1] eq 0 then 1
let c2evn = if b[i=@shf:-1] eq 0 and b[i=@shf:0] eq 1 and b[i=@shf:1] eq 1 and b[i=@shf:2] eq 0 then 1
let c3evn = if b[i=@shf:-1] eq 0 and b[i=@shf:0] eq 1 and b[i=@shf:1] eq 1 and b[i=@shf:2] eq 1 and b[i=@shf:3] eq 0 then 1 
let c4evn = if b[i=@shf:-1] eq 0 and b[i=@shf:0] eq 1 and b[i=@shf:1] eq 1 and b[i=@shf:2] eq 1 and b[i=@shf:3] eq 1 and b[i=@shf:4] eq 0 then 1

list b, c1evn, c2evn, c3evn, c4evn
list c1evn[i=@sum], c2evn[i=@sum], c3evn[i=@sum], c4evn[i=@sum]

message

!========================================================
repeat/range=1:25:1/name=var (\
	go defvar b `var` \
)

list b, d1evn, d2evn, d3evn, d4evn
list d1evn[i=@sum], d2evn[i=@sum], d3evn[i=@sum], d4evn[i=@sum]
\cancel mode verify

!===============================================
let strdefvar=""
repeat/range=0:`($02)-1`/name=n ( \
		let strdefvar=strcat("`strdefvar`","AND ($01)[I=@SHF:`n`] EQ 1 ") \
)  

!===============================================
let d($02)evn = IF ($01)[I=@SHF:-1] EQ 0 `strdefvar` AND ($01)[I=@SHF:($02)] EQ 0 THEN 1

!===============================================
cancel var strdefvar

!===============================================
set mode/last verify


[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement