-
Notifications
You must be signed in to change notification settings - Fork 37
/
argparse_functions.py
252 lines (243 loc) · 7.32 KB
/
argparse_functions.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
import datetime
def AddParserArgument(P):
# Load pre-defined parsers
# P.use("--mip")
# P.use("--exp")
P.use("--results_dir")
P.use("--reference_data_path")
P.use("--modpath")
# Add parsers
P.add_argument(
"--mip",
type=str,
default="cmip5",
help="A WCRP MIP project such as CMIP3 and CMIP5",
)
P.add_argument(
"--exp",
type=str,
default="historical",
help="An experiment such as amip, historical or piContorl",
)
P.add_argument("--frequency", default="mo")
P.add_argument("--realm", default="atm")
P.add_argument("--reference_data_name", type=str, help="Name of reference data set")
P.add_argument(
"-v",
"--variability_mode",
type=str,
default="NAO",
help="Mode of variability: NAM, NAO, SAM, PNA, PDO, NPO, NPGO, AMO\n"
"- NAM: Northern Annular Mode\n"
"- NAO: Northern Atlantic Oscillation\n"
"- SAM: Southern Annular Mode\n"
"- PNA: Pacific North American Pattern\n"
"- PDO: Pacific Decadal Oscillation\n"
"- NPO: North Pacific Oscillation\n"
"- NPGO: North Pacific Gyre Oscillation\n"
"- AMO: Atlantic Multidecadal Oscillation\n"
"(Note: Case insensitive)",
)
P.add_argument(
"--seasons", type=str, nargs="+", default=None, help="List of seasons"
)
P.add_argument(
"--modnames",
type=str,
nargs="+",
default=None,
help="List of models. 'all' for every available models",
)
P.add_argument(
"-r",
"--realization",
type=str,
default="r1i1p1",
help="Consider all accessible realizations as idividual\n"
"- r1i1p1: default, consider only 'r1i1p1' member\n"
" Or, specify realization, e.g, r3i1p1'\n"
"- *: consider all available realizations",
)
P.add_argument(
"--modpath_lf",
type=str,
dest="modpath_lf",
help="Directory path to model land fraction field",
)
P.add_argument("--varOBS", type=str, help="Name of variable in reference data")
P.add_argument("--varModel", type=str, help="Name of variable in model(s)")
P.add_argument(
"--eofn_obs", type=int, default=1, help="EOF mode from observation as reference"
)
P.add_argument("--eofn_mod", type=int, default=1, help="EOF mode from model")
P.add_argument(
"--osyear", type=int, default=1900, help="Start year for reference data"
)
P.add_argument(
"--oeyear", type=int, default=2005, help="End year for reference data"
)
P.add_argument("--msyear", type=int, default=1900, help="Start year for model(s)")
P.add_argument("--meyear", type=int, default=2005, help="End year for model(s)")
P.add_argument(
"--ObsUnitsAdjust",
type=tuple,
default=(False, 0, 0),
help="For unit adjust for OBS dataset. For example:\n"
"- (True, 'divide', 100.0) # Pa to hPa\n"
"- (True, 'subtract', 273.15) # degK to degC\n"
"- (False, 0, 0) # No adjustment (default)",
)
P.add_argument(
"--ModUnitsAdjust",
type=tuple,
default=(False, 0, 0),
help="For unit adjust for model dataset. For example:\n"
"- (True, 'divide', 100.0) # Pa to hPa\n"
"- (True, 'subtract', 273.15) # degK to degC\n"
"- (False, 0, 0) # No adjustment (default)",
)
P.add_argument(
"--case_id",
type=str,
dest="case_id",
default="{:v%Y%m%d}".format(datetime.datetime.now()),
help="version as date, e.g., v20191116 (yyyy-mm-dd)",
)
# Switches
P.add_argument(
"-d",
"--debug",
type=bool,
default=False,
help="Option for debug: True / False (defualt)",
)
P.add_argument(
"--RemoveDomainMean",
type=bool,
default=True,
help="Option for Remove Domain Mean from each time step: True (defualt)/ False",
)
P.add_argument(
"--EofScaling",
type=bool,
default=False,
help="Option for Consider EOF with unit variance: True / False (default)",
)
P.add_argument(
"--landmask",
type=bool,
default=False,
help="Option for maskout land region: True / False (default)",
)
P.add_argument(
"--ConvEOF",
type=bool,
default=False,
help="Option for Calculate Conventioanl EOF for model: True / False (default)",
)
P.add_argument(
"--CBF",
type=bool,
default=True,
help="Option for Calculate Common Basis Function (CBF) for model: True (default) / False",
)
P.add_argument(
"--nc_out",
type=bool,
default=True,
help="Option for generate netCDF file output for models: True (default) / False",
)
P.add_argument(
"--plot",
type=bool,
default=True,
help="Option for generate individual plots for models: True (default) / False",
)
P.add_argument(
"--nc_out_obs",
type=bool,
default=True,
help="Option for generate netCDF file output for obs: True (default) / False",
)
P.add_argument(
"--plot_obs",
type=bool,
default=True,
help="Option for generate individual plots for obs: True (default) / False",
)
P.add_argument(
"--parallel",
type=bool,
dest="parallel",
default=False,
help="Option for running code in parallel mode: True / False (default)",
)
P.add_argument(
"--no_nc_out_obs",
dest="nc_out_obs",
action="store_false",
help="Turn off netCDF generating for obs",
)
P.add_argument(
"--no_plot_obs",
dest="plot_obs",
action="store_false",
help="Turn off plot generating for obs",
)
P.add_argument(
"--update_json",
type=bool,
default=True,
help="Option for update existing JSON file: True (i.e., update) (default) / False (i.e., overwrite)",
)
P.add_argument(
"--cmec",
dest="cmec",
action="store_true",
default=False,
help="Save metrics in CMEC format",
)
P.add_argument(
"--no_cmec",
dest="cmec",
action="store_false",
default=False,
help="Option to not save metrics in CMEC format",
)
P.set_defaults(nc_out_obs=True, plot_obs=True)
return P
def VariabilityModeCheck(mode, P):
if mode is None:
P.error("VARIABILITY_MODE is NOT defined")
else:
if mode.upper() not in [
"NAM",
"NAO",
"SAM",
"PNA",
"PDO",
"NPO",
"NPGO",
"AMO",
]:
P.error(
"".join(
[
"Given VARIABILITY_MODE, ",
mode,
", is NOT correct. ",
'Please refer help document by using "-h" option',
]
)
)
return mode.upper()
def YearCheck(syear, eyear, P):
if syear >= eyear:
P.error(
"Given starting year, "
+ str(syear)
+ ", is later than given ending year, "
+ str(eyear)
)
else:
pass