Symmetry.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:PIE_ISAE_Essais_Vol 作者: YuanxiangFranck 项目源码 文件源码
def SymmetryTest(signal1, signal2, error, binary_names, name_signal1 = "", comment="ok"):
    """
    From two signals, this function calculates the relative error at each time
    indexe, and therefore returns the time indexes where anomalies are found.
    Computes as well the linear regression coefficients.

    Inputs :

    - signal1, signal2 : two signals of the class SignalData to compare (generally signal1 -> "...CHA", and signal2 -> "...CHB" or "..AMSC1" and "..AMSC2"  )
    - error : the result will be False if there is at least one value which is out of the relative error box
    - binary_names : list of binary files names
    - [name_signal1] : optional, a string, the name of the first input.
        Allows the algorithm to check if the inputs are boolean or not (from specifications)
        By defaut, consider the signal as non boolean.
    - [comment] : otpional, a string, if equals 'none' then don't print any result, prints the result if nothing is specified. The print is done through logger.info

    Outputs :

    - result : a bool, indicates if the two imput signals are the same (according to the accepted error)
    - index : time indexes of the signal.data where the differences where found
    - lin_reg : an array which contains first the type of the signals ('b' for boolean and 'c' for continuous), then the slope, the intercept and finally the R2 value of linear regression between the two signals.
    """
    n = 6 # truncation of digits in res
    result =True
    error = abs(error)
    index = []
    lin_reg = []
    sig1 = signal1.data
    sig2 = signal2.data
    if is_bool(name_signal1, binary_names):
        #The signals are categorized as boolean : we test if they are different
        for i, s in enumerate(sig1):
            if sig2[i] != s :
                result = False
                index.append(i)
        lin_reg = ["b","  -","  -","  -"] #boolean signals : no linear regression

    else:
        #The signals are 'reg' (continuous)
        for i, s in enumerate(sig1):
            if s or sig2[i]: # avoid division by 0
                if abs(2*(s-sig2[i])/(abs(s)+abs(sig2[i]))) > error:
                    result = False
                    index.append(i)

        np.seterr(divide="ignore")
        np.seterr(invalid="ignore")
        a, b, r_value, p_value, std_err = stats.linregress(sig1, sig2)
        np.seterr(divide="warn")
        np.seterr(divide="ignore")
        lin_reg = ["c", str(a)[0:n], str(b)[0:n], str(r_value**2)] #continuous signals : linear regression parameters
    logger.info(result)
    if result:
        logger.info("Les signaux ", signal1.name, signal2.name, "sont identiques (à l'erreur error près)\n")
    else:
        logger.info("L'erreur relative entre les signaux est supérieur à error sur une certaine plage\n")

    return result, index, lin_reg

#%%
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号