forked from gentnerlab/pyoperant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-pyoperant
executable file
·89 lines (71 loc) · 2.46 KB
/
run-pyoperant
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
#!/usr/bin/env python
import sys, os
import argparse
import importlib
try: import simplejson as json
except ImportError: import json
def parse_commandline(arg_str=sys.argv[1:]):
""" parse command line arguments
"""
parser = argparse.ArgumentParser()
parser.add_argument('protocol',
action='store',
type=str,
help='(str) experiment protocol'
)
parser.add_argument('-P', '--panel',
action='store',
type=str,
dest='panel',
required=True,
help='(string) panel identifier'
)
parser.add_argument('-S', '--subject',
action='store',
type=str,
dest='subject',
required=True,
help='subject identifier'
)
parser.add_argument('-c','--config',
action='store',
type=str,
dest='config_file',
default='config.json',
required=False,
help='configuration file [default: %(default)s]'
)
args = parser.parse_args(arg_str)
return vars(args)
def find_protocol(protocol,package_list):
packages = [importlib.import_module(pstr) for pstr in package_list]
for p in packages:
try:
return getattr(p, protocol)
except AttributeError:
continue
if __name__ == "__main__":
from pyoperant.local import PANELS
try:
from pyoperant.local import BEHAVIORS
except ImportError:
BEHAVIORS = ['pyoperant.behavior']
try:
from pyoperant.local import DATAPATH
except ImportError:
DATAPATH = '/home/bird/opdat'
cmd_line = parse_commandline()
config_file = os.path.join(DATAPATH,cmd_line['subject'],cmd_line['config_file'])
with open(config_file, 'rb') as config:
parameters = json.load(config)
BehaviorProtocol = find_protocol(cmd_line['protocol'],BEHAVIORS)
if parameters['debug']:
print parameters
print PANELS
behavior = BehaviorProtocol(
panel=PANELS[cmd_line['panel']](),
subject=cmd_line['subject'],
panel_name=cmd_line['panel'],
**parameters
)
behavior.run()