-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
96 lines (74 loc) · 3.59 KB
/
main.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
# main.py
#################################
# packages
#################################
import ClimSIPS.function as csf
import ClimSIPS.pre_processing as cspp
import ClimSIPS.plots as csp
import sys
import configparser
def main():
print('==== starting subselection ====')
############# INPUTS for pre-processing #############
all_config = configparser.ConfigParser()
if len(sys.argv) < 3:
print("Use python main.py config_climsips.ini config_section_key [...]")
return
all_config.read(sys.argv[1])
config_key = sys.argv[2]
config = all_config[config_key]
skip_preprocessing_with=config.get('skip_preprocessing_with', fallback='')
if skip_preprocessing_with=='':
if len(sys.argv) == 4:
predictors_root = sys.argv[3]
if len(sys.argv) == 3:
predictors_root = "/net/h2o/climphys/meranna/Data/predictors/"
else:
print("Use python main.py config_climsips.ini config_section_key predictor_root_directory")
return
config = all_config[config_key]
skip_preprocessing_with=config.get('skip_preprocessing_with', fallback='')
# ensemble and representation
cmip = config['cmip']
im_or_em = config.get('im_or_em','IM')
season_region = config['season_region']
double_norm = config.getboolean('double_norm',fallback=False)
# convert subselection inputs in the config to integers
m = config.getint('m')
alpha = config.getint('alpha_steps',fallback=10)
beta = config.getint('beta_steps',fallback=10)
perf_cutoff = config.getint('perf_cutoff',fallback=10)
max_workers = config.getint('max_workers',fallback=1)
min2 = config.getboolean('min2')
#####################################################
if skip_preprocessing_with == '':
# paths to predictors
perf_path=predictors_root+'performance/'
spread_path=predictors_root+'spread/'
indep_path=predictors_root+'independence/'
# pre-processing: obtain performance, independence, and spread metrics
# TO DO: implement scenarios
scenario='SSP585'
common_models = cspp.model_soup(perf_path,indep_path,spread_path, cmip, im_or_em, season_region,double_norm,scenario)
#print(common_models)
dsDeltaQ = cspp.pre_process_perf(perf_path, cmip, im_or_em, season_region,spread_path,default_models=common_models,double_norm=double_norm)
ds_spread_metric,targets = cspp.pre_process_spread(spread_path, cmip, im_or_em, season_region,default_models=common_models)
dsWi = cspp.pre_process_indep(indep_path, cmip, im_or_em, season_region,spread_path,default_models=common_models)
# save output file
outfile = 'perf_ind_spread_metrics.nc'
csf.make_output_file(dsDeltaQ,ds_spread_metric,targets,dsWi,outfile)
else:
outfile = skip_preprocessing_with
print('skipping preprocessing with', outfile)
# predictor info
cspp.metric_information(cmip, im_or_em, season_region)
# plot components
csp.performance_order(outfile,cmip,im_or_em,season_region,plotname="performance_order.png")
csp.independence_square(outfile,cmip,im_or_em,season_region,plotname="independence_metric.png")
csp.spread_scatter(outfile,cmip,im_or_em,season_region,plotname="spread_scatter.png")
# subselection
optimal_models_csv = csf.select_models(outfile, cmip, im_or_em, season_region, m, alpha, beta, perf_cutoff, max_workers=max_workers, min2=min2)
csp.selection_triangle(optimal_models_csv,alpha,plotname="optimal_subsets.png")
print('---- subselection complete ----')
if __name__ == '__main__':
main()