<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_exclusion_file(self, confound, exclusion_criteria, confound_stat='mean'):
 """ Excludes subjects given a certain exclusion criteria. Parameters confound : str or list string or list of confound name(s) from confound files exclusion_criteria : str or list for each confound, an exclusion_criteria should be expressed as a string. It starts with >,<,>= or <= then the numerical threshold. Ex. '>0.2' will entail every subject with the avg greater than 0.2 of confound will be rejected. confound_stat : str or list Can be median, mean, std. How the confound data is aggregated (so if there is a meaasure per time-point, this is averaged over all time points. If multiple confounds specified, this has to be a list.). Returns -------- calls TenetoBIDS.set_bad_files with the files meeting the exclusion criteria. """

        self.add_history(inspect.stack()[0][3], locals(), 1)
        if isinstance(confound, str):
            confound = [confound]
        if isinstance(exclusion_criteria, str):
            exclusion_criteria = [exclusion_criteria]
        if isinstance(confound_stat, str):
            confound_stat = [confound_stat]
        if len(exclusion_criteria) != len(confound):
            raise ValueError(
                'Same number of confound names and exclusion criteria must be given')
        if len(confound_stat) != len(confound):
            raise ValueError(
                'Same number of confound names and confound stats must be given')
        relex, crit = process_exclusion_criteria(exclusion_criteria)
        files = sorted(self.get_selected_files(quiet=1))
        confound_files = sorted(
            self.get_selected_files(quiet=1, pipeline='confound'))
        files, confound_files = confound_matching(files, confound_files)
        bad_files = []
        bs = 0
        foundconfound = []
        foundreason = []
        for s, cfile in enumerate(confound_files):
            df = load_tabular_file(cfile, index_col=None)
            found_bad_subject = False
            for i, _ in enumerate(confound):
                if confound_stat[i] == 'median':
                    if relex[i](df[confound[i]].median(), crit[i]):
                        found_bad_subject = True
                elif confound_stat[i] == 'mean':
                    if relex[i](df[confound[i]].mean(), crit[i]):
                        found_bad_subject = True
                elif confound_stat[i] == 'std':
                    if relex[i](df[i][confound[i]].std(), crit[i]):
                        found_bad_subject = True
                if found_bad_subject:
                    foundconfound.append(confound[i])
                    foundreason.append(exclusion_criteria[i])
            if found_bad_subject:
                bad_files.append(files[s])
                bs += 1
        self.set_bad_files(
            bad_files, reason='excluded file (confound over specfied stat threshold)')
        for i, f in enumerate(bad_files):
            sidecar = get_sidecar(f)
            sidecar['file_exclusion'] = {}
            sidecar['confound'] = foundconfound[i]
            sidecar['threshold'] = foundreason[i]
            for af in ['.tsv', '.nii.gz']:
                f = f.split(af)[0]
            f += '.json'
            with open(f, 'w') as fs:
                json.dump(sidecar, fs)
        print('Removed ' + str(bs) + ' files from inclusion.')