Пример #1
0
	def bdmCue(self):
		'''

		'''

		with open(self.FolderTracker(['bdm','cue_loc'], filename = 'plot_dict.pickle') ,'rb') as handle:
			info = pickle.load(handle)
		times = info['times']	

		files = glob.glob(self.FolderTracker(['bdm','cue_loc'], filename = 'class_*_perm-False-broad.pickle'))
		bdm = []
		for file in files:
			print(file)
			with open(file ,'rb') as handle:
				bdm.append(pickle.load(handle))

		# plot conditions
		plt.figure(figsize = (30,20))
		norm = MidpointNormalize(midpoint=1/3.0)
		diag = {'partial':0,'whole':0}
		for idx, cnd in enumerate(['partial','whole']):
						
			X = np.stack([bdm[i][cnd]['standard'] for i in range(len(bdm))])
			diag[cnd] = np.vstack([np.diag(x) for x in X]) 
			cl_p_vals = clusterBasedPermutation(X,1/3.0)
			X = X.mean(axis = 0)
			
			
			# plot diagonal
			# ax = plt.subplot(2,2, idx + 3, title = 'Diagonal-{}'.format(cnd), ylabel = 'dec acc (%)', xlabel = 'time (ms)', ylim = (0.3,0.4))
			# plt.plot(times, np.diag(X))
			# plt.axhline(y = 1/3.0, color = 'black', ls = '--')
			# sns.despine(offset=50, trim = False)

			# plot GAT
			X[cl_p_vals == 1] = 1/3.0
			ax = plt.subplot(2,2, idx + 1, title = 'GAT-{}'.format(cnd), ylabel = 'train time (ms)', xlabel = 'test time (ms)')
			plt.imshow(X, norm = norm, aspect = 'auto', origin = 'lower',extent = [times[0],times[-1],times[0],times[-1]], 
						cmap = cm.bwr, interpolation = None, vmin = 1/3.0, vmax = 0.5)
			plt.colorbar()
			sns.despine(offset=50, trim = False)

		ax = plt.subplot(2,1, 2, title = 'Diagonal', ylabel = 'dec acc (%)', xlabel = 'time (ms)')
		for i, cnd in enumerate(['partial', 'whole']):
				err, x = bootstrap(diag[cnd])
				plt.plot(times, x, label = cnd, color = ['red','green'][i])
				plt.fill_between(times, x + err, x - err, alpha = 0.2, color = ['red','green'][i])
				self.clusterPlot(diag[cnd], 1/3.0, 0.05, times, ax.get_ylim()[0] + 0.01*(i+1), color = ['red','green'][i])
				
		self.clusterPlot(diag['partial'], diag['whole'], 0.05, times, 0.3,'black', '--')
		plt.axhline(y = 1/3.0, color = 'black', ls = '--')
		sns.despine(offset=50, trim = False)
		plt.legend(loc = 'best')

		plt.tight_layout()	
		plt.savefig(self.FolderTracker(['bdm'], filename = 'cue_loc-decoding.pdf'))
		plt.close()
Пример #2
0
    def plotcrossBDM(self):
        '''

		'''

        files = glob.glob(
            self.FolderTracker(['cross_task', 'bdm'],
                               filename='subject-*_bdm.pickle'))
        bdm = np.stack([pickle.load(open(file, 'rb')) for file in files])
        #with open(self.FolderTracker(['bdm','identity'], filename = 'plot_dict.pickle') ,'rb') as handle:
        #	info = pickle.load(handle)
        times = np.linspace(-0.2, 0.9, 128)
        norm = MidpointNormalize(midpoint=1 / 8.0)
        plt.figure(figsize=(20, 10))

        # plot diagonal
        ax = plt.subplot(1,
                         2,
                         1,
                         title='Diagonal',
                         ylabel='dec acc (%)',
                         xlabel='time (ms)')
        diag = np.diag(np.mean(bdm, 0))
        plt.plot(times, diag)
        plt.axhline(y=1 / 8.0, color='black', ls='--')
        sns.despine(offset=50, trim=False)

        # plot gat matrix
        ax = plt.subplot(1,
                         2,
                         2,
                         title='GAT',
                         ylabel='train time (ms)',
                         xlabel='test time (ms)')
        plt.imshow(bdm.mean(0),
                   norm=norm,
                   aspect='auto',
                   origin='lower',
                   extent=[times[0], times[-1], times[0], times[-1]],
                   cmap=cm.bwr,
                   interpolation=None,
                   vmin=0.09,
                   vmax=0.15)
        plt.colorbar()
        sns.despine(offset=50, trim=False)

        plt.tight_layout()
        plt.savefig(
            self.FolderTracker(['cross_task', 'bdm'],
                               filename='cross-task.pdf'))
        plt.close()
Пример #3
0
    def plotBDM(self, elec_oi='all', task='AB'):
        '''
		Plots GAT matrix and diagonal for digits (top) and letters (bottom)

		'''
        embed()
        with open(
                self.FolderTracker([task, 'bdm', 'T1'],
                                   filename='plot_dict.pickle'),
                'rb') as handle:
            info = pickle.load(handle)
        times = info['times']
        # plot conditions
        # plt.figure(figsize = (30,20))
        # norm = MidpointNormalize(midpoint=1/8.0)
        # for idx, header in enumerate(['digit','letter']):
        # 	bdm = []
        # 	files = glob.glob(self.FolderTracker(['bdm',header], filename = 'class_*_perm-False-broad.pickle'))
        # 	for file in files:
        # 		print file
        # 		with open(file ,'rb') as handle:
        # 			bdm.append(pickle.load(handle))

        # 	X = np.stack([bdm[i][header]['standard'] for i in range(len(bdm))])
        # 	print X.shape
        # 	X = X.mean(axis = 0)

        # 	# plot diagonal
        # 	ax = plt.subplot(2,2, idx + 3, title = 'Diagonal-{}'.format(header), ylabel = 'dec acc (%)', xlabel = 'time (ms)')
        # 	plt.plot(times, np.diag(X))
        # 	plt.axhline(y = 1/8.0, color = 'black', ls = '--')
        # 	sns.despine(offset=50, trim = False)

        # 	# plot GAT
        # 	X[X <1/8.0] = 1/8.0
        # 	ax = plt.subplot(2,2, idx + 1, title = 'GAT-{}'.format(header), ylabel = 'train time (ms)', xlabel = 'test time (ms)')
        # 	plt.imshow(X, norm = norm, aspect = 'auto', origin = 'lower',extent = [times[0],times[-1],times[0],times[-1]],
        # 				cmap = cm.bwr, interpolation = None, vmin = 1/8.0, vmax = 0.16)
        # 	plt.colorbar()
        # 	sns.despine(offset=50, trim = False)

        # plt.tight_layout()
        # plt.savefig(self.FolderTracker(['bdm'], filename = 'localizer.pdf'))
        # plt.close()

        plt.figure(figsize=(30, 20))
        norm = MidpointNormalize(midpoint=1 / 8.0)
        for idx, header in enumerate(['digit', 'letter']):
            bdm = []

            files = glob.glob(
                self.FolderTracker(['bdm', header],
                                   filename='class_*_perm-False-broad.pickle'))
            for file in files:
                with open(file, 'rb') as handle:
                    bdm.append(pickle.load(handle))

            ###### plot diagonal - downscaling #######
            # ax = plt.subplot(1,2, idx + 1, title = 'Diagonal-{}'.format(header), ylabel = 'dec acc (%)', xlabel = 'time (ms)')
            # if header == 'digit':
            # 	label_list = ['standard','110-nrlabels','100-nrlabels','90-nrlabels','80-nrlabels','70-nrlabels']
            # 	label_list = ['standard','100-nrlabels']
            # else:
            # 	label_list = ['standard','100-nrlabels','90-nrlabels','80-nrlabels','70-nrlabels']
            # 	label_list = ['standard','100-nrlabels']

            # for label in label_list:	% use this for plotting when downscaling; loop through labels
            # 	#for label in np.sort(bdm[0][header].keys())[::3]:
            # 		X = np.stack([bdm[i][header][label] for i in range(len(bdm))])

            # 		x = X.mean(axis = 0)
            # 		plt.plot(times, x, label = label)

            # 	plt.legend(loc = 'best')
            # 	plt.axhline(y = 1/8.0, color = 'black', ls = '--')
            # 	sns.despine(offset=50, trim = False)

            # plt.tight_layout()
            # plt.savefig(self.FolderTracker(['bdm'], filename = 'localizer-posterior-chans.pdf'))
            # plt.close()

            X = np.stack([bdm[i][header]['standard'] for i in range(len(bdm))])
            print(X.shape)
            X = X.mean(axis=0)

            # plot diagonal
            ax = plt.subplot(2,
                             2,
                             idx + 3,
                             title='Diagonal-{}'.format(header),
                             ylabel='dec acc (%)',
                             xlabel='time (ms)')
            plt.plot(times, np.diag(X))
            plt.axhline(y=1 / 8.0, color='black', ls='--')
            sns.despine(offset=50, trim=False)

            # plot GAT
            X[X < 1 / 8.0] = 1 / 8.0
            ax = plt.subplot(2,
                             2,
                             idx + 1,
                             title='GAT-{}'.format(header),
                             ylabel='train time (ms)',
                             xlabel='test time (ms)')
            plt.imshow(X,
                       norm=norm,
                       aspect='auto',
                       origin='lower',
                       extent=[times[0], times[-1], times[0], times[-1]],
                       cmap=cm.bwr,
                       interpolation=None,
                       vmin=1 / 8.0,
                       vmax=0.16)
            plt.colorbar()
            sns.despine(offset=50, trim=False)

        plt.tight_layout()
        plt.savefig(self.FolderTracker(['bdm'], filename='localizer.pdf'))
        plt.close()
Пример #4
0
    def plotBDMwithin(self, to_plot='T1'):
        '''	
		THIS FUNCTION PLOTS WITHIN TASK DECODING
		'''

        # set plotting parameters
        plt.figure(figsize=(30, 20))
        norm = MidpointNormalize(midpoint=1 / 8.0)
        with open(
                self.FolderTracker(['bdm', 'identity'],
                                   filename='plot_dict.pickle'),
                'rb') as handle:
            info = pickle.load(handle)
        times = info['times']

        for task in ['localizer', 'AB']:
            files = glob.glob(
                self.FolderTracker([task, 'bdm'], filename='*_*_dec.pickle'))
            bdm = [pickle.load(open(file, 'rb')) for file in files]
            # collapse data
            if task == 'localizer':
                for idx, cnd in enumerate(['digit', 'letter']):
                    X = np.stack(
                        [bdm[i][cnd]['standard'] for i in range(len(bdm))])
                    # plot diagonal
                    ax = plt.subplot(3,
                                     2, [2, 4][idx],
                                     title='Diagonal-{}'.format(cnd),
                                     ylabel='dec acc (%)',
                                     xlabel='time (ms)')
                    diag = np.diag(np.mean(X, 0))
                    plt.plot(times, diag)
                    plt.axhline(y=1 / 8.0, color='black', ls='--')
                    sns.despine(offset=50, trim=False)

                    # plot gat matrix
                    ax = plt.subplot(3,
                                     2, [1, 3][idx],
                                     title='GAT-{}'.format(cnd),
                                     ylabel='train time (ms)',
                                     xlabel='test time (ms)')
                    plt.imshow(
                        X.mean(0),
                        norm=norm,
                        aspect='auto',
                        origin='lower',
                        extent=[times[0], times[-1], times[0], times[-1]],
                        cmap=cm.bwr,
                        interpolation=None,
                        vmin=0.09,
                        vmax=0.15)
                    plt.colorbar()
                    sns.despine(offset=50, trim=False)

            elif task == 'AB':
                X = np.stack(
                    [bdm[i]['all']['standard'] for i in range(len(bdm))])
                # plot diagonal
                ax = plt.subplot(3,
                                 2,
                                 6,
                                 title='Diagonal-{}'.format(to_plot),
                                 ylabel='dec acc (%)',
                                 xlabel='time (ms)')
                diag = np.diag(np.mean(X, 0))
                plt.plot(times, diag)
                plt.axhline(y=1 / 8.0, color='black', ls='--')
                sns.despine(offset=50, trim=False)

                # plot gat matrix
                ax = plt.subplot(3,
                                 2,
                                 5,
                                 title='GAT-{}'.format(to_plot),
                                 ylabel='train time (ms)',
                                 xlabel='test time (ms)')
                plt.imshow(X.mean(0),
                           norm=norm,
                           aspect='auto',
                           origin='lower',
                           extent=[times[0], times[-1], times[0], times[-1]],
                           cmap=cm.bwr,
                           interpolation=None,
                           vmin=0.09,
                           vmax=0.15)
                plt.colorbar()
                sns.despine(offset=50, trim=False)

        plt.tight_layout()
        plt.savefig(
            self.FolderTracker(['bdm'],
                               filename='within_dec_{}.pdf'.format(to_plot)))
        plt.close()
Пример #5
0
    def plotBDM(self, header):
        '''
		
		'''

        # read in data
        with open(
                self.FolderTracker(['bdm', '{}_type'.format(header)],
                                   filename='plot_dict.pickle'),
                'rb') as handle:
            info = pickle.load(handle)
        times = info['times']

        files = glob.glob(
            self.FolderTracker(['bdm', '{}_type'.format(header)],
                               filename='class_*_perm-False.pickle'))
        bdm = []
        for file in files:
            with open(file, 'rb') as handle:
                bdm.append(pickle.load(handle))

        # plot diagonal decoding (all conditions in one plot)
        plt.figure(figsize=(15, 10))
        diff = []
        for i, cnd in enumerate(['DTsim', 'DTdisP', 'DTdisDP']):
            ax = plt.subplot(1, 1, 1, ylim=(0.3, 0.45))
            X = np.stack([bdm[j][cnd]['standard'] for j in range(len(bdm))])
            X_diag = np.stack([np.diag(x) for x in X])
            diff.append(X_diag)
            self.clusterPlot(X_diag,
                             1 / 3.0,
                             p_val=0.05,
                             times=times,
                             y=plt.ylim()[0] + i * 0.002,
                             color=['red', 'purple', 'darkblue'][i])
            err_diag, X_diag = bootstrap(X_diag)
            plt.plot(times,
                     X_diag,
                     label=cnd,
                     color=['red', 'purple', 'darkblue'][i])
            plt.fill_between(info['times'],
                             X_diag + err_diag,
                             X_diag - err_diag,
                             alpha=0.2,
                             color=['red', 'purple', 'darkblue'][i])

        self.clusterPlot(diff[-1],
                         diff[-2],
                         p_val=0.05,
                         times=times,
                         y=plt.ylim()[0] + 3 * 0.002,
                         color='black')
        plt.legend(loc='best')
        self.beautifyPlot(y=1 / 3.0,
                          xlabel='Time (ms)',
                          ylabel='Decoding accuracy (%)')
        sns.despine(offset=50, trim=False)
        plt.tight_layout()
        plt.savefig(
            self.FolderTracker(['bdm', '{}_type'.format(header)],
                               filename='cnd-dec.pdf'))
        plt.close()

        plt.figure(figsize=(30, 20))
        norm = MidpointNormalize(midpoint=1 / 3.0)
        plt_idx = 1
        for i, cnd in enumerate(['DTsim', 'DTdisP', 'DTdisDP']):
            for plot in ['matrix', 'diag']:
                ax = plt.subplot(
                    3, 2, plt_idx, title=cnd
                )  #, title = cnd, ylabel = 'Time (ms)', xlabel = 'Time (ms)')
                X = np.stack(
                    [bdm[j][cnd]['standard'] for j in range(len(bdm))])
                p_vals = signedRankArray(X, 1 / 3.0)
                h, _, _, _ = FDR(p_vals)
                dec = np.mean(X, 0)
                dec[~h] = 1 / 3.0
                X_diag = np.stack([np.diag(x) for x in X])
                if plot == 'matrix':
                    plt.imshow(
                        dec,
                        norm=norm,
                        cmap=cm.bwr,
                        interpolation='none',
                        aspect='auto',
                        origin='lower',
                        extent=[times[0], times[-1], times[0], times[-1]],
                        vmin=0.3,
                        vmax=0.40)
                    plt.colorbar()
                elif plot == 'diag':
                    plt.ylim(0.3, 0.45)
                    self.clusterPlot(X_diag,
                                     1 / 3.0,
                                     p_val=0.05,
                                     times=times,
                                     y=(0.31),
                                     color='blue')
                    err_diag, X_diag = bootstrap(X_diag)
                    plt.plot(times, X_diag)
                    plt.fill_between(times,
                                     X_diag + err_diag,
                                     X_diag - err_diag,
                                     alpha=0.2)
                    plt.axhline(y=0.33, color='black', ls='--')
                    plt.axvline(x=-0.2, color='black', ls='--')
                    plt.axvline(x=0, color='black', ls='--')
                    sns.despine(offset=50, trim=False)
                plt_idx += 1

        plt.tight_layout()
        plt.savefig(
            self.FolderTracker(['bdm', '{}_type'.format(header)],
                               filename='dec.pdf'))
        plt.close()