2017-06-21 28 views
0

我試圖確定&下降的信號的時間的上漲,這看起來是這樣的:PMT Signal如何來標記不試一試循環滿足聲明項

的目標是找到秋季和上升信號的時間。我試過的是在信號的平坦部分分配90%的電平,並將0-10%分配爲信號的最小值。這是我曾嘗試:

高清drop_time(個體經營,CH,calChannel_data):

try: 
     up_limit = np.where(calChannel_data >= np.percentile(calChannel_data, 90, axis = 0)) 
     low_limit = np.where(calChannel_data == np.min(calChannel_data)) 
     midpoint = np.where(np.logical_and(calChannel_data >= np.percentile(calChannel_data, 45, axis = 0), \ 
             calChannel_data <= np.percentile(calChannel_data, 55, axis = 0))) 
     before_fall =up_limit[0][ np.where(up_limit[0] <= low_limit[0][0])] 
     after_fall = up_limit[0][np.where(up_limit[0]>= low_limit[0][0])] 
    except IndexError: 
     print("the criteria was not met") 
    else: 
     return ch, up_limit[0], low_limit[0][0], midpoint[0], before_fall, after_fall 
    finally: 
     print("the end") 

但是,它並沒有完全用於工作,也有不滿足的條件部分信號try:代碼的一部分。有沒有辦法標記條件不滿足的任何情況並防止它停止?

回答

0

你總是窩try S,像

try: 
    try: 
     up_limit = np.where(calChannel_data >= np.percentile(calChannel_data, 90, axis = 0)) 
    except: 
     up_limit = "Failed" # or whatever 
    # ... similarly for the others 
    low_limit = np.where(calChannel_data == np.min(calChannel_data)) 
    midpoint = np.where(np.logical_and(calChannel_data >= np.percentile(calChannel_data, 45, axis = 0), \ 
            calChannel_data <= np.percentile(calChannel_data, 55, axis = 0))) 
    before_fall =up_limit[0][ np.where(up_limit[0] <= low_limit[0][0])] 
    after_fall = up_limit[0][np.where(up_limit[0]>= low_limit[0][0])] 
except IndexError: 
    print("the criteria was not met") 
else: 
    return ch, up_limit[0], low_limit[0][0], midpoint[0], before_fall, after_fall 
finally: 
    print("the end") 
相關問題