-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseevis.py
More file actions
99 lines (82 loc) · 3.13 KB
/
Copy pathseevis.py
File metadata and controls
99 lines (82 loc) · 3.13 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import arghelper
from arghelper import inputfile
from arghelper import inputdir
from arghelper import check_range
import os
import sys
from functions import *
class SeevisParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write("> error: %s\n" % message)
self.print_help()
sys.exit(2)
def main(argv=None):
'''
Handles the parsing of arguments
'''
parser = SeevisParser(
prog="SEEVIS",
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""----------------------------------------------
SEEVIS - (S)egmentation-Fr(EE)(VIS)ualisation
----------------------------------------------
Hattab et al. Under the MIT License. """,
epilog="""
Usage examples:
./seevis.py -i img_directory/
./seevis.py -f filename.csv -s 2
""")
# Arguments to be handled
parser.add_argument("-v", "--version", action="version", version="%(prog)s"
"1.0\n")
parser.add_argument("-i", "--input", default=None, metavar="dir", help="run "
"SeeVIS on the supplied "
"directory", type=lambda x: arghelper.inputdir(parser, x))
parser.add_argument("-f", "--file", default=None, help="run "
"the Visualisation of SeeVIS", type=inputfile)
parser.add_argument("-s", help="run colour scheme"
"ranging from 1 to 3 "
"(default is 1)", nargs="?", default=1, type=check_range)
try:
args = parser.parse_args()
if args.file is None and args.input is None:
parser.error("--input or --file must be supplied")
elif args.file is not None and args.input is not None:
parser.error("please choose either an input dir. or a csv file")
elif args.file is not None:
print(parser.description, "\n")
print("Input file", args.file)
print("Chosen scheme", args.s)
st = time.time()
d = load_data(args.file)
elapsed_time(st)
visualise(d, args.s)
elapsed_time(st)
print("Press Enter to exit")
input()
elif args.input is not None:
if not args.input.endswith("/"):
parser.error("please supply a suitable directory (Usage examples below).")
else:
print(parser.description, "\n")
print("Input directory", args.input)
print("Chosen scheme", args.s)
st = time.time()
outdir = preprocess(args.input)
elapsed_time(st)
d = get_data(outdir)
elapsed_time(st)
visualise(d, args.s)
elapsed_time(st)
print("Press Enter to exit")
input()
except IOError as msg:
parser.error(str(msg))
except KeyboardInterrupt:
parser.exit(1, "\nExecution aborted")
# ------------------------------------------------------------------------------
if __name__ == "__main__":
main(sys.argv[1:])