From faf1d69cb19245cb38d06e840192c43737cb069c Mon Sep 17 00:00:00 2001 From: Johannes Hjorth Date: Thu, 26 Oct 2023 10:50:02 +0200 Subject: [PATCH] Working on handling soma only --- snudda/core.py | 9 +++++ snudda/detect/detect.py | 47 ++++++++++++++----------- snudda/neurons/morphology_data.py | 4 +++ snudda/neurons/neuron_model_extended.py | 2 -- snudda/simulate/simulate.py | 3 ++ 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/snudda/core.py b/snudda/core.py index 51d635721..965dae88a 100755 --- a/snudda/core.py +++ b/snudda/core.py @@ -216,6 +216,8 @@ def place_neurons(self, self.stop_parallel() self.close_log_file() + return sp + ############################################################################ def touch_detection_wrapper(self, args): @@ -318,6 +320,8 @@ def touch_detection(self, self.stop_parallel() self.close_log_file() + return sd, sp + ############################################################################ def prune_synapses_wrapper(self, args): @@ -390,6 +394,8 @@ def prune_synapses(self, self.stop_parallel() self.close_log_file() + return sp + ############################################################################ def setup_input_wrapper(self, args): @@ -472,6 +478,8 @@ def setup_input(self, self.stop_parallel() self.close_log_file() + return si + ############################################################################ def export_to_SONATA_wrapper(self, args): @@ -752,6 +760,7 @@ def simulate(self, print(f"Program run time: {stop - start:.1f}s") # sim.plot() + return sim ############################################################################ diff --git a/snudda/detect/detect.py b/snudda/detect/detect.py index 1c81314a6..636b8a6b2 100644 --- a/snudda/detect/detect.py +++ b/snudda/detect/detect.py @@ -550,26 +550,33 @@ def get_hypervoxel_coords_and_section_id(self, neuron=None, neuron_info=None): hyper_voxel_id = self.hyper_voxel_id_lookup[tuple(hyper_voxel_coords[inside_idx, :].T)] section_type_id = subtree.section_data[inside_idx, :][:, [2, 0]] - hid_st_sid = np.hstack([hyper_voxel_id.reshape([hyper_voxel_id.shape[0], 1]), section_type_id]) - - # We also need to add parent points with the child branch's section id - # This is so we do not miss the first bit between the parent point and the first real point of the branch - parent_rows = [] - if inside_idx.all(): - # If inside_idx are all True then hyper_voxel_id is same length - # as subtree.geometry (should be valid for all but possibly Virtual Axons) - - for tree_type in subtree.sections: - for section in subtree.sections[tree_type].values(): - - if section.section_type == 1: - # Soma has no parent, skip - continue - - parent_idx = section.point_idx[0] - parent_rows.append([hyper_voxel_id[parent_idx], section.section_type, section.section_id]) - - tree_info[subtree_name] = np.unique(np.vstack([hid_st_sid, parent_rows]), axis=0) + tree_info[subtree_name] = np.hstack([hyper_voxel_id.reshape([hyper_voxel_id.shape[0], 1]), section_type_id]) + + # TODO: This should no longer be necessary! PARENT POINT should be included if + # parent section type is the same + # + # # We also need to add parent points with the child branch's section id + # # This is to not miss the first bit between the parent point and the first real point of the branch + # parent_rows = [] + # if inside_idx.all(): + # # If inside_idx are all True then hyper_voxel_id is same length + # # as subtree.geometry (should be valid for all but possibly Virtual Axons) + # + # for tree_type in subtree.sections: + # for section in subtree.sections[tree_type].values(): + # + # if section.section_type == 1: + # # Soma has no parent, skip + # continue + # + # parent_idx = section.point_idx[0] + # parent_rows.append([hyper_voxel_id[parent_idx], section.section_type, section.section_id]) + # + # if len(parent_rows) > 0: + # tree_info[subtree_name] = np.unique(np.vstack([hid_st_sid, parent_rows]), axis=0) + # else: + # # This is the case if we only have a soma + # tree_info[subtree_name] = hid_st_sid # OBS, there is a rare case when a line segment starts in a hyper voxel, crosses a second hyper voxel # and ends up in a third hyper voxel. In this case the intermediate second hyper voxel will be missed if diff --git a/snudda/neurons/morphology_data.py b/snudda/neurons/morphology_data.py index 85838b599..7b76fb23f 100644 --- a/snudda/neurons/morphology_data.py +++ b/snudda/neurons/morphology_data.py @@ -252,6 +252,10 @@ def load_swc_file(self, swc_file=None, remapping_types={4: 3}, use_cache=True): data = np.loadtxt(swc_file) + if len(data.shape) == 1: + # This is to handle case when we only have a soma + data = data.reshape([1, 7]) + if any(np.diff(data[:, 0]) != 1): raise IndexError(f"SWC file has gaps in ID numbering ({swc_file})") diff --git a/snudda/neurons/neuron_model_extended.py b/snudda/neurons/neuron_model_extended.py index b1937c61e..dd0895e68 100644 --- a/snudda/neurons/neuron_model_extended.py +++ b/snudda/neurons/neuron_model_extended.py @@ -277,8 +277,6 @@ def define_morphology(self, replace_axon=True, morph_file=None): assert (morph_file is not None) - # print("Using morphology: " + morph_file) - return ephys.morphologies.NrnFileMorphology(morph_file, do_replace_axon=replace_axon) # OLD BUGFIX FOR segment pop diff --git a/snudda/simulate/simulate.py b/snudda/simulate/simulate.py index 930e71e8a..95858c207 100644 --- a/snudda/simulate/simulate.py +++ b/snudda/simulate/simulate.py @@ -1234,6 +1234,9 @@ def set_resting_voltage(self, neuron_id, rest_volt=None): self.write_log(f"Neuron {self.neurons[neuron_id].name} ({neuron_id}) resting voltage = {rest_volt * 1e3}") + # import pdb + # pdb.set_trace() + soma = [x for x in self.neurons[neuron_id].icell.soma] axon = [x for x in self.neurons[neuron_id].icell.axon] dend = [x for x in self.neurons[neuron_id].icell.dend]