-
Notifications
You must be signed in to change notification settings - Fork 1
/
reading_endmembers.py
99 lines (78 loc) · 2.02 KB
/
reading_endmembers.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#reading endmembers from text files and generating abundance maps
import scipy.io as spio
import pysptools.eea as eea
import pysptools.abundance_maps as amp
import matplotlib.pyplot as plt
import numpy as np
import scipy.io as spio
from spectral import *
import spectral.io.envi as envi
img = envi.open('subset_045728.hdr', 'subset_045728')
arr = img.load()
arr = np.array(arr)
#read endmember 1 from txt file
file1 = open('residue_em.txt', 'r')
Lines = file1.readlines()
import numpy as np
count = 0
# Strips the newline character
i=0
a1 = np.zeros((2151))
for i in range(2154):
line = Lines[i]
if(i>2):
line = line.split("\t")
line = line[-1]
line = line[:-1]
line = float(line)
a1[i-3] = line
file1.close
#read endmember 2
file1 = open('soil_em.txt', 'r')
Lines = file1.readlines()
import numpy as np
count = 0
# Strips the newline character
i=0
a2 = np.zeros((2151))
for i in range(2154):
line = Lines[i]
if(i>2):
line = line.split("\t")
line = line[-1]
line = line[:-1]
line = float(line)
a2[i-3] = line
file1.close
#to match the wavelengths from the excel file and txt file of endmembers
import xlrd
import numpy as np
# Give the location of the file
loc = ("AVIRISNG.xlsx")
# To open Workbook
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
band = np.zeros((425))
# For row 0 and column 0
for i in range(1,sheet.nrows):
band[i-1] = float(sheet.cell_value(i,1))
#map the wavelengths from excel sheet and txt file
residue = np.zeros((425))
for i in range(425):
residue[i] = a1[int(band[i]-350)]
soil = np.zeros((425))
for i in range(425):
soil[i] = a2[int(band[i]-350)]
#concatenate the endmembers
residue = residue.reshape((1,425))
soil = soil.reshape((1,425))
M = np.concatenate((residue,soil))
print(M.shape)
#remove noisy bands
m1 = M[:,:195]
m2 = M[:,212:281]
m3 = M[:,316:]
print(m1.shape,m2.shape,m3.shape)
h = np.hstack((m1,m2,m3))
h = h[:,1:]
print(h.shape)