18
18
import h5py
19
19
from typing import List
20
20
import numpy as np
21
+ import os
21
22
22
23
from bluecellulab .tools import resolve_segments , resolve_source_nodes
23
24
from bluecellulab .cell .cell_dict import CellDict
@@ -58,14 +59,20 @@ def configure_all_reports(cells, simulation_config):
58
59
source_type = "compartment_set"
59
60
source_sets = simulation_config .get_compartment_sets ()
60
61
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
61
65
else :
62
66
source_type = "node_set"
63
67
source_sets = simulation_config .get_node_sets ()
64
68
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
65
72
66
73
source = source_sets .get (source_name )
67
74
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. " )
69
76
continue
70
77
71
78
population = source ["population" ]
@@ -79,6 +86,7 @@ def configure_all_reports(cells, simulation_config):
79
86
80
87
81
88
def write_compartment_report (
89
+ report_name : str ,
82
90
output_path : str ,
83
91
cells : CellDict ,
84
92
report_cfg : dict ,
@@ -112,7 +120,8 @@ def write_compartment_report(
112
120
source_name = report_cfg .get ("cells" ) if source_type == "node_set" else report_cfg .get ("compartments" )
113
121
source = source_sets .get (source_name )
114
122
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
116
125
117
126
population = source ["population" ]
118
127
@@ -201,6 +210,7 @@ def write_sonata_spikes(f_name: str, spikes_dict: dict[int, np.ndarray], populat
201
210
node_ids_sorted = np .array (all_node_ids , dtype = np .uint64 )[sorted_indices ]
202
211
timestamps_sorted = np .array (all_timestamps , dtype = np .float64 )[sorted_indices ]
203
212
213
+ os .makedirs (os .path .dirname (f_name ), exist_ok = True )
204
214
with h5py .File (f_name , 'a' ) as f : # 'a' to allow multiple writes
205
215
spikes_group = f .require_group ("spikes" )
206
216
if population in spikes_group :
0 commit comments