Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figs correction #157

Merged
merged 10 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions figures/kCSD_properties/L_curve_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def main_loop(src_width, total_ele, inpos, lpos, nm, noise=0, srcs=1):
for i, noise in enumerate(n_spec):
plt.close('all')
noise = np.round(noise, 5)
print('numer rekonstrukcji: ', i, 'noise level: ', noise)
print('number of reconstruction: ', i, 'noise level: ', noise)
#Electrodes
ele_pos, pots = electrode_config(total_ele, true_csd, t_csd_x, t_csd_y, inpos, lpos)
ele_y = ele_pos[:, 1]
Expand Down Expand Up @@ -179,5 +179,5 @@ def main_loop(src_width, total_ele, inpos, lpos, nm, noise=0, srcs=1):
os.chdir('..')
np.save('sim_results', sim_results)
sim_results = np.load('sim_results.npy')
make_plot_perf(sim_results)
make_plot_perf(sim_results, noise_lvl)

133 changes: 24 additions & 109 deletions figures/kCSD_properties/README.txt
Original file line number Diff line number Diff line change
@@ -1,178 +1,93 @@
Instructions for the figures from kCSD-revisited paper.
Instructions for the figures from kCSD-python, reliable current source density estimation with quality control.

~~~~~~~~~~~~~~~~~~~~~~~
Figure 1 - Schematic

name: figure1.png

~~~~~~~~~~~~~~~~~~~~~~~
Figure 2 - 1D spectral properties of kCSD method

figure_eigensources_M_1D.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 3 - Noise-free Electrode / Basis source placement

figure_Tbasis.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 4 - Noisy electrodes / Basis source placement

figure_Tbasis_noise.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 5 - L-curve method for regularization
Figure 2 - L-curve method for regularization

You will need to run L_curve_simulation.py first.

figure_LC.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 6 - L-curve versus Cross-validation

You will need to run L_curve_simulation.py first.

figure_LCandCVperformance.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 7 - Error propagation map
Figure 3 - Error propagation map

error_propagation.py
colorblind_friendly.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 8 - Reliability map
Figure 4 - Reliability map 2D

reliability_map_2d.py

error_maps_2D/point_error_large_100_all_ele.npy
error_maps_2D/point_error_small_100_all_ele.npy

~~~~~~~~~~~~~~~~~~~~~~~
Figure 9 - Reliability map; Use case in a 2D dipolar large source
Figure 5 - Reliability map; Use case in a 2D dipolar large source

kCSD_with_reliability_map_2D.py

error_maps_2D/point_error_large_100_all_ele.npy
error_maps_2D/point_error_small_100_all_ele.npy

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

You will need to run tutorial3.py first or download files from here
https://www.dropbox.com/sh/6kykj4d3dx3fp5s/AAACtN49VCbAHA9otOfNXbnOa?dl=0

tutorial_broken_electrodes_diff_err.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 11 - Simulated cortical recordings in Traubs's model

You will need to download files from:
https://repod.pon.edu.pl/dataset/thalamocortical-network/resource/6add09e1-bfe4-4082-b990-24b469756886

npx/traub_data_kcsd_column_figure.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 12 - LFP and CSD as a function of time - Traub's model

You will need to download files from:
https://repod.pon.edu.pl/dataset/thalamocortical-network/resource/6add09e1-bfe4-4082-b990-24b469756886

npx/figure_traub_timespace.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 13 - Six first eigensources for a single bank of a Neuropixels probe

You will need to download files from:
https://repod.pon.edu.pl/dataset/thalamocortical-network/resource/6add09e1-bfe4-4082-b990-24b469756886

npx/figure_traub_eigensources.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 14 - LFP and CSD space profiles - experimental data from a single bank of a Neuropixels probe

You will need to download files from:

npx/kCSD2D_reconstruction_from_npx.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 15 - LFP and CSD as a function of time - experimental data

You will need to download files from:

npx/kCSD2D_reconstruction_from_npx.py

~~~~~~~~~~~~~~~~~~~~~~~~
Figure 16 - L-Curve and CV landscape
Figure 7 - L-Curve and CV landscape

You will need to run L_curve_simulation.py first.

figure_LCandCV.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 17 - Schematic - location of Neuropixels bank 0

name: figure17.png

=====================
Supplementary Figures
=====================

~~~~~~~~~~~~~~~~~~~~~~~~~~
Figure 2-Figure supplement 1 - spectral properties of kCSD method for simple 2D case

figure_eigensources_M_2D.py

~~~~~~~~~~~~~~~~~~~~~~~~~~
Figure 7-Figure supplement 1 - Error propagation maps for 1D

pots_propagation.py

~~~~~~~~~~~~~~~~~~~~~~~~~~
Figure 13-Figure supplement 1 - Eigensurces 7-12 ('start=6', 'stop=12'),
Figure 13-Figure supplement 2 - Eigensurces 13-18 ('start=12', 'stop=18'),
Figure 13-Figure supplement 3 - Eigensurces 19-24 ('start=18', 'stop=24'),
Figure 13-Figure supplement 4 - Eigensurces 25-30 ('start=24', 'stop=30'),
Figure 13-Figure supplement 5 - Eigensurces 31-36 ('start=30', 'stop=36'),
Figure 13-Figure supplement 6 - Eigensurces 37-42 ('start=36', 'stop=42'),
Figure 13-Figure supplement 7 - Eigensurces 43-48 ('start=42', 'stop=48')

All supplementary figures to Figure 13 were created using different
'start' and 'stop'parameters at:
npx/figure_traub_eigensources.py

================
Appendix Figures
================

~~~~~~~~~~~~~~~~~~~~~~~
Appendix 1 Figure 1 - Basic features tutorial
Figure 8 - Basic features tutorial

You will need to run tutorial3.py first or download files from here
https://www.dropbox.com/sh/6kykj4d3dx3fp5s/AAACtN49VCbAHA9otOfNXbnOa?dl=0

tutorial_basic.py

~~~~~~~~~~~~~~~~~~~~~~~
Appendix 1 Figure 2 - Noisy electrodes tutorial

Figure 9 - Noisy electrodes tutorial

tutorial_noisy_electrodes.py

~~~~~~~~~~~~~~~~~~~~~~~~
Appendix 1 Figure 3 - Broken electrodes tutorial
~~~~~~~~~~~~~~~~~~~~~~~
Figure 10 - Broken electrodes tutorial

Download first from
https://www.dropbox.com/sh/6kykj4d3dx3fp5s/AAACtN49VCbAHA9otOfNXbnOa?dl=0
(generated from tweaking tutorial3.py)

tutorial_broken_electrodes.py

~~~~~~~~~~~~~~~~~~~~~~~~~~
Appendix 1 Figure 4 - 3D source reconstruction
~~~~~~~~~~~~~~~~~~~~~~~
Figure 11 - Error propagation maps for 1D

pots_propagation.py

~~~~~~~~~~~~~~~~~~~~~~~
Figure 12 - 3D source reconstruction

tutorial_basic_3d.py

~~~~~~~~~~~~~~~~~~~~~~~~~~
Appendix 1 Figure 5 - sKCSD example
~~~~~~~~~~~~~~~~~~~~~~~
Figure 13 - sKCSD example

You will need to install LFPy package first:
pip install lfpy

skcsd_and_l_curve_complex_morphology.py
4 changes: 2 additions & 2 deletions figures/kCSD_properties/error_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def _BipolarColormap(name, negative, positive):
h = 50. # distance between the electrode plane and the CSD plane
conductivity = 1.0 # S/m

csd_at = np.mgrid[0.:1.:100j,
0.:1.:100j]
csd_at = np.mgrid[0.:1.:101j,
0.:1.:101j]
csd_x, csd_y = csd_at

D = 2 - 1.618
Expand Down
6 changes: 3 additions & 3 deletions figures/kCSD_properties/figure_LC.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def make_plots(title, m_norm, m_resi, true_csd, curveseq, ele_y,
fig.savefig(save_as+'.png')

if __name__=='__main__':
# os.chdir("./LCurve/LC2")
os.chdir("./LCurve/LC2")
noises = 3
noise_lvl = np.linspace(0, 0.5, noises)
#df = np.load('data_fig4_and_fig13_lc_noise25.0.npz')
df = np.load('data_fig4_and_fig13_LC_noise25.0.npz')
Rs = np.linspace(0.025, 8*0.025, 8)
title = ['nazwa_pliku']
title = ['file_name']
save_as = 'noise'
make_plots(title, df['m_norm'], df['m_resi'], df['true_csd'],
df['curve_surf'], df['ele_y'], df['pots_n'],
Expand Down
2 changes: 1 addition & 1 deletion figures/kCSD_properties/figure_LCandCV.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def plot_surface(curve_surf, errsy, save_as):
df = np.load(os.path.join('LC2', 'data_fig4_and_fig13_LC_noise25.0.npz'))

Rs = np.linspace(0.025, 8*0.025, 8)
title = ['nazwa_pliku']
title = ['file_name']
save_as = 'noise'
plot_surface(df['curve_surf'], df['errsy'], save_as+'surf')
plt.close('all')
4 changes: 2 additions & 2 deletions figures/kCSD_properties/figure_LCandCVperformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def set_axis(ax, x, y, letter=None):
transform=ax.transAxes)
return ax

def make_plot_perf(sim_results):
def make_plot_perf(sim_results, noise_lvl):
rms_lc = sim_results[0, 2]
lam_lc = sim_results[0, 0]
rms_cv = sim_results[1, 2]
Expand Down Expand Up @@ -81,4 +81,4 @@ def make_plot_perf(sim_results):
noises = 9
noise_lvl = np.linspace(0, 0.5, noises)
sim_results = np.load('sim_results.npy')
make_plot_perf(sim_results)
make_plot_perf(sim_results, noise_lvl)
16 changes: 10 additions & 6 deletions figures/kCSD_properties/kCSD_with_reliability_map_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def make_reconstruction(KK, csd_profile, csd_seed, total_ele,

def make_subplot(ax, val_type, xs, ys, values, cax, title=None, ele_pos=None,
xlabel=False, ylabel=False, letter='', t_max=None,
mask=False, level=False):
mask=False, mask_x=False, mask_y=False, level=False):
if val_type == 'csd':
cmap = cm.bwr
elif val_type == 'pot':
Expand All @@ -128,7 +128,10 @@ def make_subplot(ax, val_type, xs, ys, values, cax, title=None, ele_pos=None,
levels=levels, cmap=cmap, alpha=1,
extent=(0, 0.5, 0, 0.5))
if mask is not False:
CS = ax.contour(xs, ys, mask, cmap='Greys')
if mask_x is not False:
CS = ax.contour(mask_x, mask_y, mask, cmap='Greys')
else:
CS = ax.contour(xs, ys, mask, cmap='Greys')
ax.clabel(CS, # label every second level
inline=1,
fmt='%1.2f',
Expand Down Expand Up @@ -186,7 +189,7 @@ def generate_figure(k, true_csd, ele_pos, pots, mask=False):
# gs.update(top=.95, bottom=0.53)
ax = plt.subplot(gs[0, 0])
cax = plt.subplot(gs[1, 0])
make_subplot(ax, 'csd', csd_x, csd_y, true_csd, cax=cax, ele_pos=ele_pos,
make_subplot(ax, 'csd', k.estm_x, k.estm_y, true_csd, cax=cax, ele_pos=ele_pos,
title='True CSD', xlabel=True, ylabel=True, letter='A',
t_max=np.max(abs(true_csd)))
ax = plt.subplot(gs[0, 1])
Expand All @@ -199,10 +202,10 @@ def generate_figure(k, true_csd, ele_pos, pots, mask=False):
make_subplot(ax, 'csd', k.estm_x, k.estm_y, k.values('CSD')[:, :, 0],
cax=cax, ele_pos=ele_pos, title='kCSD with Reliability Map',
xlabel=True, letter='C', t_max=np.max(abs(true_csd)),
mask=mask)
mask=mask, mask_x=csd_x, mask_y=csd_y)
ax = plt.subplot(gs[0, 3])
cax = plt.subplot(gs[1, 3])
make_subplot(ax, 'diff', csd_x, csd_y,
make_subplot(ax, 'diff', k.estm_x, k.estm_y,
abs(true_csd-k.values('CSD')[:, :, 0]), cax=cax,
ele_pos=ele_pos, title='|True CSD - kCSD|', xlabel=True,
letter='D',
Expand Down Expand Up @@ -245,9 +248,10 @@ def matrix_symmetrization(point_error):
Rs=Rs,
lambdas=lambdas,
method=method)
test_csd = CSD_PROFILE([k.estm_x, k.estm_y], CSD_SEED)
error_l = np.load('error_maps_2D/point_error_large_100_all_ele.npy')
error_s = np.load('error_maps_2D/point_error_small_100_all_ele.npy')
error_all = np.concatenate((error_l, error_s))
symm_array_all = matrix_symmetrization(error_all)
generate_figure(k, true_csd, ele_pos, pots,
generate_figure(k, test_csd, ele_pos, pots,
mask=np.mean(symm_array_all, axis=0))
4 changes: 2 additions & 2 deletions figures/kCSD_properties/pots_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def generate_figure(true_csd_xlims, total_ele, ele_lims, R_init=0.23):
for i in range(len(ele_pos)):
ax = fig.add_subplot(gs[plt_cord[i][0],
plt_cord[i][1]:plt_cord[i][1]+2])
ax.plot(np.linspace(0, 1, 100), est_csd[i], lw=2, c='red',
ax.plot(np.linspace(0, 1, 101), est_csd[i], lw=2, c='red',
label='kCSD')
ax.scatter(ele_pos, np.zeros(len(ele_pos)), c='k', label='Electrodes')
ax2 = ax.twinx()
ax2.plot(np.linspace(0, 1, 100), OBJ_M[i].values('POT'), c='green',
ax2.plot(np.linspace(0, 1, 101), OBJ_M[i].values('POT'), c='green',
label='Potentials')
ax2.set_ylim([-1.5, 1.5])
ax.set_ylim([-150, 150])
Expand Down
2 changes: 1 addition & 1 deletion figures/kCSD_properties/reliability_map_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def make_single_subplot(ax, val_type, xs, ys, values, cax, title=None,
plt.colorbar(im, cax=cax, orientation='horizontal', format='%.2f',
ticks=ticks)
set_axis(ax, letter=letter)
plt.tight_layout()
#plt.tight_layout()
return ax, cax


Expand Down
Loading