From 420a961a22e59d9f1521029522a8dc6992a5cc03 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Mon, 2 Oct 2017 16:15:29 +0200 Subject: [PATCH] Copy all figures into a separate folder --- scripts/results/_plot_cov.py | 2 +- scripts/results/plot_fanning.py | 6 +- scripts/results/plot_filter.py | 2 +- scripts/results/plot_group.py | 2 +- scripts/results/plot_maxfilter.py | 2 +- scripts/results/plot_psd.py | 4 +- .../plot_sensor_cluster_stats_eeg_channel.py | 2 +- ...ot_sensor_spatio_temporal_cluster_stats.py | 2 +- scripts/results/plot_source_stats.py | 55 +++++++++++++++++++ scripts/results/plot_time_decoding.py | 2 +- 10 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 scripts/results/plot_source_stats.py diff --git a/scripts/results/_plot_cov.py b/scripts/results/_plot_cov.py index 8d9ece7e..edc2c47a 100644 --- a/scripts/results/_plot_cov.py +++ b/scripts/results/_plot_cov.py @@ -43,4 +43,4 @@ # axes[1].legend_.remove() fig.set_size_inches(8, 6, forward=True) plt.tight_layout() -fig.savefig('plot_white.pdf', bbox_to_inches='tight') +fig.savefig('figures/plot_white.pdf', bbox_to_inches='tight') diff --git a/scripts/results/plot_fanning.py b/scripts/results/plot_fanning.py index 1ae19d88..0e5af7f3 100644 --- a/scripts/results/plot_fanning.py +++ b/scripts/results/plot_fanning.py @@ -49,7 +49,7 @@ ts_args=dict(ylim=ylim, spatial_colors=True), topomap_args=dict(vmin=-300, vmax=300)) fig.set_size_inches(12, 6, forward=True) -fig.savefig('FanningA.pdf', bbox_to_inches='tight') +fig.savefig('figures/FanningA.pdf', bbox_to_inches='tight') ############################################################################### # Next, we highpass filter (but no lowpass filter as we have already done it) @@ -62,7 +62,7 @@ ts_args=dict(ylim=ylim, spatial_colors=True), topomap_args=dict(vmin=-300, vmax=300)) fig.set_size_inches(12, 6, forward=True) -fig.savefig('FanningB.pdf', bbox_to_inches='tight') +fig.savefig('figures/FanningB.pdf', bbox_to_inches='tight') ############################################################################### # Finally, we can also use the tSSS data which has a highpass @@ -82,4 +82,4 @@ ts_args=dict(ylim=ylim, spatial_colors=True), topomap_args=dict(vmin=-300, vmax=300)) fig.set_size_inches(12, 6, forward=True) -fig.savefig('FanningC.pdf', bbox_to_inches='tight') +fig.savefig('figures/FanningC.pdf', bbox_to_inches='tight') diff --git a/scripts/results/plot_filter.py b/scripts/results/plot_filter.py index 32078671..0a4b4abb 100644 --- a/scripts/results/plot_filter.py +++ b/scripts/results/plot_filter.py @@ -127,4 +127,4 @@ def box_off(ax): plt.tight_layout() plt.show() -plt.savefig('filters.pdf', bbox_to_inches='tight') +plt.savefig('figures/filters.pdf', bbox_to_inches='tight') diff --git a/scripts/results/plot_group.py b/scripts/results/plot_group.py index 324e4df0..23e0916f 100644 --- a/scripts/results/plot_group.py +++ b/scripts/results/plot_group.py @@ -61,7 +61,7 @@ plt.legend() plt.tight_layout() plt.show() -plt.savefig('grand_average_highpass-%sHz.pdf' % l_freq) +plt.savefig('figures/grand_average_highpass-%sHz.pdf' % l_freq) ############################################################################### # Source-space. See :ref:`sphx_glr_auto_scripts_14-group_average_source.py` diff --git a/scripts/results/plot_maxfilter.py b/scripts/results/plot_maxfilter.py index 3a8c00c1..37513de8 100644 --- a/scripts/results/plot_maxfilter.py +++ b/scripts/results/plot_maxfilter.py @@ -72,4 +72,4 @@ ylim=ylim, titles={'mag': 'After Maxfilter (TM)'}) axes[2].set_title('C') -fig.savefig('Maxfilter.pdf', bbox_to_inches='tight') +fig.savefig('figures/Maxfilter.pdf', bbox_to_inches='tight') diff --git a/scripts/results/plot_psd.py b/scripts/results/plot_psd.py index fee5c7c8..02a3aeb8 100644 --- a/scripts/results/plot_psd.py +++ b/scripts/results/plot_psd.py @@ -90,7 +90,7 @@ fig.tight_layout() plt.show() -fig.savefig('psdA.pdf', bbox_to_inches='tight') +fig.savefig('figures/psdA.pdf', bbox_to_inches='tight') ############################################################################### # Next, the linear scale to check power line frequency @@ -107,4 +107,4 @@ plt.axvline(freq, linestyle='--', alpha=0.25, linewidth=2) plt.tight_layout() -fig.savefig('psdB.pdf', bbox_to_inches='tight') +fig.savefig('figures/psdB.pdf', bbox_to_inches='tight') diff --git a/scripts/results/plot_sensor_cluster_stats_eeg_channel.py b/scripts/results/plot_sensor_cluster_stats_eeg_channel.py index 04edbb57..a4f6df96 100644 --- a/scripts/results/plot_sensor_cluster_stats_eeg_channel.py +++ b/scripts/results/plot_sensor_cluster_stats_eeg_channel.py @@ -105,4 +105,4 @@ plt.xlim([-200, 800]) plt.tight_layout() plt.show() -plt.savefig('sensorstat.pdf', bbox_to_inches='tight') +plt.savefig('figures/sensorstat.pdf', bbox_to_inches='tight') diff --git a/scripts/results/plot_sensor_spatio_temporal_cluster_stats.py b/scripts/results/plot_sensor_spatio_temporal_cluster_stats.py index c71940ec..7a28de4f 100644 --- a/scripts/results/plot_sensor_spatio_temporal_cluster_stats.py +++ b/scripts/results/plot_sensor_spatio_temporal_cluster_stats.py @@ -158,4 +158,4 @@ mne.viz.tight_layout(fig=fig) fig.subplots_adjust(bottom=.05) plt.show() - plt.savefig('spatiotemporal_stats_cluster-%02d.pdf' % i_clu) + plt.savefig('figures/spatiotemporal_stats_cluster-%02d.pdf' % i_clu) diff --git a/scripts/results/plot_source_stats.py b/scripts/results/plot_source_stats.py new file mode 100644 index 00000000..df051db1 --- /dev/null +++ b/scripts/results/plot_source_stats.py @@ -0,0 +1,55 @@ +""" +===================== +Source space clusters +===================== + +Clustering in source space. +""" +import os.path as op +import numpy as np +from scipy import stats +from functools import partial + +import mne +from mne import spatial_tris_connectivity, grade_to_tris +from mne.stats import (spatio_temporal_cluster_1samp_test, + summarize_clusters_stc, ttest_1samp_no_p) + +from library.config import meg_dir, subjects_dir + +exclude = [1, 5, 16] # Excluded subjects +contrasts = list() +for subject_id in range(1, 20): + if subject_id in exclude: + continue + subject = "sub%03d" % subject_id + print("processing subject: %s" % subject) + data_path = op.join(meg_dir, subject) + contrast = mne.read_source_estimate(op.join(data_path, 'contrast-morphed')) + contrast.resample(100) + contrast.crop(0., None) + contrasts.append(contrast.data.T) + +X = np.abs(np.array(contrasts)) + +connectivity = spatial_tris_connectivity(grade_to_tris(4)) +p_threshold = 0.001 +t_threshold = -stats.distributions.t.ppf(p_threshold / 2., 15) + +stat_fun = partial(ttest_1samp_no_p, sigma=0.5) +T_obs, clusters, cluster_p_values, H0 = clu = \ + spatio_temporal_cluster_1samp_test(X, connectivity=connectivity, n_jobs=1, + threshold=t_threshold, + stat_fun=stat_fun, verbose=True) + +good_cluster_inds = np.where(cluster_p_values < p_threshold)[0] +tstep = contrast.tstep +fsave_vertices = [np.arange(2562), np.arange(2562)] +stc_all_cluster_vis = summarize_clusters_stc(clu, tstep=tstep, + vertices=fsave_vertices, + subject='fsaverage') + +brain = stc_all_cluster_vis.plot(hemi='both', subjects_dir=subjects_dir, + time_label='Duration significant (ms)', + views='ven', + clim=dict(lims=[0, 15, 30], kind='value')) diff --git a/scripts/results/plot_time_decoding.py b/scripts/results/plot_time_decoding.py index bbeda0d1..3e4bba07 100644 --- a/scripts/results/plot_time_decoding.py +++ b/scripts/results/plot_time_decoding.py @@ -63,7 +63,7 @@ plt.legend() plt.tight_layout() plt.show() -plt.savefig('time_decoding.pdf', bbox_to_inches='tight') +plt.savefig('figures/time_decoding.pdf', bbox_to_inches='tight') ############################################################################### # It seems that `'famous'` vs `'unfamiliar'` gives much noisier time course of