def _run_interface(self, runtime): from nltools.data import Brain_Data import os in_file = self.inputs.in_file mask = self.inputs.mask low_pass = self.inputs.low_pass_cutoff high_pass = self.inputs.high_pass_cutoff TR = self.inputs.sampling_rate if low_pass == 0: low_pass = None if high_pass == 0: high_pass = None dat = Brain_Data(in_file, mask=mask) # Handle no filtering if low_pass or high_pass: dat = dat.filter(sampling_rate=TR, low_pass=low_pass, high_pass=high_pass) # Generate output file name out_file = os.path.split(in_file)[-1].split( '.nii.gz')[0] + '_filtered.nii.gz' dat.write(out_file) self._out_file = out_file runtime.returncode = 0 return runtime
import seaborn as sns from nltools.data import Brain_Data from nltools.plotting import component_viewer base_dir = '../data/localizer/derivatives/preproc/fmriprep' base_dir = '/Users/lukechang/Dropbox/Dartbrains/Data/preproc/fmriprep' sub = 'S01' data = Brain_Data(os.path.join(base_dir, f'sub-{sub}','func', f'sub-{sub}_task-localizer_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz')) ## More Preprocessing Even though, we have technically already run most of the preprocessing there are a couple of more steps that will help make the ICA cleaner. First, we will run a high pass filter to remove any low frequency scanner drift. We will pick a fairly arbitrary filter size of 0.0078hz (1/128s). We will also run spatial smoothing with a 6mm FWHM gaussian kernel to increase a signal to noise ratio at each voxel. These steps are very easy to run using nltools after the data has been loaded. data = data.filter(sampling_freq=1/2.4, high_pass=1/128) data = data.smooth(6) ## Independent Component Analysis (ICA) Ok, we are finally ready to run an ICA analysis on our data. ICA attempts to perform blind source separation by decomposing a multivariate signal into additive subcomponents that are maximally independent. We will be using the `decompose()` method on our `Brain_Data` instance. This runs the [FastICA](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.fastica.html) algorithm implemented by scikit-learn. You can choose whether you want to run spatial ICA by setting `axis='voxels` or temporal ICA by setting `axis='images'`. We also recommend running the whitening flat `whiten=True`. By default `decompose` will estimate the maximum components that are possible given the data. We recommend using a completely arbitrary heuristic of 20-30 components. tr = 2.4 output = data.decompose(algorithm='ica', n_components=30, axis='images', whiten=True) ## Viewing Components