Skip to content

Commit 3a9e7a2

Browse files
committed
Improves the master_openworm script - makes it more realsitic about what's happenning
1 parent 715de9f commit 3a9e7a2

File tree

1 file changed

+35
-72
lines changed

1 file changed

+35
-72
lines changed

master_openworm.py

Lines changed: 35 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,20 @@
1212
import math
1313

1414
print("*****************************")
15-
print("OpenWorm Master Script")
15+
print(" OpenWorm Master Script")
1616
print("*****************************")
1717
print("")
18-
print(
19-
"This script attempts to run a full pass through the OpenWorm scientific libraries."
20-
)
18+
print("This script attempts to run a full pass through the OpenWorm software stack.")
2119
print(
2220
"This depends on several other repositories being loaded to work and presumes it is running in a preloaded Docker instance."
2321
)
2422
print("It will report out where steps are missing.")
2523
print("Eventually all the steps will be filled in.")
2624
print("")
2725

28-
print("****************************")
29-
print("Step 1: Rebuild c302 from the latest owmeta")
30-
print("****************************")
31-
print("Not yet implemented. See https://github.com/openworm/c302/issues/10")
32-
3326

3427
print("****************************")
35-
print("Step 2: Execute unit tests via the c302 simulation framework")
36-
print("****************************")
37-
"""
38-
from runAndPlot import run_c302
39-
orig_display_var = None
40-
if os.environ.has_key('DISPLAY'):
41-
orig_display_var = os.environ['DISPLAY']
42-
del os.environ['DISPLAY'] # https://www.neuron.yale.edu/phpBB/viewtopic.php?f=6&t=1603
43-
44-
run_c302(DEFAULTS['reference'],
45-
DEFAULTS['c302params'],
46-
'',
47-
DEFAULTS['duration'],
48-
DEFAULTS['dt'],
49-
'jNeuroML_NEURON',
50-
data_reader=DEFAULTS['datareader'],
51-
save=True,
52-
show_plot_already=False,
53-
target_directory=os.path.join(os.environ['C302_HOME'], 'examples'),
54-
save_fig_to='tmp_images')
55-
prev_dir = os.getcwd()
56-
os.chdir(DEFAULTS['outDir'])
57-
try:
58-
os.mkdir('c302_out')
59-
except OSError as e:
60-
if e.errno != errno.EEXIST:
61-
raise
62-
src_files = os.listdir(os.path.join(os.environ['C302_HOME'], 'examples', 'tmp_images'))
63-
for file_name in src_files:
64-
full_file_name = os.path.join(os.environ['C302_HOME'], 'examples', 'tmp_images', file_name)
65-
print("COPY %s" % full_file_name)
66-
if (os.path.isfile(full_file_name)):
67-
shutil.copy2(full_file_name, 'c302_out')
68-
shutil.rmtree(os.path.join(os.environ['C302_HOME'], 'examples', 'tmp_images'))
69-
os.chdir(prev_dir)
70-
if orig_display_var:
71-
os.environ['DISPLAY'] = orig_display_var
72-
"""
73-
74-
print("****************************")
75-
print("Step 3: Run c302 + Sibernetic in the same loop.")
28+
print(" Step 1: Run c302 + Sibernetic in the same loop.")
7629
print("****************************")
7730

7831
OW_OUT_DIR = os.environ["OW_OUT_DIR"]
@@ -131,10 +84,11 @@ def execute_with_realtime_output(command, directory, env=None):
13184
sim_duration = float(os.environ["DURATION"])
13285

13386
noc302 = False
134-
if "NOC302" in os.environ:
135-
noc302 = bool(os.environ["NOC302"])
87+
if "CONFIGURATION" in os.environ:
88+
configuration = os.environ["CONFIGURATION"]
89+
noc302 = "worm" not in configuration
13690

137-
DEFAULTS = {
91+
PARAMETERS = {
13892
"duration": sim_duration,
13993
"dt": 0.005,
14094
"dtNrn": 0.05,
@@ -143,7 +97,7 @@ def execute_with_realtime_output(command, directory, env=None):
14397
"c302params": "C2",
14498
"verbose": False,
14599
"device": "CPU",
146-
"configuration": "worm_crawl_half_resolution",
100+
"configuration": configuration,
147101
"noc302": noc302,
148102
"datareader": "UpdatedSpreadsheetDataReader2",
149103
"outDir": OW_OUT_DIR,
@@ -161,6 +115,10 @@ def execute_with_realtime_output(command, directory, env=None):
161115
) # TODO: terminate xvfb after recording
162116

163117
try:
118+
print("Starting Sibernetic simulation with parameters:")
119+
for p in PARAMETERS:
120+
print(" %s: %s" % (p, PARAMETERS[p]))
121+
164122
command = """python3 sibernetic_c302.py
165123
-duration %s
166124
-dt %s
@@ -172,23 +130,24 @@ def execute_with_realtime_output(command, directory, env=None):
172130
-c302params %s
173131
-datareader %s
174132
-outDir %s""" % (
175-
DEFAULTS["duration"],
176-
DEFAULTS["dt"],
177-
DEFAULTS["dtNrn"],
178-
DEFAULTS["logstep"],
179-
DEFAULTS["device"],
180-
DEFAULTS["configuration"],
181-
DEFAULTS["reference"],
182-
DEFAULTS["c302params"],
183-
DEFAULTS["datareader"],
133+
PARAMETERS["duration"],
134+
PARAMETERS["dt"],
135+
PARAMETERS["dtNrn"],
136+
PARAMETERS["logstep"],
137+
PARAMETERS["device"],
138+
PARAMETERS["configuration"],
139+
PARAMETERS["reference"],
140+
PARAMETERS["c302params"],
141+
PARAMETERS["datareader"],
184142
"simulations",
185143
)
186-
# DEFAULTS['outDir'])
144+
# PARAMETERS['outDir'])
187145

188146
if noc302:
189147
command += " -noc302"
190148

191149
execute_with_realtime_output(command, os.environ["SIBERNETIC_HOME"], env=my_env)
150+
192151
except KeyboardInterrupt:
193152
pass
194153

@@ -198,7 +157,7 @@ def execute_with_realtime_output(command, directory, env=None):
198157
for dirpath, dirnames, filenames in os.walk(sibernetic_sim_dir):
199158
for directory in dirnames:
200159
if directory.startswith(
201-
"%s_%s" % (DEFAULTS["c302params"], DEFAULTS["reference"])
160+
"%s_%s" % (PARAMETERS["c302params"], PARAMETERS["reference"])
202161
):
203162
all_subdirs.append(os.path.join(dirpath, directory))
204163
if directory.startswith("Sibernetic"):
@@ -238,10 +197,14 @@ def execute_with_realtime_output(command, directory, env=None):
238197
shutil.move(report, new_sim_out)
239198

240199
# Copy position files etc.
241-
reports = glob.glob('%s/position_buffer*' % latest_subdir)
242-
for report in reports:
243-
print("Moving %s to %s"%(report, new_sim_out))
244-
shutil.move(report, new_sim_out)
200+
txt_files = glob.glob("%s/*.txt" % latest_subdir)
201+
for txt_file in txt_files:
202+
print("Moving %s to %s" % (txt_file, new_sim_out))
203+
shutil.move(txt_file, new_sim_out)
204+
dat_files = glob.glob("%s/*.dat" % latest_subdir)
205+
for dat_file in dat_files:
206+
print("Moving %s to %s" % (dat_file, new_sim_out))
207+
shutil.move(dat_file, new_sim_out)
245208

246209
# Copy WCON file(s)
247210
wcons = glob.glob("%s/*.wcon" % latest_subdir)
@@ -273,7 +236,7 @@ def execute_with_realtime_output(command, directory, env=None):
273236
)
274237

275238
command = "./Release/Sibernetic -f %s -l_from lpath=%s" % (
276-
DEFAULTS["configuration"],
239+
PARAMETERS["configuration"],
277240
latest_subdir,
278241
)
279242
execute_with_realtime_output(command, os.environ["SIBERNETIC_HOME"], env=my_env)
@@ -356,7 +319,7 @@ def execute_with_realtime_output(command, directory, env=None):
356319

357320

358321
print("****************************")
359-
print("Step 4: Run movement analysis")
322+
print(" Step 2: Run movement analysis")
360323
print("****************************")
361324
print("Not yet implemented.")
362325
print(
@@ -366,6 +329,6 @@ def execute_with_realtime_output(command, directory, env=None):
366329

367330

368331
print("****************************")
369-
print("Step 5: Report on movement analysis fit to real worm videos")
332+
print(" Step 3: Report on movement analysis fit to real worm videos")
370333
print("****************************")
371334
print("Not yet implemented.")

0 commit comments

Comments
 (0)