-
Notifications
You must be signed in to change notification settings - Fork 1
/
GLIF_2.py
60 lines (50 loc) · 2.12 KB
/
GLIF_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/env python
import brian2
setattr(brian2.units, 'none', 1.0) # add brian2.units.none so metaprogramming works
# Run Brian2 simulation with external input
def run_brian_sim(stim, dt, init_values, param_dict, method = 'exact'):
# Model specification
eqs = brian2.Equations("")
eqs += brian2.Equations("dV/dt = 1 / C * (Ie(t) - G * (V - El)) : volt (unless refractory)")
eqs += brian2.Equations("dTh_s/dt = -b_s * Th_s : volt (unless refractory)")
reset = ""
reset = "\n".join([reset, "V = a_r * V + b_r"])
reset = "\n".join([reset, "Th_s = Th_s + a_s"])
threshold = "V > Th_inf + Th_s"
refractory = param_dict['t_ref']
Ie = brian2.TimedArray(stim, dt=dt)
nrn = brian2.NeuronGroup(1, eqs, method=method, reset=reset, threshold=threshold, refractory=refractory, namespace=param_dict)
nrn.V = init_values['V'] * brian2.units.volt
nrn.Th_s = init_values['Th_s'] * brian2.units.volt
monvars = ['V','Th_s',]
mon = brian2.StateMonitor(nrn, monvars, record=True)
num_step = len(stim)
brian2.defaultclock.dt = dt
brian2.run(num_step * dt)
return (mon.t / brian2.units.second, mon.V[0] / brian2.units.volt, mon.Th_s[0] / brian2.units.volt, )
def add_parameter_units(param_dict):
param_dict_units = {
'El': param_dict['El'] * brian2.units.volt,
'C': param_dict['C'] * brian2.units.farad,
'G': param_dict['G'] * brian2.units.siemens,
'Th_inf': param_dict['Th_inf'] * brian2.units.volt,
't_ref': param_dict['t_ref'] * brian2.units.second,
'a_r': param_dict['a_r'] * brian2.units.none,
'b_r': param_dict['b_r'] * brian2.units.volt,
'a_s': param_dict['a_s'] * brian2.units.volt,
'b_s': param_dict['b_s'] * brian2.units.hertz,
}
return param_dict_units
def parameters_from_list(param_list):
param_dict = {
'El': param_list[0],
'C': param_list[1],
'G': param_list[2],
'Th_inf': param_list[3],
't_ref': param_list[4],
'a_r': param_list[5],
'b_r': param_list[6],
'a_s': param_list[7],
'b_s': param_list[8],
}
return param_dict