Skip to content

Commit 41c0626

Browse files
committed
Use latest master_openworm
1 parent 8a29644 commit 41c0626

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

master_openworm.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib
33
matplotlib.use('Agg')
44
import shutil
5-
from subprocess import Popen, PIPE, check_output
5+
from subprocess import Popen, PIPE, check_output, STDOUT
66
import os
77
import pwd
88
import shlex
@@ -76,16 +76,28 @@
7676
def execute_with_realtime_output(command, directory, env=None):
7777
p = None
7878
try:
79-
p = Popen(shlex.split(command), stdout=PIPE, bufsize=1, cwd=directory, env=env)
79+
80+
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
81+
print('>> Executing command: %s'%command)
82+
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
83+
p = Popen(shlex.split(command),
84+
stdout=PIPE,
85+
stderr=STDOUT,
86+
cwd=directory,
87+
env=env)
8088
with p.stdout:
8189
for line in iter(p.stdout.readline, b''):
82-
print(line.decode('utf-8'), end='')
90+
print('>> %s'%line.decode('utf-8'), end='')
8391
p.wait() # wait for the subprocess to exit
8492
except KeyboardInterrupt as e:
8593
print("Caught CTRL+C")
8694
if p:
8795
p.kill()
8896
raise e
97+
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
98+
print('>> Command exited with %i: %s'%(p.returncode,command))
99+
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n')
100+
89101

90102

91103
sys.path.append(os.environ['C302_HOME'])
@@ -110,6 +122,10 @@ def execute_with_realtime_output(command, directory, env=None):
110122
if 'DURATION' in os.environ:
111123
sim_duration = float(os.environ['DURATION'])
112124

125+
noc302 = False
126+
if 'NOC302' in os.environ:
127+
noc302 = bool(os.environ['NOC302'])
128+
113129
DEFAULTS = {'duration': sim_duration,
114130
'dt': 0.005,
115131
'dtNrn': 0.05,
@@ -119,7 +135,7 @@ def execute_with_realtime_output(command, directory, env=None):
119135
'verbose': False,
120136
'device': 'GPU',
121137
'configuration': 'worm_crawl_half_resolution',
122-
'noc302': False,
138+
'noc302': noc302,
123139
'datareader': 'UpdatedSpreadsheetDataReader2',
124140
'outDir': OW_OUT_DIR}
125141

@@ -151,6 +167,9 @@ def execute_with_realtime_output(command, directory, env=None):
151167
DEFAULTS['datareader'],
152168
'simulations')
153169
#DEFAULTS['outDir'])
170+
171+
if noc302: command += ' -noc302'
172+
154173
execute_with_realtime_output(command, os.environ['SIBERNETIC_HOME'], env=my_env)
155174
except KeyboardInterrupt as e:
156175
pass
@@ -162,9 +181,13 @@ def execute_with_realtime_output(command, directory, env=None):
162181
for directory in dirnames:
163182
if directory.startswith('%s_%s' % (DEFAULTS['c302params'], DEFAULTS['reference'])):
164183
all_subdirs.append(os.path.join(dirpath, directory))
184+
if directory.startswith('Sibernetic'):
185+
all_subdirs.append(os.path.join(dirpath, directory))
165186

166187
latest_subdir = max(all_subdirs, key=os.path.getmtime)
167-
188+
print('\n========================================================================\n')
189+
print('Finished main simulation, data saved in: %s'%latest_subdir)
190+
execute_with_realtime_output('ls -alt %s'%latest_subdir, os.environ['SIBERNETIC_HOME'], env=my_env)
168191

169192
try:
170193
os.mkdir('%s/output' % OW_OUT_DIR)
@@ -198,6 +221,9 @@ def execute_with_realtime_output(command, directory, env=None):
198221
print("Moving %s to %s"%(wcon, new_sim_out))
199222
shutil.move(wcon, new_sim_out)
200223

224+
time.sleep(2)
225+
226+
201227

202228
# Rerun and record simulation
203229
os.system('export DISPLAY=:44')
@@ -210,7 +236,9 @@ def execute_with_realtime_output(command, directory, env=None):
210236
os.system('tmux send-keys -t SiberneticRecording q')
211237
os.system('tmux send-keys -t SiberneticRecording "exit" C-m')
212238

213-
time.sleep(3)
239+
time.sleep(5)
240+
241+
execute_with_realtime_output('ls -alt %s'%latest_subdir, os.environ['SIBERNETIC_HOME'], env=my_env)
214242

215243
# Remove black frames at the beginning of the recorded video
216244
command = "ffmpeg -i %s/%s -vf blackdetect=d=0:pic_th=0.70:pix_th=0.10 -an -f null - 2>&1 | grep blackdetect" % (new_sim_out, sibernetic_movie_name)
@@ -247,7 +275,7 @@ def execute_with_realtime_output(command, directory, env=None):
247275
os.system('ffmpeg -ss 1 -i %s/cut_%s -vf "select=gt(scene\,0.1)" -vsync vfr -vf fps=fps=1/1 %s' % (new_sim_out, sibernetic_movie_name, 'tmp/out%06d.jpg'))
248276
os.system('ffmpeg -r 100 -i %s -r 100 -vb 60M %s/speeded_%s' % ('tmp/out%06d.jpg', new_sim_out, sibernetic_movie_name))
249277

250-
os.system('sudo rm -r tmp/*')
278+
os.system('rm -r tmp/*')
251279

252280

253281

run-quick.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ xhost +
2020

2121

2222
NOC302_PART="-e NOC302=1"
23-
DURATION_PART="-e DURATION=0.1"
23+
DURATION_PART="-e DURATION=3"
2424

2525
docker run -d \
2626
--name openworm_$version \

0 commit comments

Comments
 (0)