-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (46 loc) · 1.52 KB
/
main.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
"""
main.py
Used to execute operators from bash using sbin/run.sh
"""
import pickle
import argparse
import utils
import nibabel as nbl
from workflow import Workflow
from pyspark import SparkContext
""" Argument Parsing"""
parser = argparse.ArgumentParser(description="fMRI Flow: Neuroimaging with Apache Spark and Python")
parser.add_argument('--path', metavar='p', help="The data path")
parser.add_argument('--operator', metavar='o', help='The operator to be executed')
parser.add_argument('--model', metavar='m', help='A serialized model')
parser.add_argument('--vector', metavar='v', help='An input vector')
parser.add_argument('--k', metavar='k', help='k parameter for K-Means')
parser.add_argument('--nsamples', metavar='ns', help='The number of samples')
args = parser.parse_args()
""" Initial Workflow definition """
if args.path:
sc = SparkContext()
data = nbl.load(args.path).get_data()[:,:,:,:100]
flow = Workflow(data, sc).extract()
op = args.operator
if op == "vb":
flow = flow.visualizeBrain()
elif op == "v":
nsamples = args.nsamples
flow = flow.visualize(nsamples=int(nsamples))
elif op == "vc":
k = args.k
flow = flow.clustering(int(k)).visualize()
elif op == "ts":
k = args.k
flow = flow.clustering(int(k))
flow.execute()
with open("model", "a+") as output:
pickle.dump(flow.last.result, output, pickle.HIGHEST_PROTOCOL)
exit("Model Saved")
elif op == "pr":
utils.predict(args.model, args.vector)
exit()
else:
exit("Operator not found")
flow.execute()