|
10 | 10 | # from matplotlib import gridspec |
11 | 11 |
|
12 | 12 |
|
13 | | -def make_plot(xx, yy, zz, title='True CSD', cmap=cm.bwr): |
14 | | - fig = plt.figure(figsize=(7, 7)) |
15 | | - ax = plt.subplot(111) |
| 13 | +def make_plot(ax, xx, yy, zz, title='True CSD', cmap=cm.bwr): |
| 14 | + # fig = plt.figure(figsize=(7, 7)) |
| 15 | + # ax = plt.subplot(111) |
16 | 16 | ax.set_aspect('equal') |
17 | 17 | t_max = np.max(np.abs(zz)) |
18 | 18 | levels = np.linspace(-1 * t_max, t_max, 32) |
19 | 19 | im = ax.contourf(xx, yy, zz, levels=levels, cmap=cmap) |
20 | 20 | ax.set_xlabel('X (mm)') |
21 | 21 | ax.set_ylabel('Y (mm)') |
22 | 22 | ax.set_title(title) |
23 | | - ticks = np.linspace(-1 * t_max, t_max, 3, endpoint=True) |
24 | | - plt.colorbar(im, orientation='horizontal', format='%.2f', ticks=ticks) |
| 23 | + # ticks = np.linspace(-1 * t_max, t_max, 3, endpoint=True) |
| 24 | + # plt.colorbar(im, orientation='horizontal', format='%.2f', ticks=ticks) |
25 | 25 | return ax |
26 | 26 |
|
27 | 27 |
|
| 28 | +def dan_make_plot(k): |
| 29 | + fig = plt.figure(figsize=(7, 7)) |
| 30 | + ax1 = plt.subplot(121) |
| 31 | + |
| 32 | + est_csd = k.values('CSD') |
| 33 | + est_csd = est_csd.reshape(7, 90) |
| 34 | + est_pots = k.values('POT') |
| 35 | + est_pots = est_pots.reshape(7, 90) |
| 36 | + |
| 37 | + make_plot(ax1, k.estm_x, k.estm_y, est_csd[:, :], |
| 38 | + title='Estimated CSD', cmap=cm.bwr) |
| 39 | + |
| 40 | + ax2 = plt.subplot(122) |
| 41 | + make_plot(ax2, k.estm_x, k.estm_y, est_pots[:, :], |
| 42 | + title='Estimated POT', cmap=cm.PRGn) |
| 43 | + fig.suptitle('lambda = %f, R = %f' % (k.lambd, k.R)) |
| 44 | + |
| 45 | + return fig |
| 46 | + |
| 47 | + |
| 48 | + |
28 | 49 | # Specific to Ewas experimental setup |
29 | 50 | def load_chann_map(): |
30 | 51 | book = load_workbook('NP_do_map.xlsx') |
@@ -59,16 +80,16 @@ def dan_fetch_electrodes(meta): |
59 | 80 | return(electrode, channel) |
60 | 81 |
|
61 | 82 |
|
62 | | -def fetch_channels(eles): |
63 | | - chans = [] |
64 | | - exist_ele = [] |
65 | | - for ii in eles: |
66 | | - try: |
67 | | - chans.append(ele_chan_dict[ii]) |
68 | | - exist_ele.append(ii) |
69 | | - except KeyError: |
70 | | - print('Not recording from ele', ii) |
71 | | - return chans, exist_ele |
| 83 | +# def fetch_channels(eles): |
| 84 | +# chans = [] |
| 85 | +# exist_ele = [] |
| 86 | +# for ii in eles: |
| 87 | +# try: |
| 88 | +# chans.append(ele_chan_dict[ii]) |
| 89 | +# exist_ele.append(ii) |
| 90 | +# except KeyError: |
| 91 | +# print('Not recording from ele', ii) |
| 92 | +# return chans, exist_ele |
72 | 93 |
|
73 | 94 | def eles_to_rows(eles): |
74 | 95 | rows = [] |
@@ -189,31 +210,55 @@ def eles_to_coords(eles): |
189 | 210 |
|
190 | 211 |
|
191 | 212 | pots = pots.reshape((len(channels), 1)) |
192 | | -R_init = 5. # 0.3 |
| 213 | +R = 5. # 0.3 |
| 214 | +lambd = 0. |
193 | 215 | h = 20. # 50 |
194 | 216 | sigma = 0.3 |
| 217 | + |
195 | 218 | k = KCSD2D(ele_pos, pots, h=h, sigma=sigma, |
196 | | - xmin=-35, xmax=35, |
197 | | - ymin=1100, ymax=2000, |
198 | | - # ymin=1000, ymax=10000, |
199 | | - gdx=10, gdy=10, |
200 | | - R_init=R_init, n_src_init=1000, |
201 | | - src_type='gauss') # rest of the parameters are set at default |
202 | | -k.cross_validate(Rs=np.logspace(-1., 1., 10), lambdas=None) |
| 219 | + xmin=-35, xmax=35, |
| 220 | + ymin=1100, ymax=2000, |
| 221 | + # ymin=1000, ymax=10000, |
| 222 | + gdx=10, gdy=10, lambd=lambd, |
| 223 | + R_init=R, n_src_init=10000, |
| 224 | + src_type='gauss') # rest of the parameters are set at default |
| 225 | + |
| 226 | +k.L_curve(Rs=np.logspace(-1., 2., 31), lambdas=np.logspace(-5., 1., 11)) |
| 227 | +plt.imshow(k.curve_surf) |
| 228 | + |
| 229 | +# k.cross_validate(Rs=np.logspace(0., 2., 21), lambdas=np.logspace(-5., 1., 11)) |
203 | 230 | # k.cross_validate(Rs=np.linspace(0.1, 1.001, 2), lambdas=None) |
204 | 231 | # 2 -> 20 |
205 | 232 |
|
| 233 | +dan_make_plot(k) |
| 234 | + |
| 235 | + |
| 236 | +# ============================================================================= |
| 237 | +# for R in np.logspace(0., 2., 21): |
| 238 | +# for lambd in np.logspace(-5., 1., 11): |
| 239 | +# k = KCSD2D(ele_pos, pots, h=h, sigma=sigma, |
| 240 | +# xmin=-35, xmax=35, |
| 241 | +# ymin=1100, ymax=2000, |
| 242 | +# # ymin=1000, ymax=10000, |
| 243 | +# gdx=10, gdy=10, lambd=lambd, |
| 244 | +# R_init=R, n_src_init=1000, |
| 245 | +# src_type='gauss') # rest of the parameters are set at default |
| 246 | +# |
| 247 | +# est_csd = k.values('CSD') |
| 248 | +# est_csd = est_csd.reshape(7, 90) |
| 249 | +# est_pots = k.values('POT') |
| 250 | +# est_pots = est_pots.reshape(7, 90) |
| 251 | +# |
| 252 | +# dan_make_plot(k) |
| 253 | +# |
| 254 | +# ============================================================================= |
206 | 255 |
|
207 | | -est_csd = k.values('CSD') |
208 | | -est_csd = est_csd.reshape(7, 90) |
209 | | -est_pots = k.values('POT') |
210 | | -est_pots = est_pots.reshape(7, 90) |
211 | 256 |
|
212 | | -make_plot(k.estm_x, k.estm_y, est_csd[:, :], |
213 | | - title='Estimated CSD without CV', cmap=cm.bwr) |
| 257 | +# make_plot(k.estm_x, k.estm_y, est_csd[:, :], |
| 258 | +# title='Estimated CSD without CV', cmap=cm.bwr) |
214 | 259 |
|
215 | | -make_plot(k.estm_x, k.estm_y, est_pots[:, :], |
216 | | - title='Estimated POT without CV', cmap=cm.PRGn) |
| 260 | +# make_plot(k.estm_x, k.estm_y, est_pots[:, :], |
| 261 | +# title='Estimated POT without CV', cmap=cm.PRGn) |
217 | 262 |
|
218 | 263 |
|
219 | 264 | # # ax = plt.subplot(121) |
|
0 commit comments