-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinversion_params.py
400 lines (369 loc) · 13.7 KB
/
inversion_params.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# -*- coding: utf-8 -*-
import ipywidgets as widgets
from IPython.display import display, clear_output
from widgets import sens_query
style = {"description_width": "initial"}
sens = sens_query.SearchSens()
class InversionParams(widgets.VBox):
def __init__(self):
# GENERAL
####################################
self.inv_name = widgets.Text(description="run.str", style=style)
self.project = widgets.Text(
description="project", value="HFO-Europe", style=style
)
self.institute = widgets.Text(
description="institute", value="Empa, Switzerland", style=style
)
self.chunk = widgets.Dropdown(
description="chunk", options=["year", "month"], style=style
)
self.chunk.observe(self.change_chunk_w_options, names="value")
self.chunk_w = widgets.Dropdown(
description="chunk_w",
options=["year", "3year"],
style=style,
)
self.general_settings = [
self.inv_name,
self.project,
self.institute,
]
general = widgets.VBox(
children=self.general_settings+[self.chunk,
self.chunk_w]
)
# INPUT LOCATIONS
########################################
self.ftp_dir = widgets.Text(
description="ftp.dir",
value="tmp",
layout=widgets.Layout(width="85%"),
)
self.pop_data_dir = widgets.Text(
description="pop.data.dir",
value="/store/empa/em05/input/GIS/population",
layout=widgets.Layout(width="85%"),
)
self.bot_up_file = widgets.Text(
description="bot.up.file",
value="/users/shenne/progs/Rinversion/data/example.bot.up.file.csv",
layout=widgets.Layout(width="85%"),
)
self.cmask_file = widgets.Text(
description="cmask.file",
value="/project/s1302/shenne/PARIS/CH4_inversions/Country_masks/country_EUROPE_EEZ_PARIS_gapfilled_fractional.nc",
layout=widgets.Layout(width="85%"),
)
self.input_locations = [
self.ftp_dir,
self.pop_data_dir,
self.bot_up_file,
self.cmask_file,
]
input_loc = widgets.VBox(children=self.input_locations)
# INVERSION GRID
#######################################
self.igr_fn = widgets.Text(
description="igr.fn",
value="/home/hes134/projects/inversion/GEOmon/emission_grid_brunner.txt",
layout=widgets.Layout(width="60%"),
)
self.xrng = widgets.FloatRangeSlider(
description="xrng",
value=[-13.0, 26.4],
min=-180,
max=180,
layout=widgets.Layout(width="60%"),
)
self.yrng = widgets.FloatRangeSlider(
description="yrng",
value=[36.0, 70.0],
min=-90,
max=90,
layout=widgets.Layout(width="60%"),
)
self.nn_grid_target = widgets.IntText(description="nn.grid.target", value=700)
self.min_tau = widgets.IntText(description="min.tau", value=86400)
self.igr_merge = widgets.IntSlider(
description="igr.merge", value=6, min=0, max=10
)
self.remove_zero_only = widgets.Checkbox(
description="remove.zero.only", value=True
)
self.remove_pure_ocean = widgets.Checkbox(
description="remove.pure.ocean", value=True
)
self.fromaverage = [
self.xrng,
self.yrng,
self.nn_grid_target,
self.min_tau,
self.igr_merge,
self.remove_zero_only,
self.remove_pure_ocean,
]
fromaverage = widgets.VBox(children=self.fromaverage)
self.load = [self.igr_fn]
fromload = widgets.VBox(children=self.load)
def select_option_inv_grid(igr_method):
if igr_method == "fromAverage":
display(fromaverage)
return
elif igr_method == "load":
display(fromload)
return
else:
clear_output()
self.igr_method = widgets.interactive(
select_option_inv_grid, igr_method=["fromAverage", "load"]
)
inv_grid = widgets.VBox(children=[self.igr_method])
# APRIORI
#######################################
self.EDGAR_dir = widgets.Text(
description="EDGAR.dir", value="/store/empa/em05/input/EDGAR"
)
self.edgar_version = widgets.Text(
description="edgar.version", value="8.0_FT2022_GHG"
)
self.edgar_year = widgets.IntText(description="edgar.year", value=2020)
self.rescale_EDGAR = widgets.Checkbox(description="rescale.EDGAR", value=False)
self.apriori_edgar = [
self.EDGAR_dir,
self.edgar_version,
self.edgar_year,
self.rescale_EDGAR,
]
edgar = widgets.VBox(children=self.apriori_edgar)
self.apriori_dir = widgets.Text(
description="apriori.dir",
value="/project/s1302/shenne/PARIS/HFO_inversions/apriori/population",
)
self.apriori_str = widgets.Text(
description="apriori.str", value="<para>_EUROPE_<year>.nc"
)
self.apriori_load = [self.apriori_dir, self.apriori_str]
load = widgets.VBox(children=self.apriori_load)
self.apriori_lsm = widgets.Checkbox(description="apriori.lsm", value=True)
self.homo_by_country = widgets.Checkbox(
description="homo.by.country", value=False
)
self.apriori_homo = [self.apriori_lsm, self.homo_by_country]
homo = widgets.VBox(children=self.apriori_homo)
def select_option(apriori_method):
if apriori_method == "EDGAR":
display(edgar)
return
elif apriori_method == "load" or apriori_method == "load_nc":
display(load)
return
elif apriori_method == "homo":
display(homo)
return
else:
clear_output()
self.x = widgets.interactive(
select_option,
apriori_method=["EDGAR", "load", "load_nc", "homo"],
)
# APRIORI COVARIANCE
########################################
self.u_apriori0 = widgets.FloatText(
description="u.apriori0",
value=3,
)
self.max_dist = widgets.FloatText(
description="max.dist",
value=500.0,
)
self.tau_bg = widgets.FloatText(
description="tau.bg",
value=60.0,
)
self.u_outer = widgets.FloatText(
description="u.outer",
value=0.2,
)
self.apriori_covariance = [
self.u_apriori0,
self.max_dist,
self.tau_bg,
self.u_outer,
]
ap_cov = widgets.VBox(children=self.apriori_covariance)
# PLOT OPTIONS
#########################################
self.zlim = widgets.Text(description="zlim", value="[1.0, 1.0e+04]")
self.ts_units = widgets.Dropdown(
description="ts.units", options=["ppt", "ppb", "ppm"]
)
self.frmt = widgets.Dropdown(description="frmt", options=["png16m", "eps"])
self.map_db = widgets.Text(description="map.db", value="world.TM")
self.map_source = widgets.Text(description="map.source", value="myRplots")
self.cities = widgets.Checkbox(description="cities", value=False)
self.plot_options = [
self.zlim,
self.ts_units,
self.frmt,
self.map_db,
self.map_source,
self.cities,
]
plot_op = widgets.VBox(children=self.plot_options)
# INVERSION SETTINGS
#########################################
use_covariances = widgets.Checkbox(description="use.covariances", value=True)
positive = widgets.Dropdown(
description="positive",
options=["Thacker_complete", "Stohl", "Thacker_xOnly", "none"],
)
maxit = widgets.IntText(description="maxit", value=100)
neg_frac = widgets.FloatText(description="neg.frac", value=0.0005)
unc_lt0 = widgets.FloatText(description="unc.lt0", value=0.5)
unc_gt0 = widgets.FloatText(description="unc.gt0", value=1.01)
use_lsm = widgets.Checkbox(description="use.lsm", value=False)
incl_bg = widgets.Checkbox(description="incl.bg", value=True)
bg_by = widgets.Text(description="bg.by", value="months")
bg_type = widgets.Dropdown(
description="bg.type",
options=[
"boundaries.11reg",
"single",
"boundaries",
],
)
bg_by_site = widgets.Checkbox(description="bg.by.site", value=False)
bg_fac = widgets.Checkbox(description="bg.fac", value=False)
incl_outer = widgets.Checkbox(description="incl.outer", value=True)
self.inversion_settings = [
use_covariances,
positive,
maxit,
neg_frac,
unc_lt0,
unc_gt0,
use_lsm,
incl_bg,
bg_by,
bg_type,
bg_by_site,
bg_fac,
incl_outer,
]
inv_settings = widgets.VBox(children=self.inversion_settings)
# MODEL-DATA-MISMATCH COVARIANCE
############################################
self.obs_mod_unc_contrs = widgets.SelectMultiple(
description="obs.mod.unc.contrs",
options=["mod", "instr", "bg", "var"],
value=["mod", "instr", "bg", "var"],
style=style,
)
self.iterations = widgets.IntText(description="it.u.obs", value=4, style=style)
self.u_model = widgets.Checkbox(
value=True, description="scale.u.model", style=style
)
self.plot = widgets.Checkbox(
value=True, description="plot.obs.mod.unc", style=style
)
self.dist_adj_method = widgets.Dropdown(
description="dist.adj.method",
options=["relative", "rmsOnly", "Stohl"],
style=style
)
self.tau_obs = widgets.FloatText(description="tau.obs.default", style=style,value=0.2)
# TODO inclue none value
self.covar_nn_lag = widgets.IntSlider(
description="covar.nn.lag",
value=2,
min=1,
max=24,
)
self.model_data_mismatch = [
self.obs_mod_unc_contrs,
self.iterations,
self.u_model,
self.plot,
self.dist_adj_method,
self.tau_obs,
self.covar_nn_lag,
]
model_mis = widgets.VBox(children=self.model_data_mismatch)
############################################
tab = widgets.Tab()
tab.children = [
general,
input_loc,
inv_grid,
inv_settings,
model_mis,
self.x,
ap_cov,
plot_op,
]
tab.titles = [
"General",
"Input locations",
"Inversion grid",
"Inversion settings",
"Model-data-mismatch",
"Apriori",
"Apriori covariance",
"Plot options",
]
super().__init__([tab])
def change_chunk_w_options(self, change=None):
value = change["new"]
if value == "year":
self.chunk_w.options = ["year", "3year"]
else:
self.chunk_w.options = ["month", "3month"]
def construct_dict(self):
sites_dict = {"sites": sens.available_obs_list}
d = {x.description: x.value for x in self.create_attributes_list()}
# hardcoded dictionary
d.update(
{
"Interactive": False,
"main.dir": "",
"init.dir": "",
"data.dir": "",
"igr.method": self.igr_method.children[0].value,
"apriori.method": self.x.children[0].value,
}
)
d.update(sites_dict)
return d
def create_attributes_list(self):
big_list = [
*self.inversion_settings,
*self.general_settings,
*self.input_locations,
*self.model_data_mismatch,
*self.plot_options,
*self.apriori_covariance,
]
if self.x.children[0].value == "EDGAR":
big_list += self.apriori_edgar
elif self.x.children[0].value == "load":
big_list += self.apriori_load
elif self.x.children[0].value == "homo":
big_list += self.apriori_homo
if self.igr_method.children[0].value == "fromAverage":
big_list += self.fromaverage
elif self.igr_method.children[0].value == "load":
big_list += self.load
return big_list+[self.igr_method.children[0],
self.x.children[0],
]
def update(self, new_dict):
new_dict_reformated = {
key.replace("_", "."): value for key, value in new_dict.items()
}
new_dict_reformated['igr_method'] = new_dict_reformated['igr.method']
new_dict_reformated['apriori_method'] = new_dict_reformated['apriori.method']
for wg in self.create_attributes_list()+[self.chunk,
self.chunk_w]:
if wg.description in new_dict_reformated.keys():
wg.value = new_dict_reformated[wg.description]