allensdk.model.glif package¶
Submodules¶
allensdk.model.glif.glif_neuron module¶

exception
allensdk.model.glif.glif_neuron.
GlifBadResetException
(message, dv)[source]¶ Bases:
exceptions.Exception
Exception raised when voltage is still above threshold after a reset rule is applied.

class
allensdk.model.glif.glif_neuron.
GlifNeuron
(El, dt, asc_tau_array, R_input, C, asc_amp_array, spike_cut_length, th_inf, th_adapt, coeffs, AScurrent_dynamics_method, voltage_dynamics_method, threshold_dynamics_method, AScurrent_reset_method, voltage_reset_method, threshold_reset_method, init_voltage, init_threshold, init_AScurrents, **kwargs)[source]¶ Bases:
object
Implements the currentbased Mihalas Neiber GLIF neuron. Simulations model the voltage, threshold, and afterspike currents of a neuron given an input stimulus. A set of modular dynamics rules are applied until voltage crosses threshold, at which point a set of modular reset rules are applied. See glif_neuron_methods.py for a list of what options there are for voltage, threshold, and afterspike current dynamics and reset rules.
Parameters: El : float
resting potential
 dt : float
duration between time steps
 asc_tau_array: np.ndarray
TODO
 R_input : float
input resistance
 C : float
capacitance
 asc_amp_arrap : np.ndarray
afterspike current vector. one element per element of asc_tau_array.
 spike_cut_length : int
how many time steps to replace with NaNs when a spike occurs.
 th_inf : float
instantaneous threshold
 coeffs : dict
dictionary coefficients premultiplied to neuron properties during simulation. used for optimization.
 AScurrent_dynamics_method : dict
dictionary containing the ‘name’ of the afterspike current dynamics method to use and a ‘params’ dictionary parameters to pass to that function.
 voltage_dynamics_method : dict
dictionary containing the ‘name’ of the voltage dynamics method to use and a ‘params’ dictionary parameters to pass to that function.
 threshold_dynamics_method : dict
dictionary containing the ‘name’ of the threshold dynamics method to use and a ‘params’ dictionary parameters to pass to that function.
 AScurrent_reset_method : dict
dictionary containing the ‘name’ of the afterspike current dynamics method to use and a ‘params’ dictionary parameters to pass to that function.
 voltage_reset_method : dict
dictionary containing the ‘name’ of the voltage dynamics method to use and a ‘params’ dictionary parameters to pass to that function.
 threshold_reset_method : dict
dictionary containing the ‘name’ of the threshold dynamics method to use and a ‘params’ dictionary parameters to pass to that function.
 init_voltage : float
initial voltage value
 init_threshold : float
initial spike threshold value
 init_AScurrents : np.ndarray
initial afterspike current vector. one element per element of asc_tau_array.

TYPE
= 'GLIF'¶

static
configure_library_method
(method_type, params)[source]¶ Create a GlifNeuronMethod instance out of a library of functions organized by type name. This refers to the METHOD_LIBRARY in glif_neuron_methods.py, which lays out the available functions that can be used for dynamics and reset rules.
Parameters: method_type : string
the name of a function category (e.g. ‘AScurrent_dynamics_method’ for the afterspike current dynamics methods)
params : dict
a dictionary with two members. ‘name’: the string name of function you want, and ‘params’: parameters you want to pass to that function
Returns: GlifNeuronMethod
a GlifNeuronMethod instance

static
configure_method
(method_name, method, method_params)[source]¶ Create a GlifNeuronMethod instance given a name, a function, and function parameters. This is just a shortcut to the GlifNeuronMethod constructor.
Parameters: method_name : string
name for refering to this method later
method : function
a python function
method_parameters : dict
function arguments whose values should be fixed
Returns: GlifNeuronMethod
a GlifNeuronMethod instance

dynamics
(voltage_t0, threshold_t0, AScurrents_t0, inj, time_step, spike_time_steps)[source]¶ Update the voltage, threshold, and afterspike currents of the neuron for a single time step.
Parameters: voltage_t0 : float
the current voltage of the neuron
threshold_t0 : float
the current spike threshold level of the neuron
AScurrents_t0 : np.ndarray
the current state of the afterspike currents in the neuron
inj : float
the current value of the current injection into the neuron
time_step : int
the current time step of the neuron simulation
spike_time_steps : list
a list of all of the time steps of spikes in the neuron
Returns: tuple
voltage_t1 (voltage at next time step), threshold_t1 (threshold at next time step), AScurrents_t1 (afterspike currents at next time step)

reset
(voltage_t0, threshold_t0, AScurrents_t0)[source]¶ Apply reset rules to the neuron’s voltage, threshold, and afterspike currents assuming a spike has occurred (voltage is above threshold).
Parameters: voltage_t0 : float
the current voltage of the neuron
threshold_t0 : float
the current spike threshold level of the neuron
AScurrents_t0 : np.ndarray
the current state of the afterspike currents in the neuron
Returns: tuple
voltage_t1 (voltage at next time step), threshold_t1 (threshold at next time step), AScurrents_t1 (afterspike currents at next time step)

run
(stim)[source]¶ Run neuron simulation over a given stimulus. This steps through the stimulus applying dynamics equations. After each step it checks if voltage is above threshold. If so, self.spike_cut_length NaNs are inserted into the output voltages, reset rules are applied to the voltage, threshold, and afterspike currents, and the simulation resumes.
Parameters: stim : np.ndarray
vector of scalar current values
Returns: dict
 a dictionary containing:
‘voltage’: simulated voltage values, ‘threshold’: threshold values during the simulation, ‘AScurrents’: afterspike current values during the simulation, ‘grid_spike_times’: spike times (in uits of self.dt) aligned to simulation time steps, ‘interpolated_spike_times’: spike times (in units of self.dt) linearly interpolated between time steps, ‘spike_time_steps’: the indices of grid spike times, ‘interpolated_spike_voltage’: voltage of the simulation at interpolated spike times, ‘interpolated_spike_threshold’: threshold of the simulation at interpolated spike times

tau_m
¶

allensdk.model.glif.glif_neuron.
interpolate_spike_time
(dt, time_step, threshold_t0, threshold_t1, voltage_t0, voltage_t1)[source]¶ Given two voltage and threshold values, the dt between them and the initial time step, interpolate a spike time within the dt interval by intersecting the two lines.

allensdk.model.glif.glif_neuron.
interpolate_spike_value
(dt, interpolated_spike_time_offset, v0, v1)[source]¶ Take a value at two adjacent time steps and linearly interpolate what the value would be at an offset between the two time steps.
allensdk.model.glif.glif_neuron_methods module¶
The methods in this module are used for configuring dynamics and reset rules for the GlifNeuron. For more details on how to use these methods, see Generalized LIF Models.

class
allensdk.model.glif.glif_neuron_methods.
GlifNeuronMethod
(method_name, method, method_params)[source]¶ Bases:
object
A simple class to keep track of the name and parameters associated with a neuron method. This class is initialized with a name, function, and parameters to pass to the function. The function then has those passed parameters fixed to a partial function using functools.partial. This class then mimics a function itself using the __call__ convention. Parameters that are not fixed in this way are assumed to be passed into the method when it is called. If the passed parameters contain an argument that is not part of the function signature, an exception will be raised.
Parameters: method_name : string
A shorthand name that will be used to reference this method in the GlifNeuron.
method : function
A python function to be called when this instance is called.
method_params : dict
A dictionary mapping function arguments to values for values that should be fixed.

modify_parameter
(param, operator)[source]¶ Modify a function parameter needs to be modified after initialization.
Parameters: param : string
the name of the parameter to modify
operator : callable
a function or lambda that returns the desired modified value
Returns: type
the new value of the variable that was just modified.


allensdk.model.glif.glif_neuron_methods.
METHOD_LIBRARY
= {'voltage_dynamics_method': {'linear_forward_euler': <function dynamics_voltage_linear_forward_euler at 0x7f5f7de65320>}, 'threshold_dynamics_method': {'three_components_exact': <function dynamics_threshold_three_components_exact at 0x7f5f7de65ed8>, 'inf': <function dynamics_threshold_inf at 0x7f5f7de65de8>, 'spike_component': <function dynamics_threshold_spike_component at 0x7f5f7de65f50>}, 'AScurrent_dynamics_method': {'none': <function dynamics_AScurrent_none at 0x7f5f7de65398>, 'exp': <function dynamics_AScurrent_exp at 0x7f5f7de65410>}, 'AScurrent_reset_method': {'sum': <function reset_AScurrent_sum at 0x7f5f7de65d70>, 'none': <function reset_AScurrent_none at 0x7f5f7de65cf8>}, 'voltage_reset_method': {'v_before': <function reset_voltage_v_before at 0x7f5f7de598c0>, 'zero': <function reset_voltage_zero at 0x7f5f7de59848>}, 'threshold_reset_method': {'inf': <function reset_threshold_inf at 0x7f5f7de59e60>, 'three_components': <function reset_threshold_three_components at 0x7f5f7de59f50>}}¶ The METHOD_LIBRARY constant groups dynamics and reset methods by group name (e.g. ‘voltage_dynamics_method’).

allensdk.model.glif.glif_neuron_methods.
dynamics_AScurrent_exp
(neuron, AScurrents_t0, time_step, spike_time_steps)[source]¶ Exponential afterspike current dynamics method takes a current at t0 and returns the current at a time step later.

allensdk.model.glif.glif_neuron_methods.
dynamics_AScurrent_none
(neuron, AScurrents_t0, time_step, spike_time_steps)[source]¶ This method always returns zeros for the afterspike currents, regardless of input.

allensdk.model.glif.glif_neuron_methods.
dynamics_threshold_inf
(neuron, threshold_t0, voltage_t0, AScurrents_t0, inj)[source]¶ Set threshold to the neuron’s instantaneous threshold.
Parameters: neuron : class
threshold_t0 : not used here
voltage_t0 : not used here
AScurrents_t0 : not used here
inj : not used here
AScurrents_t0 : not used here
inj : not used here

allensdk.model.glif.glif_neuron_methods.
dynamics_threshold_spike_component
(neuron, threshold_t0, voltage_t0, AScurrents_t0, inj, a_spike, b_spike, a_voltage, b_voltage)[source]¶ Analytical solution for spike component of threshold. The threshold will adapt via a component initiated by a spike which decays as an exponential. The component is in reference to threshold infinity and are recorded in the neuron’s threshold components. The voltage component of the threshold is set to zero in the threshold components because it is zero here The third component refers to th_inf which is added separately as opposed to being included in the voltage component of the threshold as is done in equation 2.1 of Mihalas and Nieber 2009. Threshold infinity is removed for simple optimization.
Parameters: neuron : class
threshold_t0 : float
threshold input to function
voltage_t0 : float
voltage input to function
AScurrents_t0 : vector
values of after spike currents
inj : float
current injected into the neuron

allensdk.model.glif.glif_neuron_methods.
dynamics_threshold_three_components_exact
(neuron, threshold_t0, voltage_t0, AScurrents_t0, inj, a_spike, b_spike, a_voltage, b_voltage)[source]¶ Analytical solution for threshold dynamics. The threshold will adapt via two mechanisms: 1. a voltage dependent adaptation. 2. a component initiated by a spike which decays as an exponential. These two component are in reference to threshold infinity and are recorded in the neuron’s threshold components. The third component refers to th_inf which is added separately as opposed to being included in the voltage component of the threshold as is done in equation 2.1 of Mihalas and Nieber 2009. Threshold infinity is removed for simple optimization.
Parameters: neuron : class
threshold_t0 : float
threshold input to function
voltage_t0 : float
voltage input to function
AScurrents_t0 : vector
values of after spike currents
inj : float
current injected into the neuron

allensdk.model.glif.glif_neuron_methods.
dynamics_voltage_linear_exact
(neuron, voltage_t0, AScurrents_t0, inj)[source]¶ (TODO) Linear voltage dynamics.

allensdk.model.glif.glif_neuron_methods.
dynamics_voltage_linear_forward_euler
(neuron, voltage_t0, AScurrents_t0, inj)[source]¶ (TODO) Linear voltage dynamics.

allensdk.model.glif.glif_neuron_methods.
max_of_line_and_const
(x, b, c, d)[source]¶ Find the maximum of a value and a position on a line
Parameters: x: float
x position on line 1
c: float
slope of line 1
d: float
yintercept of line 1
b: float
yintercept of line 2
Returns: float
the max of a line value and a constant

allensdk.model.glif.glif_neuron_methods.
min_of_line_and_zero
(x, c, d)[source]¶ Find the minimum of a value and a position on a line
Parameters: x: float
x position on line 1
c: float
slope of line 1
d: float
yintercept of line 1
b: float
yintercept of line 2
Returns: float
the max of a line value and a constant

allensdk.model.glif.glif_neuron_methods.
reset_AScurrent_none
(neuron, AScurrents_t0)[source]¶ Reset afterspike currents to zero.

allensdk.model.glif.glif_neuron_methods.
reset_AScurrent_sum
(neuron, AScurrents_t0, r)[source]¶ Reset afterspike currents by adding summed exponentials. Left over currents from last spikes as well as newly initiated currents from current spike. Currents amplitudes in neuron.asc_amp_array need to be the amplitudes advanced though the spike cutting. I.e. In the preprocessor if the after spike currents are calculated via the GLM from spike initiation the amplitude at the time after the spike cutting needs to be calculated and neuron.asc_amp_array needs to be set to this value.
Parameters: r : np.ndarray
a coefficient vector applied to the afterspike currents

allensdk.model.glif.glif_neuron_methods.
reset_threshold_inf
(neuron, threshold_t0, voltage_v1)[source]¶ Reset the threshold to instantaneous threshold.

allensdk.model.glif.glif_neuron_methods.
reset_threshold_three_components
(neuron, threshold_t0, voltage_v1, a_spike, b_spike)[source]¶ This method calculates the two components of the threshold: a spike (fast) component and a voltage (slow) component. The threshold_components vectors are then updated so that the traces match the voltage, current, and total threshold traces. The spike component of the threshold decays via an exponential fit specified by the amplitude a_spike and the time constant b_spike fit via the multiblip data. The voltage component does not change during the duration of the spike. The spike component are threshold component are summed along with threshold infinity to return the total threshold. Note that in the current implementation a_spike is added to the last value of the threshold_components which means that a_spike is the amplitude after spike cutting (if there is any).
 Inputs:
 neuron: class
 contains attributes of the neuron
 threshold_t0, voltage_t0: float
 are not used but are here for consistency with other methods
 a_spike: float
 amplitude of the exponential decay of spike component of threshold after spike cutting has been implemented.
 b_spike: float
 amplitude of the exponential decay of spike component of threshold
 Outputs:
 Returns: float
 the total threshold which is the sum of the spike component of threshold, the voltage component of threshold and threshold infinity (with it’s corresponding coefficient)
 neuron.threshold_components: dictionary containing
 a spike: list
 vector of spiking component of threshold that corresponds to the voltage, current, and total threshold traces
 b_spike: list
 vector of voltage component of threshold that corresponds to the voltage, current,
 and total threshold traces.
Note that this function can be changed to use a_spike at the time of the spike and then have the the spike component plus the residual decay thought the spike. There are benefits and drawbacks to this. This potential change would be beneficial as it perhaps makes more biological sense for the threshold to go up at the time of spike if the traces are ever used. Also this would mean that a_spike would not have to be adjusted thought the spike cutting after the multiblip fit. However the current implementation makes sense in that it is similar to how afterspike currents are implemented.

allensdk.model.glif.glif_neuron_methods.
reset_voltage_v_before
(neuron, voltage_t0, a, b)[source]¶ Reset voltage to the previous value with a scale and offset applied.
Parameters: a : float
voltage scale constant
b : float
voltage offset constant

allensdk.model.glif.glif_neuron_methods.
reset_voltage_zero
(neuron, voltage_t0)[source]¶ Reset voltage to zero.

allensdk.model.glif.glif_neuron_methods.
spike_component_of_threshold_exact
(th0, b_spike, t)[source]¶ Spike component of threshold modeled as an exponential decay. Implemented here as exact analytical solution.
Parameters: th0 : float
threshold input to function
b_spike : float
decay constant of exponential
t : float or array
time step if used in an Euler setup time if used analytically

allensdk.model.glif.glif_neuron_methods.
spike_component_of_threshold_forward_euler
(th_t0, b_spike, dt)[source]¶ Spike component of threshold modeled as an exponential decay. Implemented here for forward Euler
Parameters: th_t0 : float
threshold input to function
b_spike : float
decay constant of exponential
dt : float
time step

allensdk.model.glif.glif_neuron_methods.
voltage_component_of_threshold_exact
(th0, v0, I, t, a_voltage, b_voltage, C, g, El)[source]¶ Note this function is the exact formulation; however, dt is used because t0 is the initial time and dt is the time the function is exactly evaluated at. Note: that here, this equation is in reference to th_inf. Therefore th0 is the total thresholdthr_inf (threshold_inf replaced with 0 in the equation to be verbose). This is done so that th_inf can be optimized without affecting this function.
Parameters: th0 : float
threshold input to function
v0 : float
voltage input to function
I : float
total current entering neuron (note if there are after spike currents these must be included in this value)
t : float or array
time step if used in an Euler setup time if used analytically
a_voltage : float
constant a
b_voltage : float
constant b
C : float
capacitance
g : float
conductance (1/resistance)
El : float
reversal potential

allensdk.model.glif.glif_neuron_methods.
voltage_component_of_threshold_forward_euler
(th_t0, v_t0, dt, a_voltage, b_voltage, El)[source]¶ Equation 2.1 of Mihalas and Nieber, 2009 implemented for use in forward Euler. Note here all variables are in reference to threshold infinity. Therefore thr_inf is zero here (replaced threshold_inf with 0 in the equation to be verbose). This is done so that th_inf can be optimized without affecting this function.
Parameters: th_t0 : float
threshold input to function
v_t0 : float
voltage input to function
dt : float
time step
a_voltage : float
constant a
b_voltage : float
constant b
El : float
reversal potential
allensdk.model.glif.simulate_neuron module¶

allensdk.model.glif.simulate_neuron.
load_sweep
(file_name, sweep_number)[source]¶ Load the stimulus for a sweep from file.

allensdk.model.glif.simulate_neuron.
parse_arguments
()[source]¶ Use argparse to get required arguments from the command line

allensdk.model.glif.simulate_neuron.
simulate_neuron
(neuron, sweep_numbers, input_file_name, output_file_name, spike_cut_value)[source]¶

allensdk.model.glif.simulate_neuron.
simulate_sweep
(neuron, stimulus, spike_cut_value)[source]¶ Simulate a neuron given a stimulus and initial conditions.
Module contents¶
A Generalized Linear Integrate and Fire (GLIF) neuron modeling package. Use this code to run the GLIF models available in the Allen Cell Types Atlas. See Generalized LIF Models for more details.