forked from meereeum/k-meanz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
argparser.py
51 lines (43 loc) · 2.33 KB
/
argparser.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
import argparse
import os
class setBool(argparse.Action):
"""extends Action to enable parsing of `fuzzy` boolean user inputs"""
def __call__(self, parser, namespace, values, option_string=None):
fuzzy_true = ("yes", "true", "t", "1")
boolean = (values.lower() in fuzzy_true)
setattr(namespace, self.dest, boolean)
def parse_args():
parser = argparse.ArgumentParser()
DEFAULTS = {"k": 50,
"rounds": 5,
"outdir": ".",
"scale": True,
"generate_all": False,
"data_saving": False}
# positional args
parser.add_argument("input", help = "path/to/input/file")
# optional args
parser.add_argument("-k", "--k", type = int, default = DEFAULTS["k"],
help = "number of centroids (default={})".\
format(DEFAULTS["k"]))
parser.add_argument("-r", "--rounds", type = int, default = DEFAULTS["rounds"],
help = "number of rounds of clustering (default={})".\
format(DEFAULTS["rounds"]))
parser.add_argument("-o", "--outdir", default = DEFAULTS["outdir"],
help = "path/to/output/directory (default={})".\
format(DEFAULTS["outdir"]))
parser.add_argument("-s", "--scale", default = DEFAULTS["scale"],
help = "T/F: scale pixel location to be equitable with RGB vals? \
(default={})".format(DEFAULTS["scale"]), action = setBool)
parser.add_argument("-g", "--generate_all", default = DEFAULTS["generate_all"],
help = "T/F: generate image after each round? (slower) \
(default={})".format(DEFAULTS["generate_all"]), action = setBool)
parser.add_argument("-d", "--data_saving", default = DEFAULTS["data_saving"],
help = "T/F: save clustering data as .txt? \
(centroids, cluster sizes, dimensions) (default={})".\
format(DEFAULTS["data_saving"]), action = setBool)
d_args = vars(parser.parse_args())
positional_args = [arg.dest for arg in parser._get_positional_actions()]
args = [d_args[k] for k in positional_args]
kwargs = {k: v for k,v in d_args.iteritems() if k not in positional_args}
return (args, kwargs)