Esempio n. 1
0
                    t_all=[]
                    # Load the time series and average over ROI
                    t_all=load_nii(nifti_path+this_fix[:-4]+'_stc.nii.gz', ROI_coords,TR, normalize='percent', average=True, verbose=True)
                    
                    for roiNum in range(len(roi_names)):
                        print 'Analyzing '+ roi_names[roiNum]
                        ts_roi=[]; ts_roidt=[]; ts_Box=[];
                        ts_roidv=[]; ts_roidv_dt=[]; ts_roidv_dtBox=[];

                        # Get each time series (1 x TRs)
                        ts_roi=t_all[roiNum].data
                        # Linearly detrend each ROI
                        ts_roidt=signal.detrend(ts_roi, axis=0)

                        # Band pass filter the data using boxcar filter
                        ts_Box=bp_data(ts_roidt, TR, f_ub, f_lb)
                   
                        # Get the derivative
                        ts_roidv=np.diff(ts_roi)
                        # Make it the same size as the original
                        ts_roidv=np.insert(ts_roidv, 0, 0)
                        # Detrend the derivative
                        ts_roidv_dt=signal.detrend(ts_roidv)
                        #Bandpass the derivative
                        ts_roidv_dtBox=bp_data(ts_roidv_dt, TR, f_ub, f_lb)

                        # Plot TS results
                        #plt.figure(); plt.plot(ts_roi); plt.plot(ts_roidt); plt.plot(ts_Box) ;
                        #plt.legend(('Original TS', 'Linearly Filtered TS', 'Bandpass filtered'))

                        # Plot frequencies
Esempio n. 2
0
                for this_fix in sessName[1][runName]:
                    txt_file=nifti_path+this_fix
                    1/0
                    out_file_base=save_path+this_fix[:-4]

                    # read in par file
                    data = np.loadtxt(txt_file)

                    # save the columns of data as separate .1D files
                    for i in xrange(data.shape[1]):
                        mt_deriv=[];

                        # Get derivative
                        mt_deriv=np.diff(data[:,i])
                        # Make it the same size as the original
                        mt_deriv=np.insert(mt_deriv, 0, 0)

                        # Run bandpass filter
                        mt_bp=bp_data(data[:,i], TR, f_ub, f_lb)
                        mt_bp_deriv=bp_data(mt_deriv, TR, f_ub, f_lb)

                        # Save file
                        out_file = '{0}{1}_bp.1D'.format(out_file_base, i+1)
                        np.savetxt(out_file, mt_bp)

                        # Save file
                        out_file = '{0}{1}_bp_deriv.1D'.format(out_file_base, i+1)
                        np.savetxt(out_file, mt_bp_deriv)