-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_social.py
More file actions
60 lines (43 loc) · 1.8 KB
/
run_social.py
File metadata and controls
60 lines (43 loc) · 1.8 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
import subprocess
import paths
import datetime
from functions_recorder import initialize_projector, record_vr_rig, plot_inputs_vr, load_csv
from functions_osc import create_and_send
from os.path import join
from time import sleep
from functions_GUI import get_filename_suffix, replace_name_part
# configure recording
# initialize projector
my_device = initialize_projector()
# assemble the main body of the file name
time_name = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M_%S")
# get and format the current time
csvName = join(paths.bonsai_out, time_name + r'_social_suffix.csv')
videoName = csvName.replace('.csv', '.avi')
# launch bonsai tracking
bonsai_process = subprocess.Popen([paths.bonsai_path, paths.bonsaiworkflowSOC_path,
"-p:csvName="""+csvName+"""""", "-p:videoName="""+videoName+"""""", "--start"])
# launch Unity tracking
unity_process = subprocess.Popen([paths.unitySOC_path])
# start recording
duration, current_path_sync = record_vr_rig(my_device, paths.sync_path, time_name, '_syncSOC')
# close the opened applications
create_and_send(paths.bonsai_ip, paths.bonsai_port, paths.bonsai_address, [1])
create_and_send(paths.unity_ip, paths.unity_port, paths.unity_address, [1])
sleep(2)
bonsai_process.kill()
# plot the timing
# load the frame_list
print(duration)
frame_list = load_csv(current_path_sync)
plot_inputs_vr(frame_list)
# ask the user for the suffix (animal, result, notes)
suffix = get_filename_suffix()
# add the suffix to all the file names
file_list = [csvName, videoName, current_path_sync]
failed_files, _ = replace_name_part(file_list, 'suffix', suffix)
print(failed_files)
# do the same for the bonsai files
unity_file = [paths.unity_temp_path]
failed_unity, _ = replace_name_part(unity_file, 'suffix', '_'.join((time_name, suffix)))
print(failed_unity)