snudda.input.input

class snudda.input.input.SnuddaInput(network_path=None, snudda_data=None, input_config_file=None, spike_data_filename=None, hdf5_network_file=None, time=10.0, is_master=True, h5libver='latest', rc=None, random_seed=None, time_interval_overlap_warning=True, logfile=None, verbose=False, use_meta_input=True)[source]

Generates input for the simulation.

Constructor.

Parameters:
  • network_path (str) – Path to network directory

  • snudda_data (str) – Path to Snudda Data

  • input_config_file (str) – Path to input config file, default input.json in network_path

  • spike_data_filename (str) – Path to output file, default input-spikes.hdf5

  • hdf5_network_file (str) – Path to network file, default network-synapses.hdf5

  • time (float) – Duration of simulation to generate input for, default 10 seconds

  • is_master (bool) – “master” or “worker”

  • h5libver (str) – Version of HDF5 library to use, default “latest”

  • rc – ipyparallel remote client

  • random_seed (int) – Random seed for input generation

  • time_interval_overlap_warning (bool) – Warn if input intervals specified overlap

  • logfile (str) – Log file

  • verbose (bool) – Print logging

add_csv_input(neuron_id, input_inf, input_type, rng_master)[source]

This code loads and input spikes defined in csv format.

Parameters:
  • neuron_id (int) – ID of neuron

  • input_inf (dict) – Input info of the specific neuron/input_type

  • rng_master – Numpy random stream

Returns:

csv_input (dict)

add_external_input(neuron_id, input_type, input_inf)[source]

This function sets up input_info for external input generation (not csv input).

Parameters:
  • neuron_id (int) – ID of neuron

  • input_type (str) – Name of input type

  • input_inf (dict) – Input info for neuron_id/input_type

Returns:

Formatted input_inf with default parameters

Return type:

input_inf (dict)

add_meta_input(neuron_id, input_info)[source]

The input has two parts.

The first part is defined by input.json

In addition each neuron model has a meta.json file, which can also define an input specifically for that morphology_key/parameter_key combination. This allows the modeller to specify more input to less excitable neurons if needed.

The meta.json typically contains both a background input (with number of inputs and frequency defined), and signal input (e.g. cortical or thalamic) which has the number of inputs defined, but the input frequency default set to 0. This input frequency can then be overridden in input.json to allow the user cell-model-specific control over input.

This function adds the meta.json input to the input_info.

Parameters:
  • neuron_id (int) – ID of neuron

  • input_info (dict) – Input information for neuron_id

Returns:

Updated input information, now including meta.json input

Return type:

input_info (dict)

add_soma_synapses(input_loc, n_soma_synapses, neuron_id)[source]

Add synapses specifically on the soma.

Parameters:
  • input_loc – xyz, sec_id, sec_x, dist_to_soma

  • n_soma_synapses (int) – Number of somatic synapses

  • neuron_id (int) – ID of neuron

check_sorted()[source]

Checks that spikes are in chronological order.

static create_spike_matrix(spikes)[source]

Creates a spike matrix from a list of spikes.

static cull_spikes(spikes, p_keep, rng, time_range=None)[source]

Keeps a fraction of all spikes.

Parameters:
  • spikes – Spike train

  • p_keep – Probability to keep each spike

  • rng – Numpy random number stream

  • time_range – If p_keep is vector, this specifies which part of those ranges each p_keep is for

dendrite_input_locations(neuron_id, rng, synapse_density=None, num_spike_trains=None, cluster_size=None, cluster_spread=3e-05)[source]

Return dendrite input location.

Parameters:
  • neuron_id – Neuron ID

  • rng – Numpy random number stream

  • synapse_density (str) – Distance function f(d)

  • num_spike_trains (int) – Number of spike trains

  • cluster_size (int) – Size of each synaptic cluster (None = No clustering)

  • cluster_spread (float) – Spread of cluster along dendrite (in meters)

static estimate_correlation(spikes_a, spikes_b, dt=0)[source]

Estimate correlation between spikes_a and spikes_b, assuming correlation window of dt.

Parameters:
  • spikes_a

  • spikes_b

  • dt

generate()[source]

Generates input for network. This umbrella function takes care of everything and saves input-spikes.hdf5

generate_log_normal_spikes(mean_freq, std_freq, time_ranges, rng)[source]

Generate spike times using log-normal distribution for inter-spike intervals.

Parameters: - mean_freq: array-like, mean firing frequency for each time range (Hz) - std_freq: array-like, standard deviation of firing frequency (Hz) - time_ranges: tuple of (start_times, end_times) arrays - rng: numpy random number generator

Returns: - sorted array of spike times

generate_poisson_spikes(freq, time_range, rng)[source]

This generates poisson spikes with frequency freq, for a given time range

Parameters:
  • freq (float) – frequency

  • time_range (float, float) – start and end time of input with frequency

  • rng – Numpy random stream

generate_poisson_spikes_helper(frequencies, time_ranges, rng)[source]

Generates spike trains with given frequencies within time_ranges, using rng stream.

Parameters:
  • frequencies (list) – List of frequencies

  • time_ranges (list) – List of tuples with start and end time for each frequency range

  • rng – Numpy random stream

generate_seeds(num_states)[source]

From the master seed, generate a seed sequence for inputs.

generate_spikes_function(frequency_function, time_range, rng, dt=0.0001, p_keep=1)[source]

Generates frequency based on frequency_function.

Args
frequency_function: vector based python function taking t as argument, returning momentary frequency

if it is not a python then numexpr.evaluate is run on it (with t as argument) OBS: t passed to the function is 0 at the stimultion start time, e.g. for a stimulus that starts at time 4s seconds, f(t=0) is calculated, and at the end 5s f(t=1) is calculated.

time_range: Interval of time to generate spikes for rng: Numpy rng object dt: timestep

generate_spikes_function_helper(frequencies, time_ranges, rng, dt, p_keep=1)[source]

Generates spike trains with given frequencies within time_ranges, using rng stream.

Parameters:
  • frequencies (list) – List of frequencies

  • time_ranges (list) – List of tuples with start and end time for each frequency range

  • rng – Numpy random stream

  • dt – timestep

generate_spikes_helper(frequency, time_range, rng, input_generator=None, std_freq=None)[source]

Helper function to generate spikes with different input generators

Parameters:
  • frequency (float) – Frequency of input

  • time_range (float, float) – Start and end time of input

  • rng – Numpy random stream

  • input_generator (str) – Name of input generator

  • std_freq (float) – Standard deviation, optional, used for lognormal

get_location_random_seed(neuron_id, input_type, input_inf)[source]

Allow user to define random_seed for csv input that depends on morphology_key and parameter_key.

Parameters:
  • neuron_id (int) – ID of neuron

  • input_type (str) – Name of input_type

  • input_inf (dict) – Input info for neuron_id/input_type

get_master_node_rng()[source]

Get random number for master node, from master seed.

input_update_random_seeds()[source]

Sets a unique random_seed for each input_type on every neuron, to make inputs reproducible on parallel architectures.

static jitter_spikes(spike_trains, dt, rng, time_range=None)[source]

Jitter spikes in a spike train.

If a time_range (start,end_time) is given then all spike times will be modulo duration, so if we jitter and they go to before start time, they wrap around and appear at end of the timeline

Parameters:
  • spike_trains – spike times

  • dt – amount of jitter

  • rng – Numpy random stream

  • time_range (tuple) – (start, end) see comment above about wrapping around edges.

load_network(hdf5_network_file=None)[source]

Load network file using snudda.load

Parameters:

hdf5_network_file – path to network file

make_correlated_spikes(freq, time_range, num_spike_trains, p_keep, rng, population_unit_spikes=None, ret_pop_unit_spikes=False, jitter_dt=None, input_generator=None, std_freq=None)[source]

Make correlated spikes.

Parameters:
  • freq (float or str) – frequency of spike train

  • time_range (tuple) – start time, end time of spike train

  • num_spike_trains (int) – number of spike trains to generate

  • p_keep (float or list of floats) – fraction of shared channel spikes to include in spike train, p_keep=1 (100% correlated)

  • rng – Numpy random number stream

  • population_unit_spikes

  • ret_pop_unit_spikes (bool) – if false, returns only spikes, if true returns (spikes, population unit spikes)

  • jitter_dt (float) – amount to jitter all spikes

  • input_generator (str) – “poisson” (default) or “frequency_functon”

  • std_freq (float) – Standard deviation of frequency, used for lognormal

make_neuron_input_parallel()[source]

Generate external input for every neuron. Runs in parallel if rc (Remote Client) has been provided at initialisation.

File format: “config” –> str represenation of JSON config file data “input”

–> cell id, e.g. “0”, “1”, “2”
–> input_name, e.g. “cortical”, “thalamic”, …
attrs: ‘conductance’ – 1 float, synapse conductance in siemens (S)

‘distance_to_soma’ – n floats, distance to soma in meters (m) ‘mod_file’ – str, NEURON mod file, e.g. ‘tmGlut’ ‘parameter_file’ – str, path to JSON parameter file ‘parameter_id’ – n integers, parameter id of synapse ‘parameter_list’ – str representation of list of dictionaries with parameters

parameter_id[x] % len(parameter_list) is used for synapse X

‘population_unit_id’ – int, population unit id this input belongs to ‘section_id’ – n int, section id on neuron where synapse is located ‘section_x’ – n float, section x for synapse ‘synapse_density’ – str, equation used to place the input on the dendrites

–> spikes – spike matrix, size n x m, float

Each row corresponds to one spike train for a synapse the rows are padded with -1 when spikes are missing

attrs:

‘start’ – 1 float, start time of spike trains ‘end’ – 1 float, end time of spike trains ‘freq’ – 1 float, frequency of spike trains ‘correlation’ – 1 float, correlation of spike train ‘generator’ – str, method used to generate spikes ‘num_spikes’ – n integers, number of spikes in each spike train

make_population_unit_spike_trains(rng)[source]

Generate population unit spike trains. Each synaptic input will contain a fraction of population unit spikes, which are taken from a stream of spikes unique to that particular population unit This function generates these correlated spikes

Parameters:

rng – Numpy random stream

make_uncorrelated_spikes(freq, t_start, t_end, n_spike_trains, rng)[source]

Generate uncorrelated spikes.

Parameters:
  • freq – frequency

  • t_start – start time

  • t_end – end time

  • n_spike_trains – number of spike trains to generate

  • rng – numpy random number stream

mark_virtual(neuron_id)[source]

Specify a certain neuron as virtual.

Parameters:

neuron_id (int) – ID of neuron to make virtual

static mix_fraction_of_spikes(spikes_a, spikes_b, fraction_a, fraction_b, rng, time_range=None)[source]

Picks fraction_a of spikes_a and fraction_b of spikes_b and returns sorted spike train

Parameters:
  • spikes_a (np.array) – Spike train A

  • spikes_b (np.array) – Spike train B

  • fraction_a (float) – Fraction of spikes in train A picked, e.g 0.4 means 40% of spikes are picked

  • fraction_b (float) – Fraction of spikes in train B picked

  • rng – Numpy rng object

  • time_range – (start_times, end_times) for the different fractions

static mix_fraction_of_spikes_OLD(spikes_a, spikes_b, fraction_a, fraction_b, rng)[source]

Picks fraction_a of spikes_a and fraction_b of spikes_b and returns sorted spike train

Parameters:
  • spikes_a (np.array) – Spike train A

  • spikes_b (np.array) – Spike train B

  • fraction_a (float) – Fraction of spikes in train A picked, e.g 0.4 means 40% of spikes are picked

  • fraction_b (float) – Fraction of spikes in train B picked

  • rng – Numpy rng object

static mix_spikes(spikes)[source]

Mixes spikes in list of spike trains into one sorted spike train.

plot_spikes(neuron_id=None)[source]

Plot spikes for neuron_id

process_neuron_input()[source]

Helper function to parallelize input generation

static raster_plot(spike_times, mark_spikes=None, mark_idx=None, title=None, fig_file=None, fig=None)[source]

Raster plot of spike trains.

Parameters:
  • spike_times

  • mark_spikes – list of spikes to mark

  • mark_idx – index of neuron with spikes to mark

  • title – title of plot

  • fig_file – path to figure

  • fig – matplotlib figure object

read_input_config_file()[source]

Read input configuration from JSON file.

The path is defined in self.input_config_file

read_network_config_file()[source]

Read network configuration JSON file.

setup_parallel()[source]

Setup worker nodes for parallel execution.

verify_correlation(spike_trains, dt=0)[source]

Verify correlation. This function is slow.

Parameters:
  • spike_trains

  • dt

write_hdf5()[source]

Writes input spikes to HDF5 file (input-spikes.hdf5 in the network folder).

write_log(text, flush=True, is_error=False, force_print=False)[source]

Writes to log file. Use setup_log first. Text is only written to screen if self.verbose=True, or is_error = True, or force_print = True.

test (str) : Text to write flush (bool) : Should all writes be flushed to disk directly? is_error (bool) : Is this an error, always written. force_print (bool) : Force printing, even if self.verbose=False.