forked from ThijsHoedemakers/CerebellarLoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Functions.py
149 lines (121 loc) · 4.38 KB
/
A_Functions.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from brian2 import *
import datetime, pickle, numpy, random
import scipy.io as sio
from scipy.io import loadmat
import h5py
def visualise(S):
Ns = len(S.source)
Nt = len(S.target)
figure(figsize=(10, 4), dpi= 80, facecolor='w', edgecolor='k')
subplot(121)
plot(zeros(Ns), arange(Ns), 'ok', ms=10)
plot(ones(Nt), arange(Nt), 'ok', ms=10)
for i, j in zip(S.i, S.j):
plot([0, 1], [i, j], '-k')
xticks([0, 1], ['Source', 'Target'])
ylabel('Neuron index')
xlim(-0.1, 1.1)
ylim(-1, max(Ns, Nt))
subplot(122)
plot(S.i, S.j, 'ok')
xlim(-1, Ns)
ylim(-1, Nt)
xlabel('Source neuron index')
ylabel('Target neuron index')
def rand_params(Parameter,Unit,N_Cells,Step):
Nn = [int(N_Cells/2), N_Cells-int(N_Cells/2)]
shuffle(Nn)
Base = int(1/Step)
Start = int(Base*Parameter)
Begin = Start - Nn[0]
End = Start + Nn[1]
Param_vector = [x / float(Base) for x in range(Begin, End, 1)]*Unit
shuffle(Param_vector)
return Param_vector
def NoiseGenerator(number,noisetype,IC,durSilence,durationInput,durationTotal,name,rand,typeofRun,freq1,freq2,nameF):
N_noise = number
# create global variables, so they can be used in the other scripts as well
global t_Neuron
t_Neuron=0.025*ms
global t_Monitor
t_Monitor=1*ms
global randomize
randomize = rand
print(randomize)
global typeOfRun
typeOfRun = typeofRun
global frequencyInput1
global frequencyInput2
frequencyInput1= freq1
frequencyInput2 = freq2
global NameFile
NameFile = nameF
global input_params
input_params=IC
global globname
globname = name
namesp=list(name)
namesp.append('BeforeSim.pickle')
namesp="".join(namesp)
### Different types of inputs
# OhlenbeckUhler?
if noisetype == 'OU':
print('Noise input is of type OU')
tau_noise = 50 * ms
eqs = '''
dI/dt = (I0 - I)/tau_noise + sigma*xi*tau_noise**-0.5 : amp
I0 : amp
sigma : amp
weight : 1
'''
Noise = NeuronGroup(N_noise, eqs, threshold='True', method='euler', name='Noise', dt=t_Neuron)
Noise_statemon = StateMonitor(Noise, variables=['I'], record=True, dt=t_Neuron)
Noise.I0 = IC[0] * nA # rand_params(1.5,nA,N_noise,0.4)
Noise.I = IC[1] * nA # rand_params(1.5,nA,N_noise,0.3)
Noise.sigma = IC[2] * nA # rand_params(0.5,nA,N_noise,-0.3)
# Double sine
elif noisetype == 'DS':
print('Noise input is of type double sine')
# Noise double sine
eqs = '''
I = sine_amplitude*sin(sine_frequency*t): amp
sine_amplitude : amp
sine_frequency: Hz
'''
Input = NeuronGroup(N_noise, eqs, threshold='True', method='euler', name='Noise', dt=t_Neuron)
Input.sine_amplitude = np.array(IC[number:(number+number)])*nA
Input.sine_frequency = np.array(IC[number*2:])*2*pi*Hz
Input_statemon = StateMonitor(Input, variables=['I'], record=True, dt=t_Neuron)
elif noisetype == 'const' :
print('Noise is of constant input')
constValue = IC[0] *nA
dur = int(duration/(0.025))
Noise_statemon = Struct()
Noise_statemon.t = np.arange(0, dur)
Noise_statemon.I = np.full((number,dur), constValue)
duration = 0
else:
print('Input type is not correct; chose OU,DS or const')
run(durationInput*ms)
Is = np.zeros((number,int((durationTotal)/(t_Neuron*1000))))
Inp = Input_statemon.I
for ii in range(0,number):
Inp[ii] = Inp[ii]+np.ones(len(Inp[ii]))*IC[ii]*nA
I2 = np.append(np.zeros(int(durSilence/(t_Neuron*1000))),Inp[ii])
Is[ii] = np.append(I2,np.zeros(int((durationTotal-durationInput-durSilence)/(t_Neuron*1000))))
simT =int(durationTotal/1000)
step = int(simT/((t_Neuron/ms)/1000))
t = np.linspace(0,simT,step)
t = np.round(t,6)
Input_created = {'I':Is,'time':t}
#with open(namesp, 'wb') as nn:
# pickle.dump(Input_created, nn, pickle.HIGHEST_PROTOCOL)
# print('Data is saved')
global Noise_t
Noise_t= Input_created['time']
global Noise_I
Noise_I = Input_created['I']
Noise_I = numpy.ascontiguousarray(Noise_I, dtype=np.float64)
global N_Noise
N_Noise = number
return Noise_t,Noise_I,N_Noise