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
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
+
89
101
90
102
91
103
sys .path .append (os .environ ['C302_HOME' ])
@@ -110,6 +122,10 @@ def execute_with_realtime_output(command, directory, env=None):
110
122
if 'DURATION' in os .environ :
111
123
sim_duration = float (os .environ ['DURATION' ])
112
124
125
+ noc302 = False
126
+ if 'NOC302' in os .environ :
127
+ noc302 = bool (os .environ ['NOC302' ])
128
+
113
129
DEFAULTS = {'duration' : sim_duration ,
114
130
'dt' : 0.005 ,
115
131
'dtNrn' : 0.05 ,
@@ -119,7 +135,7 @@ def execute_with_realtime_output(command, directory, env=None):
119
135
'verbose' : False ,
120
136
'device' : 'GPU' ,
121
137
'configuration' : 'worm_crawl_half_resolution' ,
122
- 'noc302' : False ,
138
+ 'noc302' : noc302 ,
123
139
'datareader' : 'UpdatedSpreadsheetDataReader2' ,
124
140
'outDir' : OW_OUT_DIR }
125
141
@@ -151,6 +167,9 @@ def execute_with_realtime_output(command, directory, env=None):
151
167
DEFAULTS ['datareader' ],
152
168
'simulations' )
153
169
#DEFAULTS['outDir'])
170
+
171
+ if noc302 : command += ' -noc302'
172
+
154
173
execute_with_realtime_output (command , os .environ ['SIBERNETIC_HOME' ], env = my_env )
155
174
except KeyboardInterrupt as e :
156
175
pass
@@ -162,9 +181,13 @@ def execute_with_realtime_output(command, directory, env=None):
162
181
for directory in dirnames :
163
182
if directory .startswith ('%s_%s' % (DEFAULTS ['c302params' ], DEFAULTS ['reference' ])):
164
183
all_subdirs .append (os .path .join (dirpath , directory ))
184
+ if directory .startswith ('Sibernetic' ):
185
+ all_subdirs .append (os .path .join (dirpath , directory ))
165
186
166
187
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 )
168
191
169
192
try :
170
193
os .mkdir ('%s/output' % OW_OUT_DIR )
@@ -198,6 +221,9 @@ def execute_with_realtime_output(command, directory, env=None):
198
221
print ("Moving %s to %s" % (wcon , new_sim_out ))
199
222
shutil .move (wcon , new_sim_out )
200
223
224
+ time .sleep (2 )
225
+
226
+
201
227
202
228
# Rerun and record simulation
203
229
os .system ('export DISPLAY=:44' )
@@ -210,7 +236,9 @@ def execute_with_realtime_output(command, directory, env=None):
210
236
os .system ('tmux send-keys -t SiberneticRecording q' )
211
237
os .system ('tmux send-keys -t SiberneticRecording "exit" C-m' )
212
238
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 )
214
242
215
243
# Remove black frames at the beginning of the recorded video
216
244
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):
247
275
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
276
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
277
250
- os .system ('sudo rm -r tmp/*' )
278
+ os .system ('rm -r tmp/*' )
251
279
252
280
253
281
0 commit comments