-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhd2ns.py
executable file
·66 lines (54 loc) · 2.17 KB
/
rhd2ns.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
#!/usr/bin/env python3
#
# Copyright (C) 2012-2016 Matthias Klumpp <[email protected]>
#
# Licensed under the GNU Lesser General Public License Version 3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the license, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import argparse
import subprocess
from tempfile import TemporaryDirectory
from convert import convert_rhd
def run_neuroscope(dat_fname):
try:
subprocess.run(['neuroscope', dat_fname])
except AttributeError:
subprocess.call(['neuroscope', dat_fname])
def main():
parser = argparse.ArgumentParser(description="Convert Intan RHD files into .dat files and Neuroscope metadata")
parser.add_argument("fname", help="Intan RHD file")
parser.add_argument("--open", help="Open Neuroscope", action='store_true')
parser.add_argument("--temporary", help="Do not permanently store the converted data", action='store_true')
parser.add_argument("--override", help="Override potentially existing files and metadata", action='store_true')
args = parser.parse_args()
if not args.fname:
print("No file name given!")
return 1
# target directory
nsdir = os.path.join(os.path.dirname(args.fname), "ns")
if args.temporary:
with TemporaryDirectory(prefix='rhd2ns-') as tmpdir:
dat_fname = convert_rhd(args.fname, tmpdir, True)
if args.open:
run_neuroscope(dat_fname)
else:
dat_fname = convert_rhd(args.fname, nsdir, args.override)
if args.open:
run_neuroscope(dat_fname)
return 0
if __name__ == "__main__":
r = main()
sys.exit(r)