-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate_Excel.py
224 lines (177 loc) · 8.23 KB
/
Create_Excel.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
from telnetlib import DO
import numpy as np
import pandas as pd
import glob
import matplotlib.pyplot as plt
import plotly.express as px
from plotly.subplots import make_subplots
from dash import Dash, dcc, html, Input, Output
R = str(15000)
Double_File = True
PSG_Directory = "/Users/elitzer/Desktop/PSG/NASA_PSG-main/Final_Data/"
# atm_1ppb_failed = PSG_Directory + '1ppb_atmosphere/try/'
Atmosphere = PSG_Directory + 'Atmosphere'
Lakes = PSG_Directory + 'Lakes/'
Ices = PSG_Directory + 'Ice/'
Full_File1a = PSG_Directory + 'Basic_Titan_Configuration/' + 'Atmosphere/' + 'Base_Titan_Atmosphere_SR1' + '.txt'
Full_File2a = PSG_Directory + 'Basic_Titan_Configuration/' + 'Atmosphere/'+ 'Base_Titan_Atmosphere_SR2' + '.txt'
Full_File1l = PSG_Directory + 'Basic_Titan_Configuration/' + 'LakesIce/' + 'Base_Titan_Atmosphere_SR1' + '.txt'
Full_File2l = PSG_Directory + 'Basic_Titan_Configuration/' + 'LakesIce/' + 'Base_Titan_Atmosphere_SR2' + '.txt'
Full_File = PSG_Directory + 'Basic_Titan_Configuration/' + 'Base_Titan_Atmosphere_SR' + '.txt'
def Load_Spec(file, data_type):
# print(file[-:-4])
(Data_array) = np.genfromtxt(file, comments="#", dtype=np.float64, names=['Wavelength', 'Spectral_Radiance','Noise', 'Titan'])
Data_array = np.array(Data_array)
Data_array = Data_array[data_type]
return Data_array
# Titan_Full = np.genfromtxt(Full_File, comments="#", dtype=np.float64, names=['Wavelength', 'Spectral_Radiance','Noise', 'Titan'])
if Double_File == True:
Wavelength1 = Load_Spec(Full_File1a, 'Wavelength')
Wavelength2 = Load_Spec(Full_File2a, 'Wavelength')
Wavelength = np.concatenate((Wavelength1, Wavelength2))
Titan_SR1 = Load_Spec(Full_File1a, 'Spectral_Radiance')
Titan_SR2 = Load_Spec(Full_File2a, 'Spectral_Radiance')
Titan_SRa = np.concatenate((Titan_SR1, Titan_SR2))
Titan_SR1 = Load_Spec(Full_File1l, 'Spectral_Radiance')
Titan_SR2 = Load_Spec(Full_File2l, 'Spectral_Radiance')
Titan_SRl = np.concatenate((Titan_SR1, Titan_SR2))
else:
Wavelength = Load_Spec(Full_File, 'Wavelength')
Titan_SR=Load_Spec(Full_File, 'Spectral_Radiance')
def files_from_dir(dir_PATH, molecule_type, data_dict_diff, data_dict, Ratio, types):
# Pull files from directory specified from dir_PATH and add molecule name to Ratio,
# Spectral radience data to data_dict and molecule type (atmosphere, surface, lakes, ices) to types
if molecule_type == 'Atmosphere':
Titan_SR = Titan_SRa
else:
Titan_SR = Titan_SRl
files = sorted(glob.glob(dir_PATH + '*.txt'))
# print(files)
for i, filename in enumerate(files):
if Double_File==False:
species = filename[len(dir_PATH):-5]
Ratio.append(species)
data1 = Load_Spec(filename, 'Spectral_Radiance')
# data2 = Load_Spec(files[i+1], 'Spectral_Radiance')
# data = np.concatenate((data1, data2))
# data_dict_diff[species] = data - Titan_SR
# data_dict[species] = data
data1 = np.array(data1)
data_dict_diff.append(data1 - Titan_SR)
data_dict.append(data1)
types[species] = molecule_type
elif ((i % 2) ==0) & (i !=len(files)): #if i odd:
species = filename[len(dir_PATH):-5]
Ratio.append(species)
data1 = Load_Spec(filename, 'Spectral_Radiance')
data2 = Load_Spec(files[i+1], 'Spectral_Radiance')
data = np.concatenate((data1, data2))
# data_dict_diff[species] = data - Titan_SR
# data_dict[species] = data
data_dict_diff.append(np.absolute(data - Titan_SR))
data_dict.append(data)
types[species] = molecule_type
return data_dict_diff, data_dict, Ratio, types #, data
# Initiallize empty dicts and lists to be filled when loading in data
Ratio = []
data_dict_diff = [] #{}
data_dict = [] #{}
types = {}
# Load in files from directories. Identify where the molecule is on Titan
# data_dict_diff, data_dict, Ratio, types = files_from_dir(Atmosphere, 'Atmosphere', data_dict_diff, data_dict, Ratio, types)
# data_dict_diff, data_dict, Ratio, types = files_from_dir(Lakes, 'Lakes', data_dict_diff, data_dict, Ratio, types)
data_dict_diff, data_dict, Ratio, types = files_from_dir(Ices, 'Ice', data_dict_diff, data_dict, Ratio, types)
Ratio = np.array(Ratio)
print(data_dict_diff)
# df_diff = pd.DataFrame(data_array_diff.T, index=Wavelength, columns=Ratio[np_mask])
data_dict = np.array(data_dict)
data_dict_diff = np.array(data_dict_diff)
Titan_SR = np.array(Titan_SRa)
pddf_diff = pd.DataFrame(data= data_dict_diff.T,
columns = Ratio,
index = Wavelength)
pddf = pd.DataFrame(data= data_dict.T,
columns = Ratio,
index = Wavelength)
titan_pf = pd.DataFrame(data= Titan_SR.T,
columns = ['Titan_SR'],
index = Wavelength)
with pd.ExcelWriter('Excel/' + 'Atmosphere_diff_R15000' + '.xlsx') as writer:
pddf.to_excel(writer, sheet_name='Atmosphere')
pddf_diff.to_excel(writer, sheet_name='Atmosphere_Diff')
titan_pf.to_excel(writer, sheet_name='Titan_SR')
print("done")
"""
fig = plt.figure(dpi=300) #, figsize=(10, 2))
N = len(data_dict) + 1
colors = plt.cm.jet(np.linspace(0,1,N))
for i, Isotope in enumerate(data_dict):
r = Ratio[i]
plt.plot(Wavelength, data_dict[i], label=( r), color=colors[i+1], linewidth=.75, alpha=1)
# plt.plot(Wavelength, Titan_SR, label='Titan SR', color=colors[1], linewidth=.75, alpha=1)
plt.title("Base Titan Configuration Spectral Radiance")
plt.ylabel("Spectral Radiance"+ r' ($\frac{W}{sr *m^2 *µm}$)')
plt.xlabel("Wavelength" + ' (µm)')
plt.yscale('log')
plt.xlim(4.5,5)
plt.ylim(1e-3,5e-3)
plt.legend()
plt.tight_layout()
# fig.savefig("Figures/" + 'Lakes_Log' + ".png", dpi=300)
plt.show()
# ----
# Create dash app with interactive plot of data
app = Dash(__name__)
app.layout = html.Div(children=[
html.Div([
html.H4('Molecules on Titan: A Comparison with a Standard Titan Atmosphere'),
dcc.Graph(id='Diff'),
dcc.Graph(id='Full'),
dcc.Interval(
id='interval-component',
interval=15000,
),
dcc.Checklist(
id='checklist',
options=['Atmosphere', 'Lakes', 'Ice'],
value=['Atmosphere', 'Lakes', 'Ice'],
inline=True
)]),
])
@app.callback(
Output("Diff", "figure"),
Input('checklist', 'value')
)
def update_line_chart1(pick_type):
np_mask = np.isin(list(types.values()), pick_type)
data_array_diff = np.array(data_dict_diff)
# data_array_diff = np.array(list(data_dict_diff.values()), dtype=object)
data_array_diff = data_array_diff[np_mask]
# print(data_array_diff.shape)
df_diff = pd.DataFrame(data_array_diff.T, index=Wavelength, columns=Ratio[np_mask])
# fig1 = px.line(data_array_diff, x = Wavelength, y=data_array_diff, title='Titan Molecule Spectra Comparison with Basic Titan Model', log_y=False)
fig1 = px.line(df_diff, title='Titan Molecule Spectra Comparison with Basic Titan Model', log_y=True, labels=dict(index=('Wavelength (µm)'), value=("Spectral Radiance W/(sr*m^2*µm)"), variable='Molecule'))
# for i, newname in enumerate(Ratio[np_mask]):
# fig1.data[i].name = newname
return fig1#.write_html("SR_dif.html")
@app.callback(
Output("Full", "figure"),
Input('checklist', 'value')
)
def update_line_chart2(pick_type):
np_mask = np.isin(list(types.values()), pick_type)
data_array = np.array(data_dict)
# data_array = np.array(list(data_dict.values()), dtype=object)
data_array = data_array[np_mask]
# print(np_mask)
# Wavelength_rep= np.tile(Wavelength, (12, 1))
# print("wav",Wavelength_rep.shape, np_mask)
# for i in range(0, len(np_mask)):
df = pd.DataFrame(data_array.T, index=Wavelength, columns=Ratio[np_mask])
# fig2 = px.line(data_array, x = Wavelength, y=data_array, title='Titan Molecule Spectral Radience', log_y=False)
fig2 = px.line(df, title='Titan Molecule Spectral Radience', log_y=False, labels=dict(index=('Wavelength (µm)'), value=("Spectral Radiance W/(sr*m^2*µm)"), variable='Molecule'))
# for i, newname in enumerate(Ratio[np_mask]):
# fig2.data[i].name = newname
return fig2#.write_html("SR.html")
app.run_server(debug=True)
# """