-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_config
executable file
·97 lines (75 loc) · 2.51 KB
/
process_config
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
#!/usr/bin/env python
# -*- mode:python -*-
import argparse
import json
import netCDF4 as nc
from collections import OrderedDict
#import os
#import shlex
#import shutil
#import subprocess
#import sys
import re
import flo_utils as fu
def read_config(options):
if not type(options) is dict:
options = vars(options)
config = json.load(open(options["config"],"r"))
overrides_file = config["config_override"]
if "overrides_file" in options.keys():
overrides_file = options["overrides_file"]
overrides = nc.Dataset(overrides_file, "r")
overrides = overrides.variables["pism_overrides"]
atts = overrides.ncattrs()
nc_config = {x: overrides.getncattr(x) for x in atts}
for x in nc_config.keys():
config[x] = nc_config[x]
return config
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="verbose output",
action="store_true", default = False)
parser.add_argument("-c", "--config", help="run_pism config file", default=None)
parser.add_argument("-o", "--overrides_file", help="pism output or override file", default=None)
options = parser.parse_args()
if options.verbose:
fu.debug = True
options_dict = vars(options)
return (options, options_dict)
def process_config(pism_config):
my_config = json.load(open("/home/flo/Apps/bin/process_config.conf","r"))
order=my_config["order"]
del my_config["order"]
direct = my_config["direct"]
del my_config["direct"]
out_dict = OrderedDict()
for x in order:
out_dict[x] = OrderedDict()
for y in my_config[x]:
val=pism_config.get(y, "N/A")
out_dict[x][y]=val
print ""
return out_dict
def texesc(text):
return re.sub(",", ", ", re.sub("_","\\_", text))
def texprint(out_dict):
output=[]
for x in out_dict.keys():
output.append( "\\midrule")
output.append( "\\multicolumn{2}{c}{%s}\\\\"%(texesc(x)))
output.append( "\\midrule")
for y in out_dict[x].keys():
val = out_dict[x][y]
if val == False:
val = "no"
elif val == True:
val = "yes"
output.append( "%s & %s\\\\"%(texesc(y), texesc(str(val))))
return "\n".join(output)
def main():
(options, options_dict) = parse_args()
pism_config = read_config(options)
out_dict = process_config(pism_config)
print texprint(out_dict)
if __name__ == "__main__":
main()