def fit(self, mask_file='', mode='+', zscore=2): """ Process/filter/threshold the output to make it ready for plot. If no mask_file is set, will pick the output from GIFT. Parameters ---------- mask_file: str, optional Path to the brain mask file to be used for thresholding. mode: str, optional Choices: '+' for positive threshold, '+-' for positive and negative threshold and '-' for negative threshold. zscore: int or float, optional Value of the Z-score thresholding. """ if not mask_file: mask_file = fetch_one_file(self.ica_dir, self._mask_fname, pat_type='re.match') super(MIALABICAResultsPlotter, self).fit(mask_file=mask_file, mode=mode, zscore=zscore)
def _check_output(self): # read the groups file subj_files = self._get_subject_files() n_timepoints = len(subj_files) # load the loadings file loads = self._load_loadings() # check shapes if n_timepoints != loads.shape[0]: raise AttributeError( 'Shape mismatch between list of subjects {} and loadings data shape {}.' .format(n_timepoints, loads.shape)) # load components image file to check shape match # this doesn't make much sense to be here (because it does not use the components image # but it checks if the ICA output is consistent). compsf = fetch_one_file(self.ica_dir, self._comps_fname) comps_img = niimg.load_img(compsf) n_ics = loads.shape[1] if comps_img.get_data().shape[-1] != n_ics: raise AttributeError( 'Shape mismatch between loadings matrix {} and components data shape {}.' .format(loads.shape, comps_img.get_data().shape))
def _fetch_components_file(self): if self._comps_fname is None: raise NotImplementedError( 'This is a generic class to support the output from different applications,' 'please use a derived class from ICAResultsPlotter.') return fetch_one_file(self.ica_dir, self._comps_fname)
def _load_timecourses(self): """ Return the timecourses image file and checks if the shape is correct.""" # load the timecourses file tcsf = fetch_one_file(self.ica_dir, self._tcs_fname, pat_type='re.match') tcs = niimg.load_img(tcsf).get_data() return tcs
def _get_subject_files(self): """ Load the .mat file with subjects lists, mainly to get the order in which subjects are introduced in the other matrices. """ from itertools import chain subjsf = fetch_one_file(self.ica_dir, self._subjects_fname) mat_file = sio.loadmat(subjsf)['files'] return [ f.strip() for f in list( chain.from_iterable( chain.from_iterable(chain.from_iterable(mat_file)))) ]
def _fetch_components_file(self): return fetch_one_file(self.ica_dir, self._comps_fname)
def _fetch_components_file(self): return fetch_one_file(self.ica_dir, self._comps_fname, pat_type='re.match')
def load_mask(self): """ Return the mask image. """ mask_file = fetch_one_file(self.ica_dir, self._mask_fname, pat_type='re.match') return niimg.load_img(mask_file)
def _load_loadings(self): loadf = fetch_one_file(self.ica_dir, self._tcs_fname) loads = niimg.load_img(loadf).get_data() return loads