## 最近两天的成果
'''
##########################################
# #
# 不忘初心 砥砺前行. #
# 418__yj #
##########################################
'''
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import pearsonr
import datetime
import os
#求原始图像各波段相关系数与P值
def corr_p(data,spad):
print('[INFO]处理原始光谱曲线')
l1=[]
l2=[]
col=data.columns
num=len(data.index)
index=np.linspace(0,num-1,num)
data.index=index
spad.index=index
for i in col:
#pearsonr函数返回两个值,分别为相关系数以及P值(显著性水平)
#l1:相关系数列表,l2:p值列表
value=pearsonr(spad[spad.columns[0]],data[i])
l1.append(value[0])
l2.append(round(value[1],3))
corr_se=pd.Series(l1,index=col)
p_se=pd.Series(l2,index=col)
#因为不可避免的存在0.01,0.05水平线不存在,因此依次在附近寻找了+-0.002范围的值
index_001_list=[0.010,0.011,0.009,0.012,0.008]
index_005_list=[0.050,0.051,0.049,0.052,0.048]
index_001=[]
index_001_01=[]
index_005=[]
index_005_01=[]
for i in index_001_list:
index_001.append(list(p_se[p_se==i].index.values))
index_001_01.append(list(p_se[p_se==-i].index.values))
for i in index_005_list:
index_005.append(list(p_se[p_se==i].index.values))
index_005_01.append(list(p_se[p_se==-i].index.values))
#数据清洗
index_001=[list(i) for i in index_001 if len(list(i))!=0]
index_001_01=[list(i) for i in index_001_01 if len(list(i))!=0]
index_005=[list(i) for i in index_005 if len(list(i))!=0]
index_005_01=[list(i) for i in index_005_01 if len(list(i))!=0]
print(index_001,index_005)
#p=0.01,p=0.05所对应波段的相关系数值
p_001=corr_se[index_001[0][0]]
p_005=corr_se[index_00