On 5/13/2014 5:19 PM, 'jagadish
karmacharya' via _OAR PMEL Ferret Users wrote:
Dear ferret
users,
I have a 1 dimensional time
series with intermittent values equal to 1 and missing
values in between (1's represent spells of certain events).
I want to calculate number of spells of of 1's and other
stats such as mean and medium duration of spells of 1's.
Hi Jagadish,
Following up on the ideas that Hein has begun ...
Your description is not sufficiently specific on the definition of a
"spell" to give a precise answer on how (or whether) the tools
available in Ferret can do what you are after.
- if the definition of a spell is that it a threshold on the
*density* of 1's found per unit length of the time series, then
the @SBX (running average) filter will give you something very
close to what you are after
- e.g. yes? let tdensity = mytimeseries[l=@sbx:11]
yes? PLOT tdensity ! have a look ...
yes? let myspells = IF tdensity gt threshold THEN 1
- if the definition of a spell is that it must be a strictly
contiguous sequence of 1's, it will take more imagination to see
how to apply the available Ferret tools. Here's one approach
to identifying the contiguous spells using existing tools:
- use the tdensity approach above varying the box width to
identify the longest spell.
yes? let tdensity = mytimeseries[l=@sbx:11]
yes? let elevenOrLonger = IF tdensity EQ 1 THEN 1
yes? LIST elevenOrLonger[L=@SUM] ! if answer is zero,
there are no spells this long
- define a new time series in which you mask out the blocks of
contiguous 1s just found
Iterate the procedure to find number and location of spells of
shorter and shorter duration. (Note only odd-number length
spells can be found this way.)
- Or ... as Hein says, you can write raw code to perform any
custom calculation you want by using either Python in pyFerret
or defining your own external function in vanilla Ferret.
==> Then contribute the idea back to the Ferret user's list!
A filter that, at each point, measured the length of contiguous
block of non-missing values surrounding it, would be a nice,
generic Ferret tool. (Should we add such a filter into Ferret?
It would be a fairly easy addition: e.g. LET
contiguous_spell_length = mytimeseries[l=@cntg])
- I cant help wondering if a clever use of the nearest index
above and nearest index below filters might be used to build a
contiguous length filter using a few LET definitions ...
- Steve
I would appreciate any lead on
this.
Thanks,
Jagadish
|