-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotSpectrum.py
80 lines (72 loc) · 2.36 KB
/
plotSpectrum.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
import numpy as np
import matplotlib.pyplot as plt
import sys
import math
def getLBLRTMoutput(filelocation):
# Pull data from text file 1
f = open(filelocation,'r')
lines=f.readlines()
# identify beginning of data in file
i = 0
data = []
copy=False
while i<len(lines):
if ("WAVENUMBER" in lines[i]): # the data starts after this line
xTitle = "Wavenumber"
if ("RADIANCE" in lines[i]):
yTitle = "Radiance"
elif ("TRANSMISSION" in lines[i]):
yTitle = "Transmission"
elif ("TEMPERATURE" in lines[i]):
yTitle = "Temperature"
elif ("OPTICAL DEPTH" in lines[i]):
yTitle = "Optical Depth"
else:
yTitle = "unknown"
copy = True
i+=1
if copy:
data.append(lines[i])
i+=1
x = []
y = []
for item in data: # data points are formatted x y in lines
try: # copy lines of data
a = float(item[5:18]) #that line's wavenumber
b = float(item[26:41]) #the corresponding radiance value
x.append(a)
y.append(b)
except ValueError: # some lines are blank
pass
return x, y, xTitle, yTitle
def files(fileNames):
i = 0
color = ['r','g','b','y','m']
for f in fileNames:
if ("TAPE30" in f) or ("TAPE29" in f) or ("TAPE28" in f) or ("TAPE27" in f):
x, y, xTitle, yTitle = getLBLRTMoutput(f)
else:
x, y = np.loadtxt(f, unpack=True)
xTitle = 'x'
yTitle = 'y'
plt.plot(x, y, color[i], linewidth=0.9)
i+=1
plt.xlim(x[0],x[-1])
plt.xlabel(xTitle)
plt.ylabel(yTitle)
plt.legend(tuple(fileNames),fontsize=9)
plt.tight_layout()
plt.show()
if __name__ == "__main__":
if (len(sys.argv) == 7):
files([ sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6] ])
if (len(sys.argv) == 6):
files([ sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5] ])
elif (len(sys.argv) == 5):
files([ sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4] ])
elif (len(sys.argv) == 4):
files([ sys.argv[1],sys.argv[2],sys.argv[3] ])
elif (len(sys.argv) == 3):
files([ sys.argv[1],sys.argv[2] ])
else:
files([ sys.argv[1] ])