[Thread Prev][Thread Next][Index]

Re: [ferret_users] count consecutive events



Hi,
     Well, that was a very interesting question from Patrick. I also
thought in the same line as Mick, but came up with sort of "automated"
method. It involves the following steps (no adjustments to be done for
your input field of 0's and 1's):

   assume that variable is 1D, along time axis, with values
        occurrence of an event : 1
        absence of event      : 0

    1. Find positions where event=1 is preceded by an event=0
              --> starting point of an event.
    2. Find positions where event=1 is followed by an event=0
              --> ending  point of an event.
    3. Make adjustments for end values.
    4. Find corresponding L-indices
    5. The difference between L-indices of ending and starting point
          will give the length of consecutive events, with respect to
          L-points.

Once you get these details, you can define a cutoff period with "IF THEN"
masking method on the length of consecutive events. As you know the starting
and ending L-indices for a specific consecutive event, extracting data for
that event is very straightforward. In addition, this method does not require
any modification according to the "length of the consecutive events" you are
interested in.

This method can be easily adapted for wet or dry (cool or warm) spell
analysis.

Patrick, please have a trial with the attached demo file, with v1.nc you send
earlier. Let me know if you have any questions.

Thanks and Regards,

Jaison



> Hi Patrick,
>
>     I had a similar problem some years ago - counting runs in sequences
> of 0's and 1's -- but just thought of a better way to do it, using the
> @cia transformation.  One identifies "start" and "end" points in the
> sequence then, whereever a "start" is found, looking for where the "next
> end above" is located.
>
>     The method results in short, independent definitions for each run
> length, and lends itself to use in a repeat loop.  A demo script (when
> the sequence is along the x-axis) is attached but the key points are:
>
> ! define start points (a 1 preceded by a 0) for the runs in the sequence "v"
> let/title="Run Starts" start=if(v eq 1 and v[i=@shf:-1] eq 0)then 1
> ! ... and end points (a 1 followed by a 0)
> let/title="Run Ends" end=if(v eq 1 and v[i=@shf:1] eq 0)then 1
> ! then the start points of runs of length "n" are given by the mask "run"
> let run=IF(START EQ 1 AND END[I=@CIA] EQ `n-1`)then 1
> ! and to count them
> list run[i=@ngd]
>
> Hope it helps,
> Mick
> ---------
> Brockmann Patrick wrote:
>> 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
>>
> åå
>

Attachment: count_events_demo.jnl
Description: Binary data


[Thread Prev][Thread Next][Index]

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

Privacy Policy | Disclaimer | Accessibility Statement