Skip to content

Commit

Permalink
Added minimal current injection example
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Sep 30, 2024
1 parent fe56fcf commit f49590d
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 6 deletions.
2 changes: 2 additions & 0 deletions examples/notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ Here is a collection of Jupyter Notebooks, some of the workflows are split over
## Additional notebooks
* [Paired current injection](validation/synapses/network_pair_pulse_simulation.ipynb) in a simulated network
* [Neuromodulation examples](https://github.com/jofrony/Neuromodulation-software/tree/main/examples) in a network
* [Minimal current injection example](neuron_with_current_injection.ipynb)

320 changes: 320 additions & 0 deletions examples/notebooks/neuron_with_current_injection.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion snudda/neurons/neuron_model_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def define_parameters(self, parameter_config, parameter_id=None, parameter_key=N
bounds=bounds,
value=value))
elif param_config['type'] in ['section', 'range']:

if param_config['dist_type'] == 'uniform':
scaler = ephys.parameterscalers.NrnSegmentLinearScaler()
elif param_config['dist_type'] in ['exp', 'distance']:
Expand Down
28 changes: 23 additions & 5 deletions snudda/simulate/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,24 @@ def __init__(self,
elif network_file:
self.network_path = os.path.dirname(network_file)
else:
assert False, "You must give network_path or network_file"
self.write_log("No network network_path or network_file specified")
self.network_path = None

self.snudda_data = get_snudda_data(snudda_data=snudda_data,
network_path=self.network_path)

if not network_file:
self.network_file = os.path.join(self.network_path, "network-synapses.hdf5")
if not network_file and self.network_path is not None:
alt_network_file = os.path.join(self.network_path, "network-synapses.hdf5")
if os.path.isfile(alt_network_file):
self.network_file = alt_network_file
else:
self.network_file = None
else:
self.network_file = network_file

if self.network_file is None:
self.write_log(f"Warning: no network_file defined.", is_error=True)

if not input_file:
default_input_file = os.path.join(self.network_path, "input-spikes.hdf5")

Expand Down Expand Up @@ -204,6 +212,10 @@ def __init__(self,
with open(current_file, "rt") as f:
self.current_injection_info = json.load(f)

if "current_injection_info" in self.sim_info:
# This is merged with current injection info read from file (above)
self.current_injection_info |= self.sim_info["current_injection_info"]

else:
self.sim_info = None

Expand Down Expand Up @@ -272,7 +284,10 @@ def __init__(self,

# We need to initialise random streams, see Lytton el at 2016 (p2072)

self.load_network_info(self.network_file)
if self.network_file is not None:
self.load_network_info(self.network_file)
else:
self.write_log("No network path or file specified, not loading network.")

self.record = SnuddaSaveNetworkRecordings(output_file=self.output_file, network_data=self.network_info,
sample_dt=self.sample_dt, node_id=node_id)
Expand Down Expand Up @@ -2375,9 +2390,12 @@ def create_dir(self, dir_name):

def parse_current_injection_info(self):

if self.current_injection_info and self.verbose:
self.write_log(f"Parsing current_injection_info.")

for neuron_id, cur_info in self.current_injection_info.items():

if neuron_id not in self.neurons:
if int(neuron_id) not in self.neurons:
# Neuron not on this worker.
continue

Expand Down

0 comments on commit f49590d

Please sign in to comment.