2
2
import matplotlib
3
3
matplotlib .use ('Agg' )
4
4
import shutil
5
- from subprocess import Popen , PIPE , check_output
5
+ from subprocess import Popen , PIPE , check_output , STDOUT
6
6
import os
7
7
import pwd
8
8
import shlex
12
12
import math
13
13
14
14
print ("*****************************" )
15
- print ("OpenWorm Master Script v0.9.2 " )
15
+ print ("OpenWorm Master Script v0.9.3 " )
16
16
print ("*****************************" )
17
17
print ("" )
18
18
print ("This script attempts to run a full pass through the OpenWorm scientific libraries." )
76
76
def execute_with_realtime_output (command , directory , env = None ):
77
77
p = None
78
78
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 )
80
88
with p .stdout :
81
89
for line in iter (p .stdout .readline , b'' ):
82
- print (line .decode ('utf-8' ), end = '' )
90
+ print ('>> %s' % line .decode ('utf-8' ), end = '' )
83
91
p .wait () # wait for the subprocess to exit
84
92
except KeyboardInterrupt as e :
85
93
print ("Caught CTRL+C" )
86
94
if p :
87
95
p .kill ()
88
96
raise e
97
+ print ('>> --------------------------------------------------------------' )
98
+ print ('>> Command exited with %i: %s' % (p .returncode ,command ))
99
+ print ('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n ' )
100
+
101
+ if p .returncode != 0 :
102
+ print ('Exiting as the last command failed' )
103
+ exit (p .returncode )
104
+
89
105
90
106
91
107
sys .path .append (os .environ ['C302_HOME' ])
@@ -110,6 +126,10 @@ def execute_with_realtime_output(command, directory, env=None):
110
126
if 'DURATION' in os .environ :
111
127
sim_duration = float (os .environ ['DURATION' ])
112
128
129
+ noc302 = False
130
+ if 'NOC302' in os .environ :
131
+ noc302 = bool (os .environ ['NOC302' ])
132
+
113
133
DEFAULTS = {'duration' : sim_duration ,
114
134
'dt' : 0.005 ,
115
135
'dtNrn' : 0.05 ,
@@ -119,13 +139,15 @@ def execute_with_realtime_output(command, directory, env=None):
119
139
'verbose' : False ,
120
140
'device' : 'GPU' ,
121
141
'configuration' : 'worm_crawl_half_resolution' ,
122
- 'noc302' : False ,
142
+ 'noc302' : noc302 ,
123
143
'datareader' : 'UpdatedSpreadsheetDataReader2' ,
124
144
'outDir' : OW_OUT_DIR }
125
145
126
146
my_env = os .environ .copy ()
127
147
my_env ["DISPLAY" ] = ":44"
128
148
149
+ # Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol.
150
+ # In contrast to other display servers, Xvfb performs all graphical operations in virtual memory without showing any screen output.
129
151
os .system ('Xvfb :44 -listen tcp -ac -screen 0 1920x1080x24+32 &' ) # TODO: terminate xvfb after recording
130
152
131
153
try :
@@ -151,6 +173,9 @@ def execute_with_realtime_output(command, directory, env=None):
151
173
DEFAULTS ['datareader' ],
152
174
'simulations' )
153
175
#DEFAULTS['outDir'])
176
+
177
+ if noc302 : command += ' -noc302'
178
+
154
179
execute_with_realtime_output (command , os .environ ['SIBERNETIC_HOME' ], env = my_env )
155
180
except KeyboardInterrupt as e :
156
181
pass
@@ -162,9 +187,13 @@ def execute_with_realtime_output(command, directory, env=None):
162
187
for directory in dirnames :
163
188
if directory .startswith ('%s_%s' % (DEFAULTS ['c302params' ], DEFAULTS ['reference' ])):
164
189
all_subdirs .append (os .path .join (dirpath , directory ))
190
+ if directory .startswith ('Sibernetic' ):
191
+ all_subdirs .append (os .path .join (dirpath , directory ))
165
192
166
193
latest_subdir = max (all_subdirs , key = os .path .getmtime )
167
-
194
+ print ('\n ========================================================================\n ' )
195
+ print ('Finished main simulation, data saved in: %s' % latest_subdir )
196
+ execute_with_realtime_output ('ls -alt %s' % latest_subdir , os .environ ['SIBERNETIC_HOME' ], env = my_env )
168
197
169
198
try :
170
199
os .mkdir ('%s/output' % OW_OUT_DIR )
@@ -198,19 +227,27 @@ def execute_with_realtime_output(command, directory, env=None):
198
227
print ("Moving %s to %s" % (wcon , new_sim_out ))
199
228
shutil .move (wcon , new_sim_out )
200
229
230
+ time .sleep (2 )
201
231
202
232
# Rerun and record simulation
203
233
os .system ('export DISPLAY=:44' )
204
234
sibernetic_movie_name = '%s.mp4' % os .path .split (latest_subdir )[- 1 ]
205
- os .system ('tmux new-session -d -s SiberneticRecording "DISPLAY=:44 ffmpeg -r 30 -f x11grab -draw_mouse 0 -s 1920x1080 -i :44 -filter:v "crop=1200:800:100:100" -cpu-used 0 -b:v 384k -qmin 10 -qmax 42 -maxrate 384k -bufsize 1000k -an %s/%s"' % (new_sim_out , sibernetic_movie_name ))
235
+ command = 'tmux new-session -d -s SiberneticRecording "DISPLAY=:44 ffmpeg -r 30 -f x11grab -draw_mouse 0 -s 1920x1080 -i :44 -filter:v "crop=1200:800:100:100" -cpu-used 0 -b:v 384k -qmin 10 -qmax 42 -maxrate 384k -bufsize 1000k -an %s/%s"' % (new_sim_out , sibernetic_movie_name )
236
+ execute_with_realtime_output (command , os .environ ['SIBERNETIC_HOME' ], env = my_env )
237
+
238
+ time .sleep (3 )
239
+
240
+ execute_with_realtime_output ('tmux list-sessions' , os .environ ['SIBERNETIC_HOME' ], env = my_env )
206
241
207
242
command = './Release/Sibernetic -f %s -l_from lpath=%s' % (DEFAULTS ['configuration' ], latest_subdir )
208
243
execute_with_realtime_output (command , os .environ ['SIBERNETIC_HOME' ], env = my_env )
209
244
210
- os . system ('tmux send-keys -t SiberneticRecording q' )
211
- os . system ('tmux send-keys -t SiberneticRecording "exit" C-m' )
245
+ execute_with_realtime_output ('tmux send-keys -t SiberneticRecording q' , os . environ [ 'SIBERNETIC_HOME' ], env = my_env )
246
+ execute_with_realtime_output ('tmux send-keys -t SiberneticRecording "exit" C-m' , os . environ [ 'SIBERNETIC_HOME' ], env = my_env )
212
247
213
- time .sleep (3 )
248
+ time .sleep (5 )
249
+
250
+ execute_with_realtime_output ('ls -alt %s' % latest_subdir , os .environ ['SIBERNETIC_HOME' ], env = my_env )
214
251
215
252
# Remove black frames at the beginning of the recorded video
216
253
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 +284,7 @@ def execute_with_realtime_output(command, directory, env=None):
247
284
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' ))
248
285
os .system ('ffmpeg -r 100 -i %s -r 100 -vb 60M %s/speeded_%s' % ('tmp/out%06d.jpg' , new_sim_out , sibernetic_movie_name ))
249
286
250
- os .system ('sudo rm -r tmp/*' )
287
+ os .system ('rm -r tmp/*' )
251
288
252
289
253
290
0 commit comments