scipy 与Pandas一起寻找逆行的水星

evrscar2  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(57)

我的物体水星在做圆周运动,它的坐标在360度之内,如果它远离360度点(0度),探测它的反转是没有问题的。

an easy case:
13.08.2010  166.41245
14.08.2010  167.00584
15.08.2010  167.53165
16.08.2010  167.98625
17.08.2010  168.36589
18.08.2010  168.66672
19.08.2010  168.88494
20.08.2010  169.01682
21.08.2010  169.05885 This is where the backward movement begins
22.08.2010  169.00792 I detect it easily
23.08.2010  168.86147
24.08.2010  168.61771
25.08.2010  168.27591
26.08.2010  167.83665

字符串
我通过寻找极端来做到这一点。

from scipy.signal import argrelextrema


但是如果温度从359度降到1度,我会不断地撞车。
这里有一个系统失败的例子。它认为这是水星的逆转,虽然它只是从359度到0度。这不是倒退的开始。

crash example
13.03.2010  350.60172
14.03.2010  352.53184
15.03.2010  354.47785
16.03.2010  356.43861
17.03.2010  358.41273 This is not the beginning of a backward movement (NOT MAXIMUM)
18.03.2010    0.39843 its just ingression from Pieces to Aries
19.03.2010    2.39354 
20.03.2010    4.39545
21.03.2010    6.40106
22.03.2010    8.40673
23.03.2010   10.40828
24.03.2010   12.40098
25.03.2010   14.37956
26.03.2010   16.33824


所以,我需要找到一个行星的逆转点,在一个360度的圆周运动。

tv6aics1

tv6aics11#

IIUC,您可以使用阈值来避免误报:

c = df['Coords']
m0 = c.diff().abs().le(1)  # limit the gap, threshold=1
m1 = c.gt(c.shift(-1)) & c.gt(c.shift()) & m0  # upper peak ↗↘
m2 = c.lt(c.shift(-1)) & c.lt(c.shift()) & m0  # lower peak ↘↗
df['Reversal'] = m1|m2

字符串
输出量:

>>> df
          Date     Coords  Reversal
0   13.03.2010  350.60172     False
1   14.03.2010  352.53184     False
2   15.03.2010  354.47785     False
3   16.03.2010  356.43861     False
4   17.03.2010  358.41273     False
5   18.03.2010    0.39843     False  # ignore this case
6   19.03.2010    2.39354     False
7   20.03.2010    4.39545     False
8   21.03.2010    6.40106     False
9   22.03.2010    8.40673     False
10  23.03.2010   10.40828     False
11  24.03.2010   12.40098     False
12  25.03.2010   14.37956     False
13  26.03.2010   16.33824     False
14  13.08.2010  166.41245     False
15  14.08.2010  167.00584     False
16  15.08.2010  167.53165     False
17  16.08.2010  167.98625     False
18  17.08.2010  168.36589     False
19  18.08.2010  168.66672     False
20  19.08.2010  168.88494     False
21  20.08.2010  169.01682     False
22  21.08.2010  169.05885      True  # real case
23  22.08.2010  169.00792     False
24  23.08.2010  168.86147     False
25  24.08.2010  168.61771     False
26  25.08.2010  168.27591     False
27  26.08.2010  167.83665     False

相关问题