-
Notifications
You must be signed in to change notification settings - Fork 37
/
parallel_submitter_all_modes_models.py
131 lines (98 loc) · 3.31 KB
/
parallel_submitter_all_modes_models.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
import datetime
import glob
import os
from pcmdi_metrics.misc.scripts import parallel_submitter
from pcmdi_metrics.variability_mode.lib import sort_human
def find_latest(path):
dir_list = [p for p in glob.glob(path + "/v????????")]
return sorted(dir_list)[-1]
# ---------------------------------------------------------------
mip = "cmip6"
exp = "historical"
datadir = '/p/user_pub/pmp/pmp_results/pmp_v1.1.2/additional_xmls/latest'
param_dir = "../param"
modes = ["NAM", "SAM", "NAO", "PNA", "NPO", "PDO", "NPGO"]
case_id = "{:v%Y%m%d}".format(datetime.datetime.now())
num_workers = 40
debug = True
# ---------------------------------------------------------------
cmds_list = list()
logfilename_list = list()
for mode in modes:
if mode in ["PDO", "NPGO", "AMO"]:
var = "ts"
param_file = "myParam_demo_PDO.py"
else:
var = "psl"
param_file = "myParam_demo_NAM.py"
if mode in ["SAM"]:
osyear = 1955
else:
osyear = 1900
if mode in ["NPO", "NPGO"]:
eofn_obs = 2
eofn_mod = 2
else:
eofn_obs = 1
eofn_mod = 1
datadir_ver = find_latest(datadir)
datadir_final = os.path.join(datadir_ver, mip, exp, 'atmos', 'mon', var)
xml_list = glob.glob(os.path.join(datadir_final, '*.xml'))
# get list of models
models_list = sort_human(
[r.split("/")[-1].split(".")[2] for r in xml_list]
)
# remove repeat
models_list = sort_human(list(dict.fromkeys(models_list)))
if debug:
models_list = models_list[0:3]
print(models_list)
print(len(models_list))
for model in models_list:
file_list_model = glob.glob(os.path.join(datadir_final, '*.' + model + '.*.xml'))
runs_list = sort_human(
[
r.split("/")[-1].split(".")[3]
for r in file_list_model
]
)
if debug:
runs_list = runs_list[0:1]
print(model, runs_list)
for run in runs_list:
cmd_content = [
'variability_modes_driver.py',
'-p', os.path.join(param_dir, param_file),
'--variability_mode', mode,
'--osyear', str(osyear),
'--eofn_obs', str(eofn_obs),
'--eofn_mod', str(eofn_mod),
'--mip', mip, '--exp', exp,
'--modnames', model,
'--realization', run,
]
if model != models_list[0] or run != runs_list[0]:
cmd_content.extend(["--no_plot_obs", "--no_nc_out_obs"])
if debug:
cmd_content.append('--debug True')
cmd = ' '.join(cmd_content)
log_file = '_'.join(['variability_modes', mode, mip, exp, model, run]) + '.txt'
print(cmd)
cmds_list.append(cmd)
logfilename_list.append(log_file)
# =================================================
# Run subprocesses in parallel
# -------------------------------------------------
# log dir
log_dir = os.path.join(
"/p/user_pub/pmp/pmp_results/pmp_v1.1.2",
"log",
"variability_modes",
mip, exp, case_id)
os.makedirs(log_dir, exist_ok=True)
parallel_submitter(
cmds_list,
log_dir=log_dir,
logfilename_list=logfilename_list,
num_workers=num_workers,
)