Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SBI MEA Model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Doorn, Nina (UT-TNW)
SBI MEA Model
Commits
aa84b112
Commit
aa84b112
authored
3 months ago
by
Doorn, Nina (UT-TNW)
Browse files
Options
Downloads
Patches
Plain Diff
Fixed MEA feature names
parent
1c4e4ebb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Simulator.py
+150
-149
150 additions, 149 deletions
Simulator.py
with
150 additions
and
149 deletions
Simulator.py
+
150
−
149
View file @
aa84b112
...
...
@@ -10,68 +10,69 @@ from scipy.stats import norm
from
itertools
import
combinations
import
numpy
as
np
def
MEAnetSimulate
(
parameter_set
,
simtime
=
165
*
second
,
transient
=
5
*
second
):
# network parameters
def
MEAnetsimulate
(
parameter_set
,
simtime
=
165
*
second
,
transient
=
5
*
second
):
# Network parameters
Nl
=
10
N
=
Nl
*
Nl
# number of neurons
#
n
euron parameters
area
=
300
*
umetre
**
2
Cm
=
(
1
*
ufarad
*
cm
**
-
2
)
*
area
# membrane capacitance
El
=
-
39.2
*
mV
#
N
ernst potential of leaky ions
EK
=
-
80
*
mV
#
N
ernst potential of potassium
ENa
=
70
*
mV
#
N
ernst potential of sodium
gam_na
=
parameter_set
[
1
].
item
()
g_na
=
gam_na
*
(
50
*
msiemens
*
cm
**
-
2
)
*
area
# maximal conductance of sodium channels
gam_kd
=
parameter_set
[
2
].
item
()
g_kd
=
gam_kd
*
(
5
*
msiemens
*
cm
**
-
2
)
*
area
# maximal conductance of
potassium
gl
=
(
0.3
*
msiemens
*
cm
**
-
2
)
*
area
# maximal leak conductance
VT
=
-
30.4
*
mV
# alter
s firing threshold of neurons
sigma
=
parameter_set
[
0
].
item
()
*
mV
# standard deviation of the noisy voltage fluctuations
N
=
Nl
*
Nl
# number of neurons
#
N
euron parameters
area
=
300
*
umetre
**
2
Cm
=
(
1
*
ufarad
*
cm
**
-
2
)
*
area
# membrane capacitance
E
_
l
=
-
39.2
*
mV
#
n
ernst potential of leaky ions
E
_
K
=
-
80
*
mV
#
n
ernst potential of potassium
E
_
Na
=
70
*
mV
#
n
ernst potential of sodium
gam_na
=
parameter_set
[
1
].
item
()
# modifies sodium channel conductance
g_na
=
gam_na
*
(
50
*
msiemens
*
cm
**
-
2
)
*
area
# maximal conductance of sodium channels
gam_kd
=
parameter_set
[
2
].
item
()
# modifies potassium channel conductance
g_kd
=
gam_kd
*
(
5
*
msiemens
*
cm
**
-
2
)
*
area
# maximal conductance of
delayed rectifyer potassium channels
g
_
l
=
(
0.3
*
msiemens
*
cm
**
-
2
)
*
area
# maximal leak conductance
V
_
T
=
-
30.4
*
mV
# adapt
s firing threshold of neurons
sigma
=
parameter_set
[
0
].
item
()
*
mV
# standard deviation of the noisy voltage fluctuations
# Adaptation parameters
E_AHP
=
EK
#
N
ernst potential of afterhyperpolarization current
g_AHP
=
parameter_set
[
3
].
item
()
*
nS
# maximal conductance of sAHP channels
tau_Ca
=
6000
*
ms
# recovery time constant AHP channels
alpha_Ca
=
0.00035
# strength of the spike-frequency adaptation
--DS MODEL VALUE: 0.00005
E_AHP
=
E
_
K
#
n
ernst potential of afterhyperpolarization
potassium
current
g_AHP
=
parameter_set
[
3
].
item
()
*
nS
# maximal conductance of sAHP
potassium
channels
tau_Ca
=
6000
*
ms
# recovery time constant
s
AHP channels
alpha_Ca
=
0.00035
# strength of the spike-frequency adaptation
# synapse parameters
g_ampa
=
parameter_set
[
4
].
item
()
*
nS
# maximal conductance of AMPA channels
g_nmda
=
parameter_set
[
5
].
item
()
*
nS
E_ampa
=
0
*
mV
#
N
ernst potentials of synaptic channels
g_ampa
=
parameter_set
[
4
].
item
()
*
nS
# maximal conductance of AMPA channels
g_nmda
=
parameter_set
[
5
].
item
()
*
nS
# maximal conductance of NMDA channels
E_ampa
=
0
*
mV
#
n
ernst potentials of synaptic channels
E_nmda
=
0
*
mV
tau_ampa
=
2
*
ms
# recovery time constant of ampa conductance
taus_nmda
=
100
*
ms
# decay time constant of nmda conductance
taux_nmda
=
2
*
ms
# rise time constant of nmda conductance
tau_ampa
=
2
*
ms
# recovery time constant of ampa conductance
taus_nmda
=
100
*
ms
# decay time constant of nmda conductance
taux_nmda
=
2
*
ms
# rise time constant of nmda conductance
alpha_nmda
=
0.5
*
kHz
prob
=
parameter_set
[
6
].
item
()
# connection probability
sd
=
0.7
# SD of normal distribution of synaptic weights
M
axdelay
=
25
*
ms
# maximum conduction delay between neurons furthest away
prob
=
parameter_set
[
6
].
item
()
# connection probability
sd
=
0.7
# SD of normal distribution of synaptic weights
m
ax
_
delay
=
25
*
ms
# maximum conduction delay between neurons furthest away
tau_d
=
parameter_set
[
7
].
item
()
*
ms
# Recovery time constant of synaptic depression
U
=
parameter_set
[
8
].
item
()
# Magnitude
of STD
tau_d
=
parameter_set
[
7
].
item
()
*
ms
# Recovery time constant of synaptic depression
(STD)
U
=
parameter_set
[
8
].
item
()
# strength
of STD
tau_ar
=
700
*
ms
#
T
ime constant of asynchronous release
Uar
=
parameter_set
[
9
].
item
()
#
S
trength of asynchronous release
Umax
=
0.5
/
ms
#
S
aturation level of asynchronous release
x0
=
5
#
N
umber of neurotransmitters in a vesicle
tau_ar
=
700
*
ms
#
t
ime constant of asynchronous release
U
_
ar
=
parameter_set
[
9
].
item
()
#
s
trength of asynchronous release
U
_
max
=
0.5
/
ms
#
s
aturation level of asynchronous release
x0
=
5
#
n
umber of neurotransmitters in a vesicle
# BUILD NETWORK
# neuron model
eqs
=
Equations
(
'''
dV/dt = noise + (-gl*(V-El)-g_na*(m*m*m)*h*(V-ENa)-g_kd*(n*n*n*n)*(V-EK)+I-I_syn+I_AHP)/Cm : volt
dV/dt = noise + (-g
_
l*(V-E
_
l)-g_na*(m*m*m)*h*(V-E
_
Na)-g_kd*(n*n*n*n)*(V-E
_
K)+I-I_syn+I_AHP)/Cm : volt
dm/dt = alpha_m*(1-m)-beta_m*m : 1
dh/dt = alpha_h*(1-h)-beta_h*h : 1
dn/dt = (alpha_n*(1-n)-beta_n*n) : 1
dhp/dt = 0.128*exp((17.*mV-V+VT)/(18.*mV))/ms*(1.-hp)-4./(1+exp((30.*mV-V+VT)/(5.*mV)))/ms*h : 1
alpha_m = 0.32*(mV**-1)*4*mV/exprel((13*mV-V+VT)/(4*mV))/ms : Hz
beta_m = 0.28*(mV**-1)*5*mV/exprel((V-VT-40*mV)/(5*mV))/ms : Hz
alpha_h = 0.128*exp((17*mV-V+VT)/(18*mV))/ms : Hz
beta_h = 4./(1+exp((40*mV-V+VT)/(5*mV)))/ms : Hz
alpha_n = 0.032*(mV**-1)*5*mV/exprel((15*mV-V+VT)/(5*mV))/ms : Hz
beta_n = .5*exp((10*mV-V+VT)/(40*mV))/ms : Hz
noise = sigma*(2*gl/Cm)**.5*randn()/sqrt(dt) :volt/second (constant over dt)
dhp/dt = 0.128*exp((17.*mV-V+V
_
T)/(18.*mV))/ms*(1.-hp)-4./(1+exp((30.*mV-V+V
_
T)/(5.*mV)))/ms*h : 1
alpha_m = 0.32*(mV**-1)*4*mV/exprel((13*mV-V+V
_
T)/(4*mV))/ms : Hz
beta_m = 0.28*(mV**-1)*5*mV/exprel((V-V
_
T-40*mV)/(5*mV))/ms : Hz
alpha_h = 0.128*exp((17*mV-V+V
_
T)/(18*mV))/ms : Hz
beta_h = 4./(1+exp((40*mV-V+V
_
T)/(5*mV)))/ms : Hz
alpha_n = 0.032*(mV**-1)*5*mV/exprel((15*mV-V+V
_
T)/(5*mV))/ms : Hz
beta_n = .5*exp((10*mV-V+V
_
T)/(40*mV))/ms : Hz
noise = sigma*(2*g
_
l/Cm)**.5*randn()/sqrt(dt) :volt/second (constant over dt)
I : amp
I_syn = I_ampa + I_nmda: amp
I_ampa = g_ampa*(V-E_ampa)*(s_ampa) : amp
...
...
@@ -90,8 +91,8 @@ def MEAnetSimulate(parameter_set, simtime=165*second, transient=5*second):
method
=
'
exponential_euler
'
)
# Initialize neuron parameters
P
.
V
=
-
39
*
mV
# approximately resting membrane potential
P
.
I
=
'
(rand() -0.5)* 19 * pA
'
#
M
ake neurons heterogeneously excitable
P
.
V
=
-
39
*
mV
# approximately resting membrane potential
P
.
I
=
'
(rand() -0.5)* 19 * pA
'
#
m
ake neurons heterogeneously excitable
# Position neurons on a grid
grid_dist
=
45
*
umeter
...
...
@@ -112,7 +113,7 @@ def MEAnetSimulate(parameter_set, simtime=165*second, transient=5*second):
eqs_onpre
=
'''
x_nmda += 1
x_d *= (1-U)
uar += Uar*(Umax-uar)
uar += U
_
ar*(U
_
max-uar)
s_ampa += w * x_d
'''
# Make synapses
...
...
@@ -120,57 +121,56 @@ def MEAnetSimulate(parameter_set, simtime=165*second, transient=5*second):
Conn
.
connect
(
p
=
prob
)
Conn
.
w
[:]
=
'
clip(1.+sd*randn(), 0, 2)
'
Conn
.
x_d
[:]
=
1
Vmax
=
(
sqrt
(
Nl
**
2
+
Nl
**
2
)
*
grid_dist
)
/
M
axdelay
Conn
.
delay
=
'
(sqrt((x_pre - x_post)**2 + (y_pre - y_post)**2))/Vmax
'
V
_
max
=
(
sqrt
(
Nl
**
2
+
Nl
**
2
)
*
grid_dist
)
/
m
ax
_
delay
Conn
.
delay
=
'
(sqrt((x_pre - x_post)**2 + (y_pre - y_post)**2))/V
_
max
'
# SET UP MONITORS AND RUN
recordstring
=
[
'
V
'
]
dt2
=
defaultclock
.
dt
# Allows for chanching the timestep of recording
record_string
=
[
'
V
'
]
trace
=
StateMonitor
(
P
,
recordstring
,
record
=
True
,
dt
=
dt2
)
dt2
=
defaultclock
.
dt
# allows for changing the timestep of recording
trace
=
StateMonitor
(
P
,
record_string
,
record
=
True
,
dt
=
dt2
)
spikes
=
SpikeMonitor
(
P
)
try
:
run
(
simtime
,
report
=
'
text
'
,
profile
=
True
)
# run
run
(
simtime
,
report
=
'
text
'
,
profile
=
True
)
# run
except
:
simulation_num
=
int
(
float
(
sys
.
argv
[
1
]))
torch
.
save
([
nan
,
nan
,
nan
,
nan
,
nan
,
nan
,
nan
,
nan
],
'
Results
'
+
str
(
simulation_num
)
+
'
.pt
'
)
print
(
"
Simulation failed, results are set to nan and python will be terminated
"
)
exit
()
#
s
et up a filter to filter the voltage signal
fs
=
1
/
(
dt2
/
second
)
fc
=
100
#
C
ut-off frequency of the filter
w
=
fc
/
(
fs
/
2
)
#
N
ormalize the frequency
#
S
et up a filter to filter the voltage signal
fs
=
1
/
(
dt2
/
second
)
# nyquist frequency
fc
=
100
#
c
ut-off frequency of the
high-pass
filter
w
=
fc
/
(
fs
/
2
)
#
n
ormalize the frequency
b
,
a
=
signal
.
butter
(
5
,
w
,
'
high
'
)
voltagetraces
=
zeros
((
12
,
len
(
trace
.
t
)))
elec_grid_dist
=
(
grid_dist
*
(
Nl
-
1
))
/
4
# electrode grid size (there are 12 electrodes)
elec_range
=
3
*
grid_dist
# measurement range of each electrode
elec_grid_dist
=
(
grid_dist
*
(
Nl
-
1
))
/
4
# electrode grid size (there are 12 electrodes)
elec_range
=
3
*
grid_dist
# measurement range of each electrode
comp_dist
=
((
Nl
-
1
)
*
grid_dist
-
elec_grid_dist
*
3
)
/
2
elecranges
=
pickle
.
load
(
open
(
"
elecranges.dat
"
,
"
rb
"
))
elecranges
=
pickle
.
load
(
open
(
"
elecranges.dat
"
,
"
rb
"
))
k
=
0
M
axAPs
=
len
(
spikes
.
t
)
m
ax
_
APs
=
len
(
spikes
.
t
)
# maximum amount of detected APs
APs
=
np
.
array
([
0
,
0
])
for
i
in
[
1
,
2
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
13
,
14
]:
templist
=
elecranges
[
i
,
:]
x_electrode
=
i
%
4
*
elec_grid_dist
+
comp_dist
y_electrode
=
i
//
4
*
elec_grid_dist
+
comp_dist
templist
=
[
j
for
j
in
templist
if
j
!=
0
]
V
oltage
=
np
.
zeros
(
len
(
trace
.
V
[
0
]))
v
oltage
=
np
.
zeros
(
len
(
trace
.
V
[
0
]))
for
l
in
range
(
len
(
templist
)):
Voltage
+=
trace
[
templist
[
l
]].
V
/
mV
*
1
/
(
sqrt
((
x_electrode
-
P
.
x
[
templist
[
l
]])
**
2
+
(
y_electrode
-
P
.
y
[
templist
[
l
]])
**
2
)
/
(
grid_dist
*
0.2
))
Voltage
=
Voltage
-
mean
(
Voltage
)
Voltagefilt
=
signal
.
filtfilt
(
b
,
a
,
Voltage
)
# high pass filter
threshold
=
4
*
np
.
sqrt
(
np
.
mean
(
Voltagefilt
**
2
))
# threshold to detect APs
APstemp
,
_
=
signal
.
find_peaks
(
abs
(
Voltagefilt
),
height
=
threshold
)
for
j
in
range
(
len
(
APstemp
)):
APs
=
np
.
append
(
APs
,
[
k
,
APstemp
[
j
]])
voltage
+=
trace
[
templist
[
l
]].
V
/
mV
*
1
/
(
sqrt
((
x_electrode
-
P
.
x
[
templist
[
l
]])
**
2
+
(
y_electrode
-
P
.
y
[
templist
[
l
]])
**
2
)
/
(
grid_dist
*
0.2
))
voltage
=
voltage
-
mean
(
voltage
)
voltagefilt
=
signal
.
filtfilt
(
b
,
a
,
voltage
)
# high pass filter
threshold
=
4
*
np
.
sqrt
(
np
.
mean
(
voltagefilt
**
2
))
# threshold to detect APs
APs_temp
,
_
=
signal
.
find_peaks
(
abs
(
voltagefilt
),
height
=
threshold
)
for
j
in
range
(
len
(
APs_temp
)):
APs
=
np
.
append
(
APs
,
[
k
,
APs_temp
[
j
]])
templist
=
None
k
+=
1
...
...
@@ -179,32 +179,32 @@ def MEAnetSimulate(parameter_set, simtime=165*second, transient=5*second):
return
APs
,
simtime
,
transient
,
fs
def
C
ompute
F
eatures
(
APs
,
simtime
,
transient
,
fs
):
numelectrodes
=
12
# number of electrodes
tim
eB
in
=
25
*
ms
# timebin to compute network firing rate
def
c
ompute
_f
eatures
(
APs
,
simtime
,
transient
,
fs
):
numelectrodes
=
12
# number of electrodes
tim
b
in
=
25
*
ms
# timebin to compute network firing rate
#
i
nitialize
APsinbin
=
zeros
((
numelectrodes
,
int
(
floor
((
simtime
-
transient
)
/
tim
eB
in
))))
spikerate
=
zeros
((
numelectrodes
,
int
(
floor
((
simtime
-
transient
)
/
tim
eB
in
))))
#
I
nitialize
APs
_
inbin
=
zeros
((
numelectrodes
,
int
(
floor
((
simtime
-
transient
)
/
tim
b
in
))))
spikerate
=
zeros
((
numelectrodes
,
int
(
floor
((
simtime
-
transient
)
/
tim
b
in
))))
#
d
elete transient
#
D
elete transient
APs_wot
=
APs
[
APs
[:,
1
]
>
transient
*
fs
/
second
,
:]
APs_wot
[:,
1
]
=
APs_wot
[:,
1
]
-
transient
*
fs
/
second
#
c
alculate the network firing rate
#
C
alculate the network firing rate
for
l
in
range
(
numelectrodes
):
APt
=
APs_wot
[
APs_wot
[:,
0
]
==
l
,
:]
# go through one electrode first
APt
=
APs_wot
[
APs_wot
[:,
0
]
==
l
,
:]
# go through one electrode first
APt
=
APt
[:,
1
]
binsize
=
tim
eB
in
*
fs
/
second
for
k
in
range
(
int
(
floor
((
simtime
-
transient
)
/
tim
eB
in
))):
APsinbin
[
l
,
k
]
=
sum
((
APt
>
(
k
*
binsize
))
&
(
APt
<
((
k
+
1
)
*
binsize
)))
spikerate
[
l
,
k
]
=
APsinbin
[
l
,
k
]
*
second
/
tim
eB
in
binsize
=
tim
b
in
*
fs
/
second
for
k
in
range
(
int
(
floor
((
simtime
-
transient
)
/
tim
b
in
))):
APs
_
inbin
[
l
,
k
]
=
sum
((
APt
>
(
k
*
binsize
))
&
(
APt
<
((
k
+
1
)
*
binsize
)))
spikerate
[
l
,
k
]
=
APs
_
inbin
[
l
,
k
]
*
second
/
tim
b
in
APsinbintot
=
sum
(
APsinbin
,
axis
=
0
)
APs
_
inbintot
=
sum
(
APs
_
inbin
,
axis
=
0
)
spikeratetot
=
sum
(
spikerate
,
axis
=
0
)
#
make smoo
the
r
spikerate
width
=
11
#
Smoothen
the spikerate
by convolution with gaussian kernel
width
=
11
sigma
=
3.0
x
=
np
.
arange
(
0
,
width
,
1
,
float
)
x
=
x
-
width
//
2
...
...
@@ -212,93 +212,93 @@ def ComputeFeatures(APs, simtime, transient, fs):
kernel
/=
np
.
sum
(
kernel
)
spikeratesmooth
=
np
.
convolve
(
spikeratetot
,
kernel
,
mode
=
'
same
'
)
#
d
etect fragmented bursts on smoothed spikerate
MBth
=
(
1
/
16
)
*
max
(
spikeratetot
)
peaks
,
ph
=
find_peaks
(
spikeratesmooth
,
height
=
MBth
,
prominence
=
(
1
/
20
)
*
max
(
spikeratetot
))
#
D
etect fragmented bursts on smoothed spikerate
MB
_
th
=
(
1
/
16
)
*
max
(
spikeratetot
)
peaks
,
ph
=
find_peaks
(
spikeratesmooth
,
height
=
MB
_
th
,
prominence
=
(
1
/
20
)
*
max
(
spikeratetot
))
#
s
et parameters for burst detection
actelec
=
sum
(
mean
(
spikerate
,
axis
=
1
)
>
0.02
)
# calculate the number of active electrodes
#
S
et parameters for burst detection
act
_
elec
=
sum
(
mean
(
spikerate
,
axis
=
1
)
>
0.02
)
# calculate the number of active electrodes
S
tartth
=
0.25
*
max
(
spikeratetot
)
#
threshold to start a burst
T
th
=
int
((
50
*
ms
)
/
tim
eB
in
)
# how long it has to surpass threshold
E
th
=
0.5
*
actelec
# active
electrode n
umber threshold
S
topth
=
(
1
/
50
)
*
max
(
spikeratetot
)
# threshold to
stop
a burst
s
tart
_
th
=
0.25
*
max
(
spikeratetot
)
# spikerate
threshold to start a burst
t_
th
=
int
((
50
*
ms
)
/
tim
b
in
)
# how long it has to surpass threshold
for to start burst
e_
th
=
0.5
*
act
_
elec
# how many
electrode
s
n
eed to be active in the burst
s
top
_
th
=
(
1
/
50
)
*
max
(
spikeratetot
)
# threshold to
end
a burst
#
i
nitialize
#
I
nitialize
burst detection
i
=
0
NBcount
=
0
maxNB
=
1000
NBs
=
zeros
((
maxNB
,
4
))
#
d
etect NBs
while
(
i
+
T
th
)
<
len
(
spikeratetot
):
if
(
all
(
spikeratetot
[
i
:
i
+
T
th
]
>
S
tartth
))
\
&
(
sum
(
sum
(
APsinbin
[:,
i
:
i
+
T
th
],
axis
=
1
)
>
T
th
)
>
E
th
):
NBs
[
NBcount
,
2
]
=
NBs
[
NBcount
,
2
]
+
sum
(
APsinbintot
[
i
:
i
+
T
th
])
NBs
[
NBcount
,
0
]
=
i
i
=
i
+
T
th
while
any
(
spikeratetot
[
i
:
i
+
2
*
T
th
]
>
S
topth
):
NBs
[
NBcount
,
2
]
=
NBs
[
NBcount
,
2
]
+
APsinbintot
[
i
]
NB
_
count
=
0
max
_
NB
s
=
1000
# maximum amount of to be detected bursts
NBs
=
zeros
((
max
_
NB
s
,
4
))
#
D
etect NBs
while
(
i
+
t_
th
)
<
len
(
spikeratetot
):
if
(
all
(
spikeratetot
[
i
:
i
+
t_
th
]
>
s
tart
_
th
))
\
&
(
sum
(
sum
(
APs
_
inbin
[:,
i
:
i
+
t_
th
],
axis
=
1
)
>
t_
th
)
>
e_
th
):
NBs
[
NB
_
count
,
2
]
=
NBs
[
NB
_
count
,
2
]
+
sum
(
APs
_
inbintot
[
i
:
i
+
t_
th
])
NBs
[
NB
_
count
,
0
]
=
i
i
=
i
+
t_
th
while
any
(
spikeratetot
[
i
:
i
+
2
*
t_
th
]
>
s
top
_
th
):
NBs
[
NB
_
count
,
2
]
=
NBs
[
NB
_
count
,
2
]
+
APs
_
inbintot
[
i
]
i
=
i
+
1
NBs
[
NBcount
,
3
]
=
sum
((
peaks
>
NBs
[
NBcount
,
0
])
&
(
peaks
<
i
))
NBs
[
NBcount
,
1
]
=
i
NBcount
=
NBcount
+
1
NBs
[
NB
_
count
,
3
]
=
sum
((
peaks
>
NBs
[
NB
_
count
,
0
])
&
(
peaks
<
i
))
NBs
[
NB
_
count
,
1
]
=
i
NB
_
count
=
NB
_
count
+
1
else
:
i
=
i
+
1
NBs
=
NBs
[
0
:
NBcount
,
:]
NBs
=
NBs
[
0
:
NB
_
count
,
:]
MNBR
=
NBcount
*
60
*
second
/
(
simtime
-
transient
)
NBdurations
=
(
array
(
NBs
[:,
1
])
-
array
(
NBs
[:,
0
]))
*
tim
eB
in
/
second
MNBR
=
NB
_
count
*
60
*
second
/
(
simtime
-
transient
)
NBdurations
=
(
array
(
NBs
[:,
1
])
-
array
(
NBs
[:,
0
]))
*
tim
b
in
/
second
MNBD
=
mean
(
NBdurations
)
PSIB
=
sum
(
NBs
[:,
2
]
/
len
(
APs_wot
))
*
100
MFR
=
len
(
APs_wot
)
/
((
simtime
-
transient
)
/
second
)
/
numelectrodes
IBI
=
(
array
(
NBs
[
1
:,
0
])
-
array
(
NBs
[
0
:
-
1
,
1
]))
*
tim
eB
in
/
second
IBI
=
(
array
(
NBs
[
1
:,
0
])
-
array
(
NBs
[
0
:
-
1
,
1
]))
*
tim
b
in
/
second
CVIBI
=
np
.
std
(
IBI
)
/
np
.
mean
(
IBI
)
if
NBcount
==
0
:
if
NB
_
count
==
0
:
MNBD
=
0.0
MNMBs
=
0.0
NFBs
=
0
else
:
NFBs
=
sum
(
NBs
[:,
3
])
/
NBcount
NFBs
=
sum
(
NBs
[:,
3
])
/
NB
_
count
if
NBcount
<
2
:
if
NB
_
count
<
2
:
CVIBI
=
0.0
#
MAC
as defined by Maheswaranathan
#
Calculate MAC metric
as defined by Maheswaranathan
yf
=
fft
(
spikeratetot
)
xf
=
fftfreq
(
len
(
spikeratetot
),
tim
eB
in
/
second
)[:
len
(
spikeratetot
)
//
2
]
xf
=
fftfreq
(
len
(
spikeratetot
),
tim
b
in
/
second
)[:
len
(
spikeratetot
)
//
2
]
MAC
=
max
(
np
.
abs
(
yf
[
1
:
len
(
spikeratetot
)]))
/
np
.
abs
(
yf
[
0
])
# Calculate cross-correlation between binarized spike trains
#
b
inarize
#
B
inarize
the spike trains
all_combinations
=
list
(
combinations
(
list
(
arange
(
numelectrodes
)),
2
))
T
ranstimebin
=
0.2
*
second
# timebin to transform spiketrains to binary
bintimeseries
=
list
(
range
(
0
,
int
((
simtime
-
transient
)
/
ms
),
int
(
T
ranstimebin
/
ms
)))
binarysignal
=
zeros
((
numelectrodes
,
len
(
bintimeseries
)))
t
rans
_
timebin
=
0.2
*
second
# timebin to transform spiketrains to binary
bin
_
timeseries
=
list
(
range
(
0
,
int
((
simtime
-
transient
)
/
ms
),
int
(
t
rans
_
timebin
/
ms
)))
binary
_
signal
=
zeros
((
numelectrodes
,
len
(
bin
_
timeseries
)))
for
i
in
range
(
numelectrodes
):
signal
=
APsinbin
[
i
,
:]
grosssignal
=
[
sum
(
signal
[
x
:
x
+
int
((
T
ranstimebin
/
tim
eB
in
))])
for
x
in
range
(
0
,
len
(
signal
),
int
(
T
ranstimebin
/
tim
eB
in
))]
binarysignal
[
i
,
:]
=
[
1
if
x
>
0
else
0
for
x
in
grosssignal
]
signal
=
APs
_
inbin
[
i
,
:]
grosssignal
=
[
sum
(
signal
[
x
:
x
+
int
((
t
rans
_
timebin
/
tim
b
in
))])
for
x
in
range
(
0
,
len
(
signal
),
int
(
t
rans
_
timebin
/
tim
b
in
))]
binary
_
signal
[
i
,
:]
=
[
1
if
x
>
0
else
0
for
x
in
grosssignal
]
# Calculate coefficients between every pair of electrodes
coefficients
=
[]
N
=
len
(
binarysignal
[
0
,
:])
N
=
len
(
binary
_
signal
[
0
,
:])
for
i
,
j
in
all_combinations
:
signal1
=
binarysignal
[
i
,
:]
signal2
=
binarysignal
[
j
,
:]
signal1
=
binary
_
signal
[
i
,
:]
signal2
=
binary
_
signal
[
j
,
:]
if
(
i
!=
j
)
&
(
not
list
(
signal1
)
==
list
(
signal2
)):
coefficients
.
append
((
N
*
sum
(
signal1
*
signal2
)
-
sum
(
signal1
)
*
(
sum
(
signal2
)))
*
((
N
*
sum
(
signal1
**
2
)
-
sum
(
signal1
)
**
2
)
**
(
-
0.5
))
*
((
N
*
sum
(
signal2
**
2
)
-
sum
(
signal2
)
**
2
)
**
(
-
0.5
)))
meancorr
=
mean
(
coefficients
)
sdcorr
=
std
(
coefficients
)
mean
_
corr
=
mean
(
coefficients
)
sd
_
corr
=
std
(
coefficients
)
if
not
coefficients
:
meancorr
=
1
sdcorr
=
0
mean
_
corr
=
1
sd
_
corr
=
0
# Compute continuous ISI arrays
time_vector
=
np
.
arange
(
0
,
(
simtime
-
transient
)
/
second
,
1
/
fs
)
...
...
@@ -322,16 +322,17 @@ def ComputeFeatures(APs, simtime, transient, fs):
# Compute ISI measures
meanisi_array
=
np
.
nanmean
(
isi_arrays
,
axis
=
0
)
meanISI
=
np
.
nanmean
(
meanisi_array
)
sdmeanISI
=
np
.
nanstd
(
meanisi_array
)
sdtimeISI
=
np
.
nanmean
(
np
.
nanstd
(
isi_arrays
,
axis
=
0
))
mean
_
ISI
=
np
.
nanmean
(
meanisi_array
)
sdmean
_
ISI
=
np
.
nanstd
(
meanisi_array
)
sdtime
_
ISI
=
np
.
nanmean
(
np
.
nanstd
(
isi_arrays
,
axis
=
0
))
# Calculate the ISI-distance and ISI correlations
isi
_distances
=
np
.
zeros
(
len
(
all_combinations
))
ISI
_distances
=
np
.
zeros
(
len
(
all_combinations
))
isicoefficients
=
np
.
zeros
(
len
(
all_combinations
))
N
=
len
(
isi_arrays
[
0
,
:])
j
=
0
# iterate through the electrode combinations
# Iterate through the electrode combinations
for
electrode1_key
,
electrode2_key
in
all_combinations
:
# Get the ISI arrays for the selected electrodes
isit1_wn
=
isi_arrays
[
electrode1_key
,
:]
...
...
@@ -342,7 +343,7 @@ def ComputeFeatures(APs, simtime, transient, fs):
isit1
=
isit1
[
~
isnan
(
isit2_wn
)]
isi_diff
=
isit1
/
isit2
isi
_distances
[
j
]
=
np
.
mean
(
np
.
where
(
isi_diff
<=
1
,
abs
(
isi_diff
-
1
),
-
1
*
(
1
/
isi_diff
-
1
)))
ISI
_distances
[
j
]
=
np
.
mean
(
np
.
where
(
isi_diff
<=
1
,
abs
(
isi_diff
-
1
),
-
1
*
(
1
/
isi_diff
-
1
)))
if
(
i
!=
j
)
&
(
not
list
(
isit1
)
==
list
(
isit2
)):
isicoefficients
[
j
]
=
((
N
*
sum
(
isit1
*
isit2
)
-
sum
(
isit1
)
*
(
sum
(
isit2
)))
...
...
@@ -351,10 +352,10 @@ def ComputeFeatures(APs, simtime, transient, fs):
j
+=
1
mean
isi
corr
=
mean
(
isicoefficients
)
sd
isi
corr
=
std
(
isicoefficients
)
isi
_distance
=
np
.
mean
(
isi
_distances
)
mean
_ISI
corr
=
mean
(
isicoefficients
)
sd
_ISI
corr
=
std
(
isicoefficients
)
ISI
_distance
=
np
.
mean
(
ISI
_distances
)
return
[
MFR
,
MNBR
,
MNBD
,
PSIB
,
NFBs
,
CVIBI
,
meancorr
,
sdcorr
,
mean
isi
corr
,
sd
isi
corr
,
isi
_distance
,
meanISI
,
sdmeanISI
,
sdtimeISI
,
MAC
]
return
[
MFR
,
MNBR
,
MNBD
,
PSIB
,
NFBs
,
CVIBI
,
mean
_
corr
,
sd
_
corr
,
mean
_ISI
corr
,
sd
_ISI
corr
,
ISI
_distance
,
mean
_
ISI
,
sdmean
_
ISI
,
sdtime
_
ISI
,
MAC
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment