99import os
1010from 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
1416def 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)
0 commit comments