查找感兴趣的几个地区,在一个阵列 [英] Finding several regions of interest in an array

查看:154
本文介绍了查找感兴趣的几个地区,在一个阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我已经在这里进行我已经离开了一段很长一段时间,并在这段时间我已经采取了一些量的多次测量与时间运行的Python程序的实验。每次测量是由一些值1和3秒之间与所使用的时间步远小于分离......说为0.01s。这样的一个例子,即使你只取Y轴类似:

Say I have conducted an experiment where I've left a python program running for some long time and in that time I've taken several measurements of some quantity against time. Each measurement is separated by some value between 1 and 3 seconds with the time step used much smaller than that... say 0.01s. An example of such an even if you just take the y axis might look like:

<$c$c>[...0,1,-1,4,1,0,0,2,3,1,0,-1,2,3,5,7,8,17,21,8,3,1,0,0,-2,-17,-20,-10,-3,3,1,0,-2,-1,1,0,0,1,-1,0,0,2,0...]

在这里,我们不活动之后急剧上升,下跌,在0附近短暂的停顿,经过一段时间,大幅下降,大幅上涨和0左右再定居的点表示这是数据的延伸的长流的一部分两个方向。会有很多这些活动在与低幅度区分开不同长度整个数据集的。

Here we have some period of inactivity followed by a sharp rise, fall, a brief pause around 0, drop sharply, rise sharply and settle again around 0. The dots indicate that this is part of a long stream of data extending in both directions. There will be many of these events over the whole dataset with varying lengths separated by low magnitude regions.

我想基本上形成N阵列的数组秒(元组 S')与不同长度刚捕获的事件,所以我以后可以分别对它们进行分析。我不能单纯用 np.absolute()键入阈因为有一个给定的事件内接近零值的偶然的小区域,如在上面的例子中分离出来。除了这有可能是在大幅度但持续时间短的测量之间偶然的光点。

I wish to essentially form an array of 'n' arrays (tuples?) with varying lengths capturing just the events so I can analyse them separately later. I can't separate purely by an np.absolute() type threshold because there are occasional small regions of near zero values within a given event such as in the above example. In addition to this there may be occasional blips in between measurements with large magnitudes but short duration.

上面的样品将理想最终成为一对夫妇从平坦区域任一侧或这样的元素或这样的

The sample above would ideally end up as with a couple of elements or so from the flat region either side or so.

[0,-1,2,3,5,7,8,17,21,8,3,1,0,0,-2,-17,-20,-10 ,-3,3,1,0,-2,-1]

我想是这样的:

输入:

<$c$c>[0,1,0,0,-1,4,8,22,16,7,2,1,0,-1,-17,-20,-6,-1,0,1,0,2,1,0,8,-7,-1,0,0,1,0,1,-1,-17,-22,-40,16,1,3,14,17,19,8,2,0,1,3,2,3,1,0,0,-2,1,0,0,-1,22,4,0,-1,0]

基于2的幅度低于某一数量的连续值的分割

Split based on some number of consecutive values below a magnitude of 2.

<$c$c>[[-1,4,8,22,16,7,2,1,0,-1,-17,-20,-6,-1],[8,-7,-1,0],[-1,-17,-22,-40,16,1,3,14,17,19,8,2,0],[1,22,4,]]

就像这个图:

如果子数组的长度小于比如说10然后取出:

If sub arrays length is less than say 10 then remove:

[ - 1,4,8,22,16,7,2,1,0,-1,-17,-20,-6,-1],[ - 1, -17,-22,-40,1​​6,1,3,14,17,19,8,2,0]

这是接近它的好方法?第一步也是困惑我一点点。我需要preserve那些小规模低的地区的事件也之内。

Is this a good way to approach it? The first step is confusing me a little also. I need to preserve those small low magnitude regions within an event also.

重新编辑!我将要比较两个信号作为每一个时间的函数测量,以便他们将在一个元组列表被压缩在一起。

Re-edited! I'm going to be comparing two signals each measured as a function of time so they will be zipped together in a list of tuples.

推荐答案

下面是我的两分钱的基础上,指数平滑。

Here is my two cents, based on exponential smoothing.

import itertools
A=np.array([0,1,0,0,-1,4,8,22,16,7,2,1,0,-1,-17,-20,-6,-1,0,1,0,2,1,0,8,-7,-1,0,0,1,0,1,-1,-17,-22,-40,16,1,3,14,17,19,8,2,0,1,3,2,3,1,0,0,-2,1,0,0,-1,22,4,0,-1,0])
B=np.hstack(([0,0],A,[0,0]))
B=np.asanyarray(zip(*[B[i:] for i in range(5)]))
C=(B*[0.25,0.5,1,0.5,0.25]).mean(axis=1) #C is the 5-element sliding windows exponentially smoothed signal
D=[]
for item in itertools.groupby(enumerate(C), lambda x: abs(x[1])>1.5): 
    if item[0]:
        D.append(list(item[1])) #Get the indices where the signal are of magnitude >2. Change 1.5 to control the behavior.
E=[D[0]]
for item in D[1:]:
    if (item[0][0]-E[-1][-1][0]) <5: #Merge interesting regions if they are 5 or less indices apart. Change 5 to control the behavior.
        E[-1]=E[-1]+item
    else:
        E.append(item)
print [(item[0][0], item[-1][0]) for item in E]
[A[item[0][0]: item[-1][0]] for item in E if (item[-1][0]-item[0][0])>9] #Filter out the interesting regions <10 in length.

这篇关于查找感兴趣的几个地区,在一个阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆