neurodynex.tools package¶
Submodules¶
neurodynex.tools.input_factory module¶

neurodynex.tools.input_factory.
get_ramp_current
(t_start, t_end, unit_time, amplitude_start, amplitude_end, append_zero=True)[source]¶ Creates a ramp current. If t_start == t_end, then ALL entries are 0.
Parameters:  t_start (int) – start of the ramp
 t_end (int) – end of the ramp
 unit_time (Brian2 unit) – unit of t_start and t_end. e.g. 0.1*brian2.ms
 amplitude_start (Quantity) – amplitude of the ramp at t_start. e.g. 3.5*brian2.uamp
 amplitude_end (Quantity) – amplitude of the ramp at t_end. e.g. 4.5*brian2.uamp
 append_zero (bool, optional) – if true, 0Amp is appended at t_end+1. Without that trailing 0, Brian reads out the last value in the array (=amplitude_end) for all indices > t_end.
Returns: Brian2.TimedArray
Return type: TimedArray

neurodynex.tools.input_factory.
get_sinusoidal_current
(t_start, t_end, unit_time, amplitude, frequency, direct_current, phase_offset=0.0, append_zero=True)[source]¶ Creates a sinusoidal current. If t_start == t_end, then ALL entries are 0.
Parameters:  t_start (int) – start of the sine wave
 t_end (int) – end of the sine wave
 unit_time (Quantity, Time) – unit of t_start and t_end. e.g. 0.1*brian2.ms
 amplitude (Quantity, Current) – maximum amplitude of the sinus e.g. 3.5*brian2.uamp
 frequency (Quantity, Hz) – Frequency of the sine. e.g. 0.5*brian2.kHz
 direct_current (Quantity, Current) – DCcomponent (=offset) of the current
 phase_offset (float, Optional) – phase at t_start. Default = 0.
 append_zero (bool, optional) – if true, 0Amp is appended at t_end+1. Without that trailing 0, Brian reads out the last value in the array for all indices > t_end.
Returns: Brian2.TimedArray
Return type: TimedArray

neurodynex.tools.input_factory.
get_spikes_current
(t_spikes, unit_time, amplitude, append_zero=True)[source]¶ Creates a two dimensional TimedArray wich has one column for each value in t_spikes. All values in each column are 0 except one, the spike time as specified in t_spikes is set to amplitude. Note: This function is provided to easily insert pulse currents into a cable. For other use of spike input, search the Brian2 documentation for SpikeGeneration.
Parameters:  t_spikes (int) – list of spike times
 unit_time (Quantity, Time) – unit of t_spikes . e.g. 1*brian2.ms
 amplitude (Quantity, Current) – amplitude of the spike. All spikes have the sampe amplitude
 append_zero (bool, optional) – if true, 0Amp is appended at t_end+1. Without that trailing 0, Brian reads out the last value in the array for all indices > t_end.
Returns: Brian2.TimedArray
Return type: TimedArray

neurodynex.tools.input_factory.
get_step_current
(t_start, t_end, unit_time, amplitude, append_zero=True)[source]¶ Creates a step current. If t_start == t_end, then a single entry in the values array is set to amplitude.
Parameters:  t_start (int) – start of the step
 t_end (int) – end of the step
 unit_time (Brian2 unit) – unit of t_start and t_end. e.g. 0.1*brian2.ms
 amplitude (Quantity) – amplitude of the step. e.g. 3.5*brian2.uamp
 append_zero (bool, optional) – if true, 0Amp is appended at t_end+1.
 that trailing 0, Brian reads out the last value in the array (Without) –
Returns: Brian2.TimedArray
Return type: TimedArray

neurodynex.tools.input_factory.
get_zero_current
()[source]¶ Returns a TimedArray with one entry: 0 Amp
Returns: TimedArray
neurodynex.tools.plot_tools module¶

neurodynex.tools.plot_tools.
plot_ISI_distribution
(spike_stats, hist_nr_bins=50, xlim_max_ISI=None)[source]¶ Computes the ISI distribution of the given spike_monitor and displays the distribution in a histogram
Parameters:  spike_stats (neurodynex.tools.spike_tools.PopulationSpikeStats) – statistics of a population activity
 hist_nr_bins (int) – Number of histrogram bins. Default:50
 xlim_max_ISI (Quantity) – Default: None. In not None, the upper xlim of the plot is set to xlim_max_ISI. The CV does not change if this bound is set.
Returns: the figure

neurodynex.tools.plot_tools.
plot_network_activity
(rate_monitor, spike_monitor, voltage_monitor=None, spike_train_idx_list=None, t_min=None, t_max=None, N_highlighted_spiketrains=3, avg_window_width=1. * msecond, sup_title=None, figure_size=(10, 4))[source]¶ Visualizes the results of a network simulation: spiketrain, population activity and voltagetraces.
Parameters:  rate_monitor (PopulationRateMonitor) – rate of the population
 spike_monitor (SpikeMonitor) – spike trains of individual neurons
 voltage_monitor (StateMonitor) – optional. voltage traces of some (same as in spike_train_idx_list) neurons
 spike_train_idx_list (list) – optional. A list of neuron indices whose spiketrain is plotted. If no list is provided, all (up to 500) spiketrains in the spike_monitor are plotted. If None, the the list in voltage_monitor.record is used.
 t_min (Quantity) – optional. lower bound of the plotted time interval. if t_min is None, it is set to the larger of [0ms, (t_max  100ms)]
 t_max (Quantity) – optional. upper bound of the plotted time interval. if t_max is None, it is set to the timestamp of the last spike in
 N_highlighted_spiketrains (int) – optional. Number of spike trains visually highlighted, defaults to 3 If N_highlighted_spiketrains==0 and voltage_monitor is not None, then all voltage traces of the voltage_monitor are plotted. Otherwise N_highlighted_spiketrains voltage traces are plotted.
 avg_window_width (Quantity) – optional. Before plotting the population rate (PopulationRateMonitor), the rate is smoothed using a window of width = avg_window_width. Defaults is 1.0ms
 sup_title (String) – figure suptitle. Default is None.
 figure_size (tuple) – (width,height) tuple passed to pyplot’s figsize parameter.
Returns: The whole figure Axes: Top panel, Raster plot Axes: Middle panel, population activity Axes: Bottom panel, voltage traces. None if no voltage monitor is provided.
Return type: Figure

neurodynex.tools.plot_tools.
plot_population_activity_power_spectrum
(freq, ps, max_freq, average_At=None, plot_f0=False)[source]¶ Plots the power spectrum of the population activity A(t)
Parameters:  freq – frequencies (= x axis)
 ps – power spectrum of the population activity
 max_freq (Quantity) – The data is plotted in the interval [.05*max_freq, max_freq]
 plot_f0 (bool) – if true, the power at frequency 0 is plotted. Default is False and the value is not plotted.
Returns: the figure

neurodynex.tools.plot_tools.
plot_spike_train_power_spectrum
(freq, mean_ps, all_ps, max_freq, nr_highlighted_neurons=2, mean_firing_freqs_per_neuron=None, plot_f0=False)[source]¶ Visualizes the power spectrum of the spike trains.
Parameters:  freq – frequencies (= x axis)
 mean_ps – average power taken over all neurons (typically all of a subsample).
 all_ps (dict) – power spectra for each single neuron
 max_freq (Quantity) – The xlim of the plot is [0.05*max_freq, max_freq]
 mean_firing_freqs_per_neuron (float) – None or the mean firing rate averaged across the neurons. Default is None in which case the value is not shown in the legend
 plot_f0 (bool) – if true, the power at frequency 0 is plotted. Default is False and the value is not plotted.
Returns: all_ps[random_neuron_index]
Return type: the figure and the index of the random neuron for which the PS is computed
neurodynex.tools.spike_tools module¶
This the spike_tools submodule provides functions to analyse the Brian2 SpikeMonitors and Brian2 StateMonitors. The code provided here is not optimized for performance and there is no guarantee for correctness.
 Relevant book chapters:

class
neurodynex.tools.spike_tools.
PopulationSpikeStats
(nr_neurons, nr_spikes, all_ISI, filtered_spike_trains)[source]¶ Wraps a few spiketrain related properties.

CV
¶ Coefficient of Variation

all_ISI
¶ all ISIs in no specific order

filtered_spike_trains
¶ a timewindow filtered copy of the original spike_monitor.all_spike_trains

mean_isi
¶ Mean Inter Spike Interval

nr_neurons
¶ Number of neurons in the original population

nr_spikes
¶ Nr of spikes

std_isi
¶ Standard deviation of the ISI


neurodynex.tools.spike_tools.
filter_spike_trains
(spike_trains, window_t_min=0. * second, window_t_max=None, idx_subset=None)[source]¶  creates a new dictionary neuron_idx=>spike_times where all spike_times are in the
 half open interval [window_t_min,window_t_max)
Parameters:  spike_trains (dict) – a dictionary of spike trains. Typically obtained by calling spike_monitor.spike_trains()
 window_t_min (Quantity) – Lower bound of the time window: t>=window_t_min. Default is 0ms.
 window_t_max (Quantity) – Upper bound of the time window: t<window_t_max. Default is None, in which case no upper bound is set.
 idx_subset (list, optional) – a list of neuron indexes (dict keys) specifying a subset of neurons. Neurons NOT in the key list are NOT added to the resulting dictionary. Default is None, in which case all neurons are added to the resulting list.
Returns: a filtered copy of spike_trains

neurodynex.tools.spike_tools.
get_averaged_single_neuron_power_spectrum
(spike_monitor, sampling_frequency, window_t_min, window_t_max, nr_neurons_average=100, subtract_mean=False)[source]¶  averaged powerspectrum of spike trains in the time window [window_t_min, window_t_max).
 The power spectrum of every single neuron’s spike train is computed. Then the average across all singleneuron powers is computed. In order to limit the compuation time, the number of neurons taken to compute the average is limited to nr_neurons_average which defaults to 100
Parameters:  spike_monitor (SpikeMonitor) – Brian2 SpikeMonitor
 sampling_frequency (Quantity) – sampling frequency used to discretize the spike trains.
 window_t_min (Quantity) – Lower bound of the time window: t>=window_t_min. Spikes before window_t_min are not taken into account (set a lower bound if you want to exclude an initial transient in the population activity)
 window_t_max (Quantity) – Upper bound of the time window: t<window_t_max.
 nr_neurons_average (int) – Number of neurons over which the average is taken.
 subtract_mean (bool) – If true, the mean value of the signal is subtracted before FFT. Default is False
Returns: freq, mean_ps, all_ps_dict, mean_firing_rate, mean_firing_freqs_per_neuron

neurodynex.tools.spike_tools.
get_population_activity_power_spectrum
(rate_monitor, delta_f, k_repetitions, T_init=100. * msecond, subtract_mean_activity=False)[source]¶ Computes the power spectrum of the population activity A(t) (=rate_monitor.rate)
Parameters:  rate_monitor (RateMonitor) – Brian2 rate monitor. rate_monitor.rate is the signal being analysed here. The temporal resolution is read from rate_monitor.clock.dt
 delta_f (Quantity) – The desired frequency resolution.
 k_repetitions (int) – The data rate_monitor.rate is split into k_repetitions which are FFT’d independently and then averaged in frequency domain.
 T_init (Quantity) – Rates in the time interval [0, T_init] are removed before doing the Fourier transform. Use this parameter to ignore the initial transient signals of the simulation.
 subtract_mean_activity (bool) – If true, the mean value of the signal is subtracted. Default is False
Returns: freqs, ps, average_population_rate

neurodynex.tools.spike_tools.
get_spike_stats
(voltage_monitor, spike_threshold)[source]¶ Detects spike times and computes ISI, mean ISI and firing frequency. Note: meanISI and firing frequency are set to numpy.nan if less than two spikes are detected Note: currently only the spike times of the first column in voltage_monitor are detected. Matrixlike monitors are not supported. :param voltage_monitor: A state monitor with at least the fields “v: and “t” :type voltage_monitor: StateMonitor :param spike_threshold: The spike threshold voltage. e.g. 50*b2.mV :type spike_threshold: Quantity
Returns: (nr_of_spikes, spike_times, isi, mean_isi, spike_rate) Return type: tuple

neurodynex.tools.spike_tools.
get_spike_time
(voltage_monitor, spike_threshold)[source]¶ Detects the spike times in the voltage. The spike time is the value in voltage_monitor.t for which voltage_monitor.v[idx] is above threshold AND voltage_monitor.v[idx1] is below threshold (crossing from below). Note: currently only the spike times of the first column in voltage_monitor are detected. Matrixlike monitors are not supported. :param voltage_monitor: A state monitor with at least the fields “v: and “t” :type voltage_monitor: StateMonitor :param spike_threshold: The spike threshold voltage. e.g. 50*b2.mV :type spike_threshold: Quantity
Returns: A list of spike times (Quantity)

neurodynex.tools.spike_tools.
get_spike_train_stats
(spike_monitor, window_t_min=0. * second, window_t_max=None)[source]¶ Analyses the spike monitor and returns a PopulationSpikeStats instance.
Parameters:  spike_monitor (SpikeMonitor) – Brian2 spike monitor
 window_t_min (Quantity) – Lower bound of the time window: t>=window_t_min. The stats are computed for spikes within the time window. Default is 0ms
 window_t_max (Quantity) – Upper bound of the time window: t<window_t_max. The stats are computed for spikes within the time window. Default is None, in which case no upper bound is set.
Returns: PopulationSpikeStats

neurodynex.tools.spike_tools.
pretty_print_spike_train_stats
(voltage_monitor, spike_threshold)[source]¶ Computes and returns the same values as get_spike_stats. Additionally prints these values to the console. :param voltage_monitor: :param spike_threshold:
Returns: (nr_of_spikes, spike_times, isi, mean_isi, spike_rate) Return type: tuple