-
Notifications
You must be signed in to change notification settings - Fork 37
/
common.py
64 lines (57 loc) · 2.37 KB
/
common.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
import genutil
import argparse
from pcmdi_metrics.driver.pmp_parser import PMPParser
monthname_d = {1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun',
7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec'}
class INPUT(object):
def __init__(self, args, filename, filename_template, varname="pr"):
self.fileName = filename
self.args = args
self.monthname = monthname_d[args.month]
self.varname = varname
self.template = filename_template
def populateStringConstructor(template, args):
template = genutil.StringConstructor(template)
for k in template.keys():
if hasattr(args, k):
setattr(template, k, str(getattr(args, k)))
return template
P = PMPParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
P.add_argument("-i", "--modroot",
default='data',
help="Root directory for model (or observed) 3-hourly data")
P.add_argument("-m", "--month",
type=int,
default=7,
help="Month to be processed, given as 2-char month number")
P.add_argument("-f", "--firstyear",
type=int,
default=1999,
help="First year of data processing")
P.add_argument("-l", "--lastyear",
type=int,
default=2005,
help="Last year of data processing")
P.add_argument("-o", "--output_directory",
default="out",
help="output directory")
P.add_argument("-r", "--realization",
default="r1i1p1",
help="Realization used")
P.add_argument("-w", "--num-workers", default=None, type=int,
help="number of workers to use in multiprocessing, 0 means auto")
P.add_argument("--version", default="*")
P.add_argument("--frequency", default="3hr")
P.add_argument("--realm", default="atm")
P.add_argument("--model", default="*")
P.add_argument("--experiment", default="historical")
P.add_argument("-t", "--filename_template",
default="cmip5.%(model).%(experiment).%(realization).%(frequency).%(realm).%(frequency).%(variable).%(version).latestX.xml") # noqa
P.add_argument("--skip", default=[],
help="models to skip", nargs="*")
P.add_argument(
"-a",
"--append",
default=False,
action="store_true",
help="append in json file if json exist (e.g. adding a model to file)")