Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bluecellulab/reports/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,37 @@ def prepare_recordings_for_reports(
sites_index[cell_id].append(entry)
cell.report_sites[report_name].append(entry)

for cell_id, cell in cells.items():
sec = cell.soma
sec_name = sec.name().split(".")[-1]
segx = 0.5
rec_name = section_to_variable_recording_str(sec, segx, "v")

if rec_name in recording_index[cell_id]:
continue

report_name = "__default_voltage__"
cell.report_sites.setdefault(report_name, [])

configured = cell.configure_recording(
[(sec, sec_name, segx)],
"v",
report_name,
)

for (sec, sec_name, segx), rec_name in configured:
recording_index[cell_id].append(rec_name)

entry_default_voltage: SiteEntry = {
"report": report_name,
"rec_name": rec_name,
"section": sec_name,
"segx": float(segx),
"area_um2": None,
}
sites_index[cell_id].append(entry_default_voltage)
cell.report_sites[report_name].append(entry_default_voltage)

return dict(recording_index), dict(sites_index)


Expand Down
26 changes: 21 additions & 5 deletions tests/test_reports/test_reports_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,30 @@
)


class DummySection:
def name(self):
return "cell.soma[0]"

def __str__(self):
return "soma[0]"


class DummyCell:
def __init__(self, targets, rec_names):
self.targets = targets
self.rec_names = rec_names
self.report_sites: dict[str, list[dict]] = {}
self.soma = DummySection()

def resolve_segments_from_config(self, _cfg):
return self.targets

def resolve_segments_from_compartment_set(self, _node_id, _compartment_nodes):
return self.targets

def configure_recording(self, sites, _variable, _report_name):
def configure_recording(self, sites, variable, report_name):
if report_name == "__default_voltage__":
return [(site, f"default_{variable}_{idx}") for idx, site in enumerate(sites)]
return list(zip(sites, self.rec_names))


Expand Down Expand Up @@ -134,8 +145,11 @@ def test_prepare_recordings_for_reports_compartment_populates_report_sites(caplo
recording_index, sites_index = prepare_recordings_for_reports(cells, cfg)

assert not caplog.records
assert recording_index[cell_id] == ["rec_soma", "rec_dend"]
assert len(sites_index[cell_id]) == 2
assert recording_index[cell_id][:2] == ["rec_soma", "rec_dend"]
assert len(recording_index[cell_id]) == 3
assert len(sites_index[cell_id]) == 3
assert "__default_voltage__" in cell.report_sites
assert len(cell.report_sites["__default_voltage__"]) == 1
assert "r1" in cell.report_sites
assert [s["rec_name"] for s in cell.report_sites["r1"]] == ["rec_soma", "rec_dend"]

Expand All @@ -155,8 +169,10 @@ def test_prepare_recordings_for_reports_warns_on_rec_mismatch(caplog):
recording_index, sites_index = prepare_recordings_for_reports(cells, cfg)

assert "Configured 1/2 recording sites" in caplog.text
assert recording_index[cell_id] == ["only_one"]
assert len(sites_index[cell_id]) == 1
assert recording_index[cell_id][0] == "only_one"
assert len(recording_index[cell_id]) == 2
assert len(sites_index[cell_id]) == 2
assert "__default_voltage__" in cell.report_sites


def test_prepare_recordings_for_reports_populates_area_um2(monkeypatch):
Expand Down
Loading