Skip to content

Commit

Permalink
Updated virtual neuron code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Nov 24, 2023
1 parent f15ac97 commit 788e95a
Show file tree
Hide file tree
Showing 5 changed files with 8,025 additions and 402 deletions.
68 changes: 68 additions & 0 deletions examples/notebooks/lateral_inhitibion/input-virtual.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"dSPN": {
"Ctx_1" : {
"generator" : "poisson",
"start" : [0.5, 3.5],
"end" : [1.5, 4.5],
"frequency" : [25, 25],
"conductance" : 0.5e-9,
"nInputs" : 50,
"populationUnitCorrelation" : [0.5, 0.5],
"populationUnitID" : 1,
"jitter" : 0.01,
"modFile": "tmGlut"
},

"Ctx_2" : {
"generator" : "poisson",
"start" : [2, 3.5],
"end" : [3, 4.5],
"frequency" : [5, 5],
"conductance" : 0.5e-9,
"nInputs" : 50,
"populationUnitCorrelation" : [0.5, 0.5],
"populationUnitID" : 2,
"jitter" : 0.01,
"modFile": "tmGlut"
},

"VirtualNeuron" : {
"spikeFile": "virtual_input_spikes.txt",
"rowMappingFile": "virtual_input_mapping.txt"
}
},

"iSPN": {
"Ctx_1" : {
"generator" : "poisson",
"start" : [0.5, 3.5],
"end" : [1.5, 4.5],
"frequency" : [25, 25],
"conductance" : 0.5e-9,
"nInputs" : 50,
"populationUnitCorrelation" : [0.5, 0.5],
"populationUnitID" : 1,
"jitter" : 0.01,
"modFile": "tmGlut"
},

"Ctx_2" : {
"generator" : "poisson",
"start" : [2, 3.5],
"end" : [3, 4.5],
"frequency" : [5, 5],
"conductance" : 0.5e-9,
"nInputs" : 50,
"populationUnitCorrelation" : [0.5, 0.5],
"populationUnitID" : 2,
"jitter" : 0.01,
"modFile": "tmGlut"
},

"VirtualNeuron" : {
"spikeFile": "virtual_input_spikes.txt",
"rowMappingFile": "virtual_input_mapping.txt"
}
}

}
7,756 changes: 7,756 additions & 0 deletions examples/notebooks/lateral_inhitibion/lateral_inhibition_virtual.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

48 changes: 33 additions & 15 deletions snudda/plotting/plot_neuron_voltage.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ def plot_neuron_voltage(self, neuron_id, section_id=None, axis=None,

time, volt, sec_id, sec_x = self.get_voltage_sec(neuron_id=neuron_id, section_id=section_id)

ax.plot(time, volt)
soma_dist = self.get_soma_dist(neuron_id=neuron_id, section_id=sec_id, section_x=sec_x)
label = [f"Neuron {neuron_id}, sec {sid}:{sx}, dist {sd*1e6:.1f} um" for (sid, sx, sd) in zip(sec_id, sec_x, soma_dist)]

ax.plot(time, volt, label=label)

plt.legend()

if fig_name:
self.create_fig_dir(fig_name)
Expand All @@ -86,6 +91,13 @@ def plot_neuron_voltage(self, neuron_id, section_id=None, axis=None,

return ax

def list_all_section_dist(self, neuron_id):

morphology = self.load_morphology(neuron_id=neuron_id)

for section in morphology.morphology_data["neuron"].sections[3].values():
print(f"Section {section.section_id}, center dist {section.soma_distance_at(0.5)*1e6:.0f} um, length {section.section_length()*1e6:.0f} um")

def create_fig_dir(self, fig_path):

fig_dir = os.path.dirname(fig_path)
Expand Down Expand Up @@ -115,21 +127,8 @@ def plot_binned_neuron_voltage(self, neuron_id, time_bins, section_id=None, dist
else:
ax = axis

morphology = self.load_morphology(neuron_id=neuron_id)

time, volt, sec_id, sec_x = self.get_voltage_sec(neuron_id=neuron_id, section_id=section_id)

soma_dist = np.zeros(sec_id.shape)

for idx, (s_id, s_x) in enumerate(zip(sec_id, sec_x)):

if s_id < 0:
sec_type = 1 # soma
s_id = 0
else:
sec_type = 3 # dend

soma_dist[idx] = morphology.morphology_data["neuron"].sections[sec_type][s_id].soma_distance_at(s_x)
soma_dist = self.get_soma_dist(neuron_id=neuron_id, section_id=sec_id, section_x=sec_x)

# First bin is soma only, bins after are for dendrites (with binwidth dist_bin_size)
bin_idx = np.floor(soma_dist / dist_bin_size).astype(int) + 1
Expand Down Expand Up @@ -191,6 +190,25 @@ def plot_binned_neuron_voltage(self, neuron_id, time_bins, section_id=None, dist
return ax


def get_soma_dist(self, neuron_id, section_id, section_x):

morphology = self.load_morphology(neuron_id=neuron_id)

soma_dist = np.zeros(section_id.shape)

for idx, (sec_id, sec_x) in enumerate(zip(section_id, section_x)):

if sec_id < 0:
sec_type = 1 # soma
sec_id = 0
else:
sec_type = 3 # dend

soma_dist[idx] = morphology.morphology_data["neuron"].sections[sec_type][sec_id].soma_distance_at(sec_x)

return soma_dist


def cli():

import argparse
Expand Down
2 changes: 1 addition & 1 deletion snudda/utils/ablate_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def make_virtual(self, neuron_id):
if type(neuron_id) == list:
self.make_virtual_neuron_id += neuron_id
elif isinstance(neuron_id, np.ndarray):
self.make_virtual_neuron_id += [x for x in np.ndarray]
self.make_virtual_neuron_id += [x for x in neuron_id]
else:
self.make_virtual_neuron_id.append(neuron_id)

Expand Down

0 comments on commit 788e95a

Please sign in to comment.