def estimate_smoothness(self, overwrite=None, imgtype='zstat'): """ estimate smoothness of Z maps using FSL's smoothness estimation """ log_to_file( self.dirs.logfile, sys._getframe().f_code.co_name, headspace=2) func_args = inspect.getargvalues( inspect.currentframe()).locals log_to_file( self.dirs.logfile, stringify_dict(func_args)) if overwrite is None: overwrite = self.overwrite output_file = os.path.join(self.dirs.dirs['metadata'], 'smoothness_est.csv') if os.path.exists(output_file) and not overwrite: if self.verbose: print('using existing smoothness file') smoothness_df = pandas.read_csv(output_file) return(smoothness_df) # use nipype's interface to the FSL smoothest command est = SmoothEstimate() smoothness = [] for teamID in self.complete_image_sets['unthresh']: for hyp in range(1, 10): if hyp not in self.teams[teamID].images['unthresh'][imgtype]: # fill missing data with nan print('no zstat present for', teamID, hyp) smoothness.append([teamID, hyp, numpy.nan, numpy.nan, numpy.nan]) continue infile = self.teams[teamID].images['unthresh'][imgtype][hyp] if not os.path.exists(infile): print('no image present:', infile) continue else: if self.verbose: print('estimating smoothness for hyp', hyp) est.inputs.zstat_file = infile est.inputs.mask_file = self.dirs.MNI_mask est.terminal_output = 'file_split' smoothest_output = est.run() smoothness.append([teamID, hyp, smoothest_output.outputs.dlh, smoothest_output.outputs.volume, smoothest_output.outputs.resels]) self.teams[teamID].logs['smoothest'] = ( smoothest_output.runtime.stdout, smoothest_output.runtime.stderr) smoothness_df = pandas.DataFrame( smoothness, columns=['teamID', 'hyp', 'dhl', 'volume', 'resels']) smoothness_df.to_csv(output_file) return(smoothness_df)