Skip to content

Commit 149622d

Browse files
committed
feat: add script to create summary readme for channels
1 parent 501284f commit 149622d

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

NeuroML2/compare_MC/IT2/compare/create_summary_readme.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111

1212
from pathlib import Path
13+
from contextlib import chdir
14+
import json
15+
import numpy as np
16+
from pyneuroml.plot import generate_plot
1317

1418

1519
cwd = Path('.')
@@ -20,15 +24,40 @@
2024
md_text += "|---------|------------|----------------|---------------|--------------|--------------|\n"
2125

2226
for d in directories:
23-
print(f"Looking in {d.name}")
27+
print(f"--> Processing {d.name}")
2428
channel = d.name
2529
mod_source = f"[{channel}.mod](../mod/{channel}.mod)"
2630
nml_source = f"[{channel}.channel.nml](../{channel}.channel.nml)"
27-
np_plot = list(d.glob("netpyne*png"))[0]
28-
nml_plot = list(d.glob("nml*png"))[0]
31+
np_data = list(d.glob("netpyne*json"))[0]
32+
np_plot = np_data.name.replace(".json", ".png")
33+
nml_data = list(d.glob("nml*dat"))[0]
34+
nml_plot = f"nml_{channel}.png"
2935
combined_plot = f"{d.name}/Figure_1.png"
3036

3137
md_text += f"| {channel} | {mod_source} | {nml_source} | ![{channel} NetPyNE]({np_plot}) | ![{channel} NML]({nml_plot}) | ![{channel} combined]({combined_plot})\n"
3238

39+
combined_figure = Path(d) / Path("Figure_1.png")
40+
41+
if not combined_figure.exists():
42+
print("--> All required figures not found, re-generating")
43+
with chdir(d):
44+
dat_data = np.loadtxt(nml_data.name)
45+
time_dat = dat_data[:, 0]
46+
voltage_dat = dat_data[:, 1] * 1000
47+
48+
voltage_json = None
49+
time_json = None
50+
51+
with open(np_data.name, 'r') as f:
52+
json_data = json.load(f)
53+
54+
voltage_json = json_data['simData']['V_soma']['cell_0']
55+
56+
dt = 1e-5
57+
time_json = np.arange(len(voltage_json)) * dt
58+
59+
generate_plot([time_dat, time_json], [voltage_dat, voltage_json], title="Comparison of Voltage from nml and netpyne", labels=["NML", "NetPyNE"], colors=["b", "r"], linestyles=["-", "--"], xaxis="Time (s)", yaxis="Voltage (mV)", show_plot_already=False, title_above_plot=True, save_figure_to="Figure_1.png", close_plot=True, xlim=[min(time_dat[0], time_json[0]), max(time_dat[-1], time_json[-1])], font_size=12)
60+
61+
print("--> Writing README.md")
3362
with open("README.md", 'w') as f:
3463
print(md_text, file=f)

0 commit comments

Comments
 (0)