Skip to content

Commit

Permalink
updated beh experiments: (1) use cmd /c when starting sync led captur…
Browse files Browse the repository at this point in the history
…e, (2) reogranize code such that directories get created prior to recording happening, (3) use pathlib instead of os to create directories
  • Loading branch information
bartulem committed Jul 27, 2023
1 parent c8f43b2 commit a26cacb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# usv-playpen v0.2.12
# usv-playpen v0.2.13

<br>
<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='usv-playpen',
version='0.2.12',
version='0.2.13',
author='@bartulem',
author_email='mimica.bartul@gmail.com',
classifiers=[
Expand Down
62 changes: 28 additions & 34 deletions src/behavioral_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import datetime
import glob
import os
import pathlib
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -153,7 +154,7 @@ def check_camera_vitals(self, camera_fr=None):
webbrowser.open(self.exp_settings_dict['video']['general']['monitor_url'])

# pause for N seconds
QTest.qWait(2000)
QTest.qWait(1000)

self.api = api

Expand Down Expand Up @@ -361,49 +362,49 @@ def conduct_behavioral_recording(self):
f"and run by @{self.exp_settings_dict['video']['metadata']['experimenter']}. "
f"You will be notified upon completion. \n \n ***This is an automatic e-mail, please do NOT respond.***")

self.check_camera_vitals(camera_fr=self.exp_settings_dict['video']['general']['recording_frame_rate'])

# start capturing sync LEDS
if not os.path.isfile(f"{self.exp_settings_dict['coolterm_basedirectory']}{os.sep}Connection_settings{os.sep}coolterm_config.stc"):
shutil.copy(f"{self.exp_settings_dict['config_settings_directory']}{os.sep}coolterm_config.stc",
f"{self.exp_settings_dict['coolterm_basedirectory']}{os.sep}Connection_settings{os.sep}coolterm_config.stc")
sync_leds_capture = subprocess.Popen(args=f'''cmd /k "{self.exp_settings_dict['coolterm_basedirectory']}{os.sep}Connection_settings{os.sep}coolterm_config.stc"''',
sync_leds_capture = subprocess.Popen(args=f'''cmd /c "{self.exp_settings_dict['coolterm_basedirectory']}{os.sep}Connection_settings{os.sep}coolterm_config.stc"''',
stdout=subprocess.PIPE)

# start recording audio
if self.exp_settings_dict['conduct_audio_recording']:
self.check_camera_vitals(camera_fr=self.exp_settings_dict['video']['general']['recording_frame_rate'])

# modify audio config file
if self.exp_settings_dict['conduct_audio_recording']:
self.modify_audio_file()

start_hour_min_sec, total_dir_name_linux, total_dir_name_windows = self.get_custom_dir_names(now=self.api.call('schedule')['now'])

# run command to start audio recording and keep executing the rest of the script
if os.path.exists(f"{self.exp_settings_dict['avisoft_basedirectory']}{os.sep}Configurations{os.sep}RECORDER_USGH{os.sep}avisoft_config.ini"):
self.avisoft_recording = subprocess.Popen(args=f'''cmd /c ""rec_usgh.exe" /CFG=avisoft_config.ini /AUT"''',
stdout=subprocess.PIPE, cwd=self.exp_settings_dict['avisoft_recorder_exe'])
self.message_output(f"Recording in progress since {start_hour_min_sec}, it will last {self.exp_settings_dict['video_session_duration'] + .36} minute(s). Please be patient.")
else:
self.message_output('Audio config file is not in the appropriate directory.')
sys.exit()
else:
start_hour_min_sec, total_dir_name_linux, total_dir_name_windows = self.get_custom_dir_names(now=self.api.call('schedule')['now'])

# pause for N seconds
QTest.qWait(10000)
start_hour_min_sec, total_dir_name_linux, total_dir_name_windows = self.get_custom_dir_names(now=self.api.call('schedule')['now'])

for directory in total_dir_name_windows:
if not os.path.isdir(f"{directory}{os.sep}video"):
os.makedirs(f"{directory}{os.sep}video", exist_ok=False)
video_path = pathlib.Path(f"{directory}{os.sep}video")
video_path.mkdir(parents=True, exist_ok=True)
if not os.path.isdir(f"{directory}{os.sep}sync"):
os.makedirs(f"{directory}{os.sep}sync", exist_ok=False)
sync_path = pathlib.Path(f"{directory}{os.sep}sync")
sync_path.mkdir(parents=True, exist_ok=True)
if self.exp_settings_dict['conduct_audio_recording']:
if not os.path.isdir(f"{directory}{os.sep}audio"):
os.makedirs(f"{directory}{os.sep}audio", exist_ok=False)
if self.exp_settings_dict['audio']['general']['total'] == 0:
os.makedirs(f"{directory}{os.sep}audio{os.sep}original", exist_ok=False)
audio_one_device_original_path = pathlib.Path(f"{directory}{os.sep}audio{os.sep}original")
audio_one_device_original_path.mkdir(parents=True, exist_ok=True)
else:
os.makedirs(f"{directory}{os.sep}audio{os.sep}original", exist_ok=False)
os.makedirs(f"{directory}{os.sep}audio{os.sep}original_mc", exist_ok=False)
audio_two_device_original_path = pathlib.Path(f"{directory}{os.sep}audio{os.sep}original")
audio_two_device_original_path.mkdir(parents=True, exist_ok=True)
audio_two_device_original_mc_path = pathlib.Path(f"{directory}{os.sep}audio{os.sep}original_mc")
audio_two_device_original_mc_path.mkdir(parents=True, exist_ok=True)

# start recording audio
if self.exp_settings_dict['conduct_audio_recording']:
# run command to start audio recording and keep executing the rest of the script
if os.path.exists(f"{self.exp_settings_dict['avisoft_basedirectory']}{os.sep}Configurations{os.sep}RECORDER_USGH{os.sep}avisoft_config.ini"):
self.avisoft_recording = subprocess.Popen(args=f'''cmd /c ""rec_usgh.exe" /CFG=avisoft_config.ini /AUT"''',
stdout=subprocess.PIPE, cwd=self.exp_settings_dict['avisoft_recorder_exe'])
self.message_output(f"Recording in progress since {start_hour_min_sec}, it will last {self.exp_settings_dict['video_session_duration'] + .36} minute(s). Please be patient.")

# pause for N seconds
QTest.qWait(10000)

# record video data
if len(self.exp_settings_dict['video']['general']['expected_cameras']) == 1:
Expand Down Expand Up @@ -508,10 +509,3 @@ def conduct_behavioral_recording(self):
f"{datetime.datetime.now().hour:02d}:{datetime.datetime.now().minute:02d}.{datetime.datetime.now().second:02d}. "
f"You will be notified about further experiments "
f"should they occur. \n \n ***This is an automatic e-mail, please do NOT respond.***")


if __name__ == '__main__':
if len(sys.argv) > 1:
ExperimentController(message_output=sys.argv[1],
email_receivers=sys.argv[2],
exp_settings_dict=sys.argv[3]).conduct_behavioral_recording()
2 changes: 1 addition & 1 deletion src/usv_playpen_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
my_app_id = 'mycompany.myproduct.subproduct.version'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(my_app_id)

app_name = 'USV Playpen v0.2.12'
app_name = 'USV Playpen v0.2.13'
experimenter_id = 'bartulem'
email_list_global = ''
config_dir_global = 'C:\\experiment_running_docs'
Expand Down

0 comments on commit a26cacb

Please sign in to comment.