-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathui.py
96 lines (86 loc) · 4.05 KB
/
ui.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
"""
User interfaces for the nek-analyze script
Currently, there is only a command line interface
"""
def command_line_ui():
"""
Command line interface for nek-analyze
Uses python's ArgumentParser to read the command line and then creates
shortcuts for common argument combinations
"""
# grab defaults from config files
from os.path import exists, expanduser, join
import json
defaults = {"mapreduce" : "MapReduce", "post": "post"}
if exists(join(expanduser("~"), ".nek-analyze.json")):
with open(join(expanduser("~"), ".nek-analyze.json")) as f:
defaults.update(json.load(f))
else:
with open(join(expanduser("~"), ".nek-analyze.json"), 'w') as f:
json.dump(defaults, f)
# Define arguments
from argparse import ArgumentParser
p = ArgumentParser()
p.add_argument("name",
help="Nek *.fld output file")
p.add_argument("-f", "--frame", type=int, default=1,
help="[Starting] Frame number")
p.add_argument("-e", "--frame_end", type=int, default=-1,
help="Ending frame number")
p.add_argument("-s", "--slice", action="store_true",
help="Display slice")
p.add_argument("-c", "--contour", action="store_true",
help="Display contour")
p.add_argument("-n", "--ninterp", type=float, default = 1.,
help="Interpolating order")
p.add_argument("-z", "--mixing_zone", action="store_true",
help="Compute mixing zone width")
p.add_argument("-m", "--mixing_cdf", action="store_true",
help="Plot CDF of box temps")
p.add_argument("-F", "--Fourier", action="store_true",
help="Plot Fourier spectrum in x-y")
p.add_argument("-b", "--boxes", action="store_true",
help="Compute box covering numbers")
p.add_argument("-nb", "--block", type=int, default=65536,
help="Number of elements to process at a time")
p.add_argument("-nt", "--thread", type=int, default=1,
help="Number of threads to spawn")
p.add_argument("-d", "--display", action="store_true", default=False,
help="Display plots with X")
p.add_argument("-p", "--parallel", action="store_true", default=False,
help="Use parallel map (IPython)")
p.add_argument( "--series", action="store_true", default=False,
help="Apply time-series analyses")
p.add_argument("--mapreduce", default=defaults["mapreduce"],
help="Module containing Map and Reduce implementations")
p.add_argument("--post", default=defaults["post"],
help="Module containing post_frame and post_series")
p.add_argument("-v", "--verbose", action="store_true", default=False,
help="Should I be really verbose, that is: wordy?")
p.add_argument("--params", dest="param_path", default=None,
help="Location of param file")
p.add_argument("--chest", dest="chest_path", default=None,
help="Location of chest directory")
p.add_argument("--figs", dest="fig_path", default=None,
help="Location of figures")
p.add_argument("--MR_init", default=None,
help="MapReduce init function. Loaded from --mapreduce if None.")
p.add_argument("--reduce", default=None,
help="Reduce function. Loaded from --mapreduce if None.")
p.add_argument("--map", default=None,
help="Map function. Loaded from --mapreduce if None.")
p.add_argument("--single_pos", default=False, action="store_true",
help="Position only in first output")
# Load the arguments
args = p.parse_args()
if args.frame_end == -1:
args.frame_end = args.frame
args.series = (args.frame != args.frame_end) or args.series
from os.path import dirname
if args.param_path is None:
args.param_path = "{:s}.json".format(args.name)
if args.chest_path is None:
args.chest_path = "{:s}-results".format(args.name)
if args.fig_path is None:
args.fig_path = "{:s}".format(dirname(args.name))
return args