-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_me.py
More file actions
132 lines (107 loc) · 4.37 KB
/
Copy pathrun_me.py
File metadata and controls
132 lines (107 loc) · 4.37 KB
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
#!/usr/bin/env python2
# (c) 2016 - author information redacted by request 2026-08-07
# INRIA Rhone-Alpes
# STDP model : script that solves equations and produces plots
import numpy as np
import matplotlib
matplotlib.use('Agg') # to be able to generate plots without X server
import matplotlib.pylab as plt
from copy import deepcopy
import solve_py
from functions import nesteddict_to_lists_r, find_for_cnd, find_STDP, interpolate_and_gsmooth
from ST_vars_and_ic import ST_vars_and_ic, CaMKII_ic, si
from paramets import paramets as pars
import os
y0 = np.hstack([CaMKII_ic, ST_vars_and_ic.values()])
lv, lk = nesteddict_to_lists_r(pars)
t = np.arange(pars['integration']['t_start'], pars['integration']['t_end'], pars['integration']['t_step'])
fig_out_dir='./pngs/'
if not os.path.isdir(fig_out_dir):
os.mkdir(fig_out_dir)
######################
##### time series ####
######################
def compute_and_plot_ca_dt(dt):
lv1 = deepcopy(lv)
lv1[lk.index('stimulation, dt_stim')] = dt
y, ISTATE = solve_py.lsoda_calc(y0, lv1, t)
fig, axs = plt.subplots(1, 2, figsize=(15, 5), sharey=True)
for ax in axs:
ax.plot(t, y[si('Ca_cyt'), :], 'k')
ax.set_xlabel('Time, s')
ax.set_title('$\Delta t_{STDP}$ = %g ms' % (lv1[lk.index('stimulation, dt_stim')]*1000))
axs[0].set_ylabel('Calcium, $\mu M$')
axs[0].set_xlim([0, 120])
axs[1].set_xlim([0, 1])
fig.savefig(fig_out_dir+'Fig_ca_dt{}ms.png'.format(dt*1000), bbox_inches='tight', pad_inches=0.1)
plt.close(fig)
dts = [0.015, 0.03, 0.2]
dts = dts + list(-np.array(dts))
for dt in dts:
compute_and_plot_ca_dt(dt)
cnds = map(
dict,
zip(
zip(['stimulation, num_stim']*4, [10, 50, 75, 100][::-1])*2,
zip(['stimulation, dt_stim']*4, [-0.015]*4) + zip(['stimulation, dt_stim']*4, [0.015]*4)
)
)
def funcs(y, lv):
return {
'ctrl1': pars['ECb']['kCB1R']*y.T[:, si('o_CB1R')] + pars['DA']['gamma1DA']*pars['DA']['DA'],
'CaMKIIpho': solve_py.extras.camkiipho(y.T[:, :13]),
# 'CaM': solve_py.extras.cam_conc_func(y.T[:, si('Ca_cyt')], lv)
}
extras = [None]*len(cnds)
for i, cnd in enumerate(cnds):
y, lv1 = find_for_cnd(lv, lk, y0, t, cnd)
extras[i] = funcs(y, lv1)
fig, axs0 = plt.subplots(1, 2, figsize=(12,5))
axs = dict(zip([-0.015, 0.015], axs0))
cc = map(plt.get_cmap('copper'), np.linspace(0, 1, 4))
for i, cnd in enumerate(cnds):
ax = axs[cnd['stimulation, dt_stim']]
ax.set_color_cycle(cc)
ax.plot(t, extras[i]['CaMKIIpho'], label="$N_{pairings}$=%i" % cnd['stimulation, num_stim'], alpha=0.5)
ax.set_title('$\Delta t_{STDP}$ = %g ms' % (cnd['stimulation, dt_stim']*1000))
ax.set_xlabel('Time, s')
axs0[0].set_ylabel('CaMKII act., $\mu M$')
plt.legend()
fig.savefig(fig_out_dir+'Fig_CaMKII.png', bbox_inches='tight', pad_inches=0.1)
plt.close(fig)
fig, axs0 = plt.subplots(1, 2, figsize=(12,5))
axs = dict(zip([-0.015, 0.015], axs0))
for i, cnd in enumerate(cnds):
ax = axs[cnd['stimulation, dt_stim']]
ax.plot(t, extras[i]['ctrl1'], label="$N_{pairings}$=%i" % cnd['stimulation, num_stim'], alpha=0.5)
ax.set_title('$\Delta t_{STDP}$ = %g ms' % (cnd['stimulation, dt_stim']*1000))
ax.set_xlabel('Time, s')
axs0[0].set_ylabel('CB1R activation ($y_{CB1R}$) (a.u.)')
plt.legend()
fig.savefig(fig_out_dir+'Fig_yCB1R.png', bbox_inches='tight', pad_inches=0.1)
plt.close(fig)
######################
##### STDP curve #####
######################
def stdp_n(n, lv, dts, dts_new):
t = np.arange(0.0, 150.0+n/pars['stimulation']['Freq'], pars['integration']['t_step'])
# raw STDP
dstdp = find_STDP(t, y0, si('fpre'), lv, lk.index('stimulation, dt_stim'), dts, parallel=True)
# smoothing
ftot = interpolate_and_gsmooth(dts, dstdp['ftot'], dts_new, 0.003)
# clip to 3
ftot = np.clip(ftot, 0, 3)
return ftot
fig, axs = plt.subplots(1, 2, figsize=(12, 5), sharey=True, sharex=True)
dts = np.linspace(-0.04, 0.04, 80)
dts_new = np.linspace(-0.04, 0.04, 300)
lv1 = deepcopy(lv)
for i, n in enumerate([10, 100]):
lv1[lk.index('stimulation, num_stim')] = n
ftot = stdp_n(n, lv1, dts, dts_new)
axs[i].plot(dts_new*1000, ftot*100)
axs[i].set_title("$N_{pairings}$=%i" % n)
axs[0].set_xlabel('$\Delta t_{STDP}$ (ms)')
axs[0].set_ylabel('$W_{total}$ (%)')
fig.savefig(fig_out_dir+'Fig_STDP.png', bbox_inches='tight', pad_inches=0.1)
plt.close(fig)