Skip to content

Commit 69d362b

Browse files
committed
Model and experimental timespace data in one figure
1 parent edb2dab commit 69d362b

2 files changed

Lines changed: 78 additions & 26 deletions

File tree

figures/npx/figure_traub_timespace.py

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import os
1010
from traub_data_kcsd_column_figure import (prepare_electrodes, prepare_pots,
1111
do_kcsd, set_axis)
12+
import kCSD2D_reconstruction_from_npx as npx
13+
from scipy.signal import filtfilt, butter
1214

1315

1416
def make_plot_spacetime(ax, val, cut=9, title='True CSD',
15-
cmap=plt.cm.bwr, letter='A'):
17+
cmap=plt.cm.bwr, letter='A', ylabel=True):
1618
yy = np.linspace(-3500, 500, val.shape[1])
1719
xx = np.linspace(-50, 250, val[cut, :, :].shape[1])
1820
max_val = np.max(np.abs(val[cut, :, :]))
@@ -26,23 +28,50 @@ def make_plot_spacetime(ax, val, cut=9, title='True CSD',
2628
color='k', ls='--')
2729
plt.text(110, value+165, name[i], fontsize=10, va='top', ha='center')
2830
ax.set_xlabel('Time (ms)')
29-
ax.set_ylabel('Y ($\mu$m)')
31+
if ylabel:
32+
ax.set_ylabel('Y ($\mu$m)')
3033
ax.set_title(title, fontsize=20, pad=30)
34+
ax.set_xlim(-50, 100)
3135
ticks = np.linspace(-max_val, max_val, 3, endpoint=True)
32-
plt.colorbar(im, orientation='vertical', format='%.3f', ticks=ticks)
36+
plt.colorbar(im, orientation='horizontal', format='%.3f', ticks=ticks)
3337
set_axis(ax, letter=letter)
34-
plt.tight_layout()
38+
#plt.tight_layout()
39+
40+
41+
def make_plot_1D_pics(ax, k, est_val, tp, Fs, cut=9, title='Experimental data',
42+
cmap=plt.cm.bwr, letter='A', ylabel=True):
43+
44+
set_axis(ax, letter=letter)
45+
npx.make_plot_spacetime(ax, k.estm_x, k.estm_y, est_val[cut,:,:], Fs,
46+
title=title, cmap=cmap, ylabel=ylabel)
47+
if letter == 'D':
48+
for lvl, name in zip([-500,-850,-2000], ['II/III', 'IV', 'V/VI']):
49+
plt.axhline(lvl, ls='--', color='grey')
50+
plt.text(340, lvl+20, name)
51+
elif letter == 'C':
52+
plt.axvline(tp/Fs*1000, ls='--', color ='grey', lw=2)
53+
54+
plt.xlim(250, 400)
55+
plt.xticks([250, 300, 350, 400], [-50, 0, 50, 100])
56+
57+
#plt.tight_layout()
58+
plt.savefig('figure_1D_pics', dpi=300)
3559

3660

37-
def make_figure_spacetime(val_pots, val_csd, cut=13, titl1='POT', titl2='CSD',
38-
fig_title='Pot and CSD in time'):
39-
fig = plt.figure(figsize=(12, 8))
40-
ax2 = plt.subplot(121)
41-
make_plot_spacetime(ax2, val_pots, cut=cut,
61+
def make_figure_spacetime(val_pots_m, val_csd_m, kcsd_obj, val_pots_e, val_csd_e, tp, Fs, cut1=13, cut2=15,
62+
titl1='POT', titl2='CSD', fig_title='Pot and CSD in time'):
63+
fig = plt.figure(figsize=(16, 8))
64+
ax2 = plt.subplot(141)
65+
make_plot_spacetime(ax2, val_pots_m, cut=cut1,
4266
title=titl1, cmap=plt.cm.PRGn, letter='A')
43-
ax1 = plt.subplot(122)
44-
make_plot_spacetime(ax1, val_csd, cut=cut,
45-
title=titl2, cmap=plt.cm.bwr, letter='B')
67+
ax1 = plt.subplot(142)
68+
make_plot_spacetime(ax1, val_csd_m, cut=cut1,
69+
title=titl2, cmap=plt.cm.bwr, letter='B', ylabel=False)
70+
ax3 = plt.subplot(143)
71+
make_plot_1D_pics(ax3, kcsd_obj, val_pots_e, tp, Fs, cut=cut2, title=titl1, cmap=plt.cm.PRGn, letter='C', ylabel=False)
72+
ax4 = plt.subplot(144)
73+
make_plot_1D_pics(ax4, kcsd_obj, val_csd_e, tp, Fs, cut=cut2, title=titl2, cmap=plt.cm.bwr, letter='D', ylabel=False)
74+
plt.tight_layout()
4675
fig.savefig(os.path.join(fig_title + '.png'), dpi=300)
4776

4877

@@ -62,14 +91,35 @@ def make_figure_spacetime(val_pots, val_csd, cut=13, titl1='POT', titl2='CSD',
6291
elec_pos_list, names_list = prepare_electrodes()
6392

6493
pot_np = prepare_pots(elec_pos_list[1], names_list[1], h, pop_names, time_pts)
65-
kcsd, est_pot, x, y, k = do_kcsd(pot_np, elec_pos_list[1][:, :2], -40, 40, -3500, 500)
94+
kcsd_m, est_pot_m, x_m, y_m, k_m = do_kcsd(pot_np, elec_pos_list[1][:, :2], -40, 40, -3500, 500)
95+
96+
lowpass = 0.5
97+
highpass = 300
98+
Fs = 30000
99+
resamp = 12
100+
tp= 760
101+
102+
forfilt=np.load('npx_data.npy')
103+
104+
[b,a] = butter(3, [lowpass/(Fs/2.0), highpass/(Fs/2.0)] ,btype = 'bandpass')
105+
filtData = filtfilt(b,a, forfilt)
106+
pots_resamp = filtData[:,::resamp]
107+
pots = pots_resamp[:, :]
108+
Fs=int(Fs/resamp)
109+
110+
pots_for_csd = np.delete(pots, 191, axis=0)
111+
ele_pos_def = npx.eles_to_coords(np.arange(384,0,-1))
112+
ele_pos_for_csd = np.delete(ele_pos_def, 191, axis=0)
113+
114+
k_e, est_csd_e, est_pots_e, ele_pos_e = npx.do_kcsd(ele_pos_for_csd, pots_for_csd, ele_limit = (0,320))
66115

67116
time_pts_ds = int(time_pts/4)
68-
cut = 9
117+
cut1 = 9
69118
start_pt = 625 # 50 ms before the stimulus
70119
end_pt = 1375 # 250 ms after the stimulus
71120
# for cut in range(kcsd.shape[0]):
72-
make_figure_spacetime(est_pot[:, :, start_pt:end_pt],
73-
kcsd[:, :, start_pt:end_pt], cut=cut,
121+
make_figure_spacetime(est_pot_m[:, :, start_pt:end_pt],
122+
kcsd_m[:, :, start_pt:end_pt], k_e, est_pots_e, est_csd_e, tp, Fs, cut1=cut1, cut2=15,
74123
titl1='Estimated LFP', titl2='Estimated CSD',
75-
fig_title=('Estimated POT and CSD in time 1stim '+ str(cut)))
124+
fig_title=('Estimated POT and CSD in time 1stim '))
125+
#plot_1D_pics(k, est_csd, est_pots, tp, 15)

figures/npx/kCSD2D_reconstruction_from_npx.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
from figure_properties import *
77
plt.close('all')
88
#%%
9-
def make_plot_spacetime(ax, xx, yy, zz, title='True CSD', cmap=cm.bwr_r, ymin=0, ymax=10000):
9+
def make_plot_spacetime(ax, xx, yy, zz, Fs, title='True CSD', cmap=cm.bwr_r, ymin=0, ymax=10000, ylabel=True):
1010
im = ax.imshow(zz,extent=[0, zz.shape[1]/Fs*1000,-3500, 500], aspect='auto',
1111
vmax = 1*zz.max(),vmin = -1*zz.max(), cmap=cmap)
1212
ax.set_xlabel('Time (ms)')
13-
ax.set_ylabel('Y ($\mu$m)')
13+
if ylabel:
14+
ax.set_ylabel('Y ($\mu$m)')
1415
if 'Pot' in title: ax.set_ylabel('Y ($\mu$m)')
1516
ax.set_title(title)
17+
ticks = np.linspace(-zz.max(), zz.max(), 3, endpoint=True)
1618
if 'CSD' in title:
17-
plt.colorbar(im, orientation='vertical', format='%.2f', ticks = [-0.01,0,0.01])
19+
plt.colorbar(im, orientation='horizontal', format='%.2f', ticks = ticks)
1820
else:
19-
plt.colorbar(im, orientation='vertical', format='%.1f', ticks = [-0.6,0,0.6])
21+
plt.colorbar(im, orientation='horizontal', format='%.1f', ticks = ticks)
2022
# plt.gca().invert_yaxis()
2123

2224
def make_plot(ax, xx, yy, zz, title='True CSD', cmap=cm.bwr):
@@ -57,13 +59,13 @@ def eles_to_coords(eles):
5759
ys = eles_to_ycoord(eles)
5860
return np.array((xs, ys)).T
5961

60-
def plot_1D_pics(k, est_csd, est_pots, tp, cut=9):
62+
def plot_1D_pics(k, est_csd, est_pots, tp, Fs, cut=9):
6163
plt.figure(figsize=(12, 8))
6264
# plt.suptitle('plane: '+str(k.estm_x[cut,0])+' $\mu$m '+' $\lambda$ : '+str(k.lambd)+
6365
# ' R: '+ str(k.R))
6466
ax1 = plt.subplot(122)
6567
set_axis(ax1, -0.05, 1.05, letter= 'D')
66-
make_plot_spacetime(ax1, k.estm_x, k.estm_y, est_csd[cut,:,:],
68+
make_plot_spacetime(ax1, k.estm_x, k.estm_y, est_csd[cut,:,:], Fs,
6769
title='Estimated CSD', cmap='bwr')
6870
for lvl, name in zip([-500,-850,-2000], ['II/III', 'IV', 'V/VI']):
6971
plt.axhline(lvl, ls='--', color='grey')
@@ -80,7 +82,7 @@ def plot_1D_pics(k, est_csd, est_pots, tp, cut=9):
8082
plt.tight_layout()
8183
plt.savefig('figure_1D_pics', dpi=300)
8284

83-
def plot_2D_pics(k, est_csd, est_pots, tp, cut, save=0):
85+
def plot_2D_pics(k, est_csd, est_pots, tp, Fs, cut, save=0):
8486
plt.figure(figsize=(12, 8))
8587
ax1 = plt.subplot(122)
8688
set_axis(ax1, -0.05, 1.05, letter= 'B')
@@ -127,5 +129,5 @@ def do_kcsd(ele_pos_for_csd, pots_for_csd, ele_limit):
127129

128130
k, est_csd, est_pots, ele_pos = do_kcsd(ele_pos_for_csd, pots_for_csd, ele_limit = (0,320))
129131

130-
plot_1D_pics(k, est_csd, est_pots, tp, 15)
131-
plot_2D_pics(k, est_csd, est_pots, tp=tp, cut=15)
132+
plot_1D_pics(k, est_csd, est_pots, tp, Fs, 15)
133+
plot_2D_pics(k, est_csd, est_pots, tp, Fs, cut=15)

0 commit comments

Comments
 (0)