Skip to content

Commit 0b70367

Browse files
committed
minor changes + include spikes report in write_reports()
1 parent d8e2519 commit 0b70367

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

bluecellulab/circuit_simulation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ def write_reports(self):
812812
)
813813
compartment_sets = self.circuit_access.config.get_compartment_sets()
814814
write_compartment_report(
815+
report_name=report_name,
815816
output_path=output_path,
816817
cells=self.cells,
817818
report_cfg=report_cfg,
@@ -827,13 +828,16 @@ def write_reports(self):
827828
"for node-based section recording (must be 'center' or 'all')."
828829
)
829830
write_compartment_report(
831+
report_name=report_name,
830832
output_path=output_path,
831833
cells=self.cells,
832834
report_cfg=report_cfg,
833835
source_sets=node_sets,
834836
source_type="node_set"
835837
)
836838

839+
self.write_spike_report()
840+
837841
def write_spike_report(self):
838842
"""Collect and write in-memory recorded spike times to a SONATA HDF5
839843
file, grouped by population as required by the SONATA specification."""

bluecellulab/simulation/report.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import h5py
1919
from typing import List
2020
import numpy as np
21+
import os
2122

2223
from bluecellulab.tools import resolve_segments, resolve_source_nodes
2324
from bluecellulab.cell.cell_dict import CellDict
@@ -58,14 +59,20 @@ def configure_all_reports(cells, simulation_config):
5859
source_type = "compartment_set"
5960
source_sets = simulation_config.get_compartment_sets()
6061
source_name = report_cfg.get("compartments")
62+
if not source_name:
63+
logger.warning(f"Report '{report_name}' does not specify a node set in 'compartments' for {source_type}.")
64+
continue
6165
else:
6266
source_type = "node_set"
6367
source_sets = simulation_config.get_node_sets()
6468
source_name = report_cfg.get("cells")
69+
if not source_name:
70+
logger.warning(f"Report '{report_name}' does not specify a node set in 'cells' for {source_type}.")
71+
continue
6572

6673
source = source_sets.get(source_name)
6774
if not source:
68-
logger.warning(f"{source_type.title()} '{source_name}' not found for report '{report_name}'")
75+
logger.warning(f"{source_type.title()} '{source_name}' not found for report '{report_name}', skipping recording.")
6976
continue
7077

7178
population = source["population"]
@@ -79,6 +86,7 @@ def configure_all_reports(cells, simulation_config):
7986

8087

8188
def write_compartment_report(
89+
report_name: str,
8290
output_path: str,
8391
cells: CellDict,
8492
report_cfg: dict,
@@ -112,7 +120,8 @@ def write_compartment_report(
112120
source_name = report_cfg.get("cells") if source_type == "node_set" else report_cfg.get("compartments")
113121
source = source_sets.get(source_name)
114122
if not source:
115-
raise ValueError(f"{source_type} '{source_name}' not found.")
123+
logger.warning(f"{source_type.title()} '{source_name}' not found for report '{report_name}', skipping write.")
124+
return
116125

117126
population = source["population"]
118127

@@ -201,6 +210,7 @@ def write_sonata_spikes(f_name: str, spikes_dict: dict[int, np.ndarray], populat
201210
node_ids_sorted = np.array(all_node_ids, dtype=np.uint64)[sorted_indices]
202211
timestamps_sorted = np.array(all_timestamps, dtype=np.float64)[sorted_indices]
203212

213+
os.makedirs(os.path.dirname(f_name), exist_ok=True)
204214
with h5py.File(f_name, 'a') as f: # 'a' to allow multiple writes
205215
spikes_group = f.require_group("spikes")
206216
if population in spikes_group:

examples/2-sonata-network/sonata-network.ipynb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,16 +943,14 @@
943943
"\n",
944944
"After running the simulation, results can be saved in SONATA format.\n",
945945
"\n",
946-
"Calling `sim.write_spike_report()` will store all spike events in a structured `.h5` file, grouped by population.\n",
946+
"To write the reports defined in the simulation config (e.g. soma report) and the spike report, use `sim.write_reports()`. \n",
947947
"\n",
948-
"To write the reports defined in the simulation config (e.g. soma report), use `sim.write_reports()`. \n",
949-
"\n",
950-
"Both reports are saved in the directory specified by the output_dir field in the output section of the simulation configuration file."
948+
"Reports are saved in the directory specified by the output_dir field in the output section of the simulation configuration file."
951949
]
952950
},
953951
{
954952
"cell_type": "code",
955-
"execution_count": 19,
953+
"execution_count": null,
956954
"metadata": {},
957955
"outputs": [
958956
{
@@ -964,7 +962,6 @@
964962
}
965963
],
966964
"source": [
967-
"sim.write_spike_report()\n",
968965
"sim.write_reports()"
969966
]
970967
}

0 commit comments

Comments
 (0)