Skip to content

Commit cee9bb6

Browse files
m-kowalskaccluri
authored andcommitted
Figures (#105)
* Fixed missing caps in kCSD * Removed redundant functions * Renamed script * Updated readme for the figures * Added separate script for figure 4 * Set relative paths to figures folder
1 parent d1b2a92 commit cee9bb6

10 files changed

Lines changed: 366 additions & 354 deletions

figures/kCSD_properties/README.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ sources_electrodes.odg
99
Figure 2 - 1D spectral properties of kCSD method
1010

1111
figure_eigensources_M_1D.py
12-
figure_eigensources_R_1D.py (another version with inset plot)
1312

1413
~~~~~~~~~~~~~~~~~~~~~~~
15-
Figure 3 and 4 - Noise-free Electrode/Basis source placement
14+
Figure 3 and 4 - Noise-free Electrode / Basis source placement
1615

1716
figure_Tbasis.py
1817

1918
~~~~~~~~~~~~~~~~~~~~~~~
2019
Figure 3 and 4 - Noisy electrodes / Basis source placement
2120

22-
figure_Tbasis.py
21+
figure_Tbasis_noise.py
2322

2423
~~~~~~~~~~~~~~~~~~~~~~~
2524
Figure 5 - L-curve method for regularization
@@ -46,14 +45,19 @@ error_maps_2D/point_error_small_100_all_ele.npy
4645
~~~~~~~~~~~~~~~~~~~~~~~
4746
Figure 9 - Reliability map; Use case in a 2D dipolar large source
4847

49-
figure7_kCSD2d.py
48+
kCSD_with_reliability_map_2D.py
5049

5150
error_maps_2D/point_error_large_100_all_ele.npy
5251
error_maps_2D/point_error_small_100_all_ele.npy
5352

5453
~~~~~~~~~~~~~~~~~~~~~~~
5554
Figure 10 - Average Error (Diff) when broken electrode and loss in reconstruction quality
5655

56+
You will need to run tutorial3.py first or download files from here
57+
https://www.dropbox.com/sh/6kykj4d3dx3fp5s/AAACtN49VCbAHA9otOfNXbnOa?dl=0
58+
59+
tutorial_broken_electrodes_diff_err.py
60+
5761
~~~~~~~~~~~~~~~~~~~~~~~
5862
Figure 11 - Basic features tutorial
5963

@@ -75,7 +79,6 @@ https://www.dropbox.com/sh/6kykj4d3dx3fp5s/AAACtN49VCbAHA9otOfNXbnOa?dl=0
7579
(generated from tweaking tutorial3.py)
7680

7781
tutorial_broken_electrodes.py
78-
tutorial_broken_electrodes_sig_err.py (another variant)
7982

8083
~~~~~~~~~~~~~~~~~~~~~~~~
8184
Figure 14 - L-Curve and CV landscape

figures/kCSD_properties/figure_Tbasis.py

Lines changed: 4 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
"""
44

55
import os
6-
from os.path import expanduser
76
import numpy as np
87
from figure_properties import *
98
import matplotlib.pyplot as plt
109
import matplotlib.gridspec as gridspec
11-
import datetime
12-
import time
1310

1411
import targeted_basis as tb
1512

@@ -122,7 +119,7 @@ def make_subplot(ax, true_csd, est_csd, estm_x, title=None, ele_pos=None,
122119
return ax
123120

124121

125-
def generate_figure(R, MU, n_src, true_csd_xlims, total_ele, save_path,
122+
def generate_figure(R, MU, n_src, true_csd_xlims, total_ele,
126123
method='cross-validation', Rs=None, lambdas=None,
127124
noise=0):
128125
"""
@@ -284,232 +281,21 @@ def generate_figure(R, MU, n_src, true_csd_xlims, total_ele, save_path,
284281
handles, labels = ax.get_legend_handles_labels()
285282
fig.legend(handles, labels, loc='lower center', ncol=3, frameon=False)
286283

287-
fig.savefig(os.path.join(save_path, 'targeted_basis_' + method +
288-
'_noise_' + str(noise) + '.png'), dpi=300)
289-
plt.show()
290-
291-
292-
def generate_figure_CVLC(R, MU, n_src, true_csd_xlims, total_ele, save_path,
293-
Rs=None, lambdas=None, noise=0):
294-
"""
295-
Generates figure for targeted basis investigation including results from
296-
both cross-validation and L-curve.
297-
298-
Parameters
299-
----------
300-
R: float
301-
Thickness of the groundtruth source.
302-
Default: 0.2.
303-
MU: float
304-
Central position of Gaussian source
305-
Default: 0.25.
306-
nr_src: int
307-
Number of basis sources.
308-
true_csd_xlims: list
309-
Boundaries for ground truth space.
310-
total_ele: int
311-
Number of electrodes.
312-
save_path: string
313-
Directory.
314-
Rs: numpy 1D array
315-
Basis source parameter for crossvalidation.
316-
Default: None.
317-
lambdas: numpy 1D array
318-
Regularization parameter for crossvalidation.
319-
Default: None.
320-
noise: float
321-
Determines the level of noise in the data.
322-
Default: 0.
323-
324-
Returns
325-
-------
326-
None
327-
"""
328-
329-
m_cv = 'cross-validation'
330-
m_lc = 'L-curve'
331-
method = 'CV_LC'
332-
ele_lims = [0, 1.]
333-
csd_at, true_csd, ele_pos, pots, val = tb.simulate_data(tb.csd_profile,
334-
true_csd_xlims, R,
335-
MU, total_ele,
336-
ele_lims,
337-
noise=noise)
338-
339-
fig = plt.figure(figsize=(15, 12))
340-
widths = [1, 1, 1]
341-
heights = [1, 1, 1]
342-
gs = gridspec.GridSpec(3, 3, height_ratios=heights, width_ratios=widths,
343-
hspace=0.45, wspace=0.3)
344-
345-
ax = fig.add_subplot(gs[0, 0])
346-
xmin = 0
347-
xmax = 1
348-
ext_x = 0
349-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
350-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
351-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
352-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
353-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
354-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
355-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
356-
ele_pos=ele_pos, title='Basis limits = [0, 1]', xlabel=False,
357-
ylabel=True, letter='A', est_csd_LC=obj_LC.values('CSD'))
358-
359-
ax = fig.add_subplot(gs[0, 1])
360-
xmin = -0.5
361-
xmax = 1
362-
ext_x = -0.5
363-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
364-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
365-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
366-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
367-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
368-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
369-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
370-
ele_pos=ele_pos, title='Basis limits = [0, 0.5]',
371-
xlabel=False, ylabel=False, letter='B',
372-
est_csd_LC=obj_LC.values('CSD'))
373-
374-
ax = fig.add_subplot(gs[0, 2])
375-
xmin = 0
376-
xmax = 1.5
377-
ext_x = -0.5
378-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
379-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
380-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
381-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
382-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
383-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
384-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
385-
ele_pos=ele_pos, title='Basis limits = [0.5, 1]',
386-
xlabel=False, ylabel=False, letter='C',
387-
est_csd_LC=obj_LC.values('CSD'))
388-
389-
ele_lims = [0, 0.5]
390-
# total_ele = 6
391-
csd_at, true_csd, ele_pos, pots, val = tb.simulate_data(tb.csd_profile,
392-
true_csd_xlims, R,
393-
MU, total_ele,
394-
ele_lims,
395-
noise=noise)
396-
ax = fig.add_subplot(gs[1, 0])
397-
xmin = 0
398-
xmax = 1
399-
ext_x = 0
400-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
401-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
402-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
403-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
404-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
405-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
406-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
407-
ele_pos=ele_pos, title=None, xlabel=False, ylabel=True,
408-
letter='D', est_csd_LC=obj_LC.values('CSD'))
409-
410-
ax = fig.add_subplot(gs[1, 1])
411-
xmin = -0.5
412-
xmax = 1
413-
ext_x = -0.5
414-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
415-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
416-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
417-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
418-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
419-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
420-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
421-
ele_pos=ele_pos, title=None, xlabel=False, ylabel=False,
422-
letter='E', est_csd_LC=obj_LC.values('CSD'))
423-
424-
ax = fig.add_subplot(gs[1, 2])
425-
xmin = 0
426-
xmax = 1.5
427-
ext_x = -0.5
428-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
429-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
430-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
431-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
432-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
433-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
434-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
435-
ele_pos=ele_pos, title=None, xlabel=False, ylabel=False,
436-
letter='F', est_csd_LC=obj_LC.values('CSD'))
437-
438-
ele_lims = [0.5, 1.]
439-
csd_at, true_csd, ele_pos, pots, val = tb.simulate_data(tb.csd_profile,
440-
true_csd_xlims, R,
441-
MU, total_ele,
442-
ele_lims,
443-
noise=noise)
444-
ax = fig.add_subplot(gs[2, 0])
445-
xmin = 0
446-
xmax = 1
447-
ext_x = 0
448-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
449-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
450-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
451-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
452-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
453-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
454-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
455-
ele_pos=ele_pos, title=None, xlabel=True, ylabel=True,
456-
letter='G', est_csd_LC=obj_LC.values('CSD'))
457-
458-
ax = fig.add_subplot(gs[2, 1])
459-
xmin = -0.5
460-
xmax = 1
461-
ext_x = -0.5
462-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
463-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
464-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
465-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
466-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
467-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
468-
make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
469-
ele_pos=ele_pos, title=None, xlabel=True, ylabel=False,
470-
letter='H', est_csd_LC=obj_LC.values('CSD'))
471-
472-
ax = fig.add_subplot(gs[2, 2])
473-
xmin = 0
474-
xmax = 1.5
475-
ext_x = -0.5
476-
obj_CV = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
477-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
478-
xmax=xmax, method=m_cv, Rs=Rs, lambdas=lambdas)
479-
obj_LC = tb.modified_bases(val, pots, ele_pos, n_src, h=0.25,
480-
sigma=0.3, gdx=0.01, ext_x=ext_x, xmin=xmin,
481-
xmax=xmax, method=m_lc, Rs=Rs, lambdas=lambdas)
482-
ax = make_subplot(ax, true_csd, obj_CV.values('CSD'), obj_CV.estm_x,
483-
ele_pos=ele_pos, title=None, xlabel=True, ylabel=False,
484-
letter='I', est_csd_LC=obj_LC.values('CSD'))
485-
handles, labels = ax.get_legend_handles_labels()
486-
fig.legend(handles, labels, loc='lower center', ncol=4, frameon=False)
487-
488-
fig.savefig(os.path.join(save_path, 'targeted_basis_' + method +
284+
fig.savefig(os.path.join('targeted_basis_' + method +
489285
'_noise_' + str(noise) + '.png'), dpi=300)
490286
plt.show()
491287

492288

493289
if __name__ == '__main__':
494-
home = expanduser('~')
495-
DAY = datetime.datetime.now()
496-
DAY = DAY.strftime('%Y%m%d')
497-
TIMESTR = time.strftime("%H%M%S")
498-
SAVE_PATH = home + "/kCSD_results/" + DAY + '/' + TIMESTR
499-
tb.makemydir(SAVE_PATH)
500-
tb.save_source_code(SAVE_PATH, time.strftime("%Y%m%d-%H%M%S"))
501-
502290
N_SRC = 64
503291
TRUE_CSD_XLIMS = [0., 1.]
504292
TOTAL_ELE = 12
505293
R = 0.2
506294
MU = 0.25
507295
method = 'cross-validation' # L-curve
508296
# method = 'L-curve'
509-
# Rs = np.arange(0.1, 0.4, 0.05)
510297
Rs = np.array([0.2])
511298
lambdas = np.zeros(1)
512-
generate_figure(R, MU, N_SRC, TRUE_CSD_XLIMS, TOTAL_ELE, SAVE_PATH,
299+
generate_figure(R, MU, N_SRC, TRUE_CSD_XLIMS, TOTAL_ELE,
513300
method=method, Rs=Rs, lambdas=lambdas, noise=0)
514-
# generate_figure_CVLC(R, MU, N_SRC, TRUE_CSD_XLIMS, TOTAL_ELE, SAVE_PATH,
515-
# Rs=Rs, lambdas=None, noise=10)
301+

0 commit comments

Comments
 (0)