-
Notifications
You must be signed in to change notification settings - Fork 0
/
usgs.py
31 lines (29 loc) · 1.22 KB
/
usgs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
# 读取txt文件,从第二行开始读,读取的每行数据转成float
path = r"H:\biaoshu\ChapterS_SoilsAndMixtures\splib07a_Sand_DWO-3-DEL2d_wet_no_oil_ASDFRa_AREF.txt"
with open(path, 'r', encoding='UTF-8') as f:
lines = f.readlines() # 接收数据
# print(len(lines))
head = lines[0]
head_list = head.split()
print(head_list)
float_spectal = []
value_to_remove = -1.23e+034
new_list = list(filter(lambda x: float(x) != value_to_remove, lines[1:]))
print(new_list)
for line in new_list: # 遍历数据
float_spectal.append(float(line))
min_value = np.min(float_spectal)
max_value = np.max(float_spectal)
print(min_value, max_value)
normal_spectal = (np.array(float_spectal) - min_value ) /(max_value - min_value) # 转成numpy数组
print(normal_spectal)
plt.plot(normal_spectal)
plt.title(head_list[2])
plt.xlabel('Bands')
plt.ylabel('Relative spectral response')
plt.savefig(path.replace('.txt', '.png'))
plt.show()