From 95d62cb6dc71c186763d5ebcc8e2dcf2202a240d Mon Sep 17 00:00:00 2001 From: Philipp Schlegel Date: Fri, 6 Oct 2023 08:34:19 +0100 Subject: [PATCH] neuron CompartmentModel: speed up adding recordings by ... ... looking up all segments at once --- navis/interfaces/neuron/comp.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/navis/interfaces/neuron/comp.py b/navis/interfaces/neuron/comp.py index 50a1580e..00aebe06 100644 --- a/navis/interfaces/neuron/comp.py +++ b/navis/interfaces/neuron/comp.py @@ -574,13 +574,18 @@ def _add_record(self, where, what, label=None): if rec_type not in self.records: self.records[rec_type] = {} - for w in where: + # # Get node segments only for nodes + is_node = ~np.array([is_NEURON_object(w) for w in where]) + node_segs = np.zeros(len(where), dtype=object) + node_segs[is_node] = self.get_node_segment(where[is_node]) + + for i, w in enumerate(where): # If this is a neuron object (e.g. segment, section or point # process) we assume this does not need mapping if is_NEURON_object(w): seg = w else: - seg = self.get_node_segment(w) + seg = node_segs[i] rec = neuron.h.Vector().record(getattr(seg, what))