diff --git a/bin/population_template b/bin/population_template index 6842c88e81..a79b31e169 100755 --- a/bin/population_template +++ b/bin/population_template @@ -558,19 +558,17 @@ def parse_input_files(in_files, mask_files, contrasts, f_agg_weight=None, whites import csv # pylint: disable=import-outside-toplevel try: with open(f_agg_weight, 'r') as fweights: - agg_weights = dict((row[0].lstrip().rstrip(), row[1]) for row in csv.reader(fweights, delimiter=',', quotechar='#')) + agg_weights = dict((row[0].strip(), row[1].strip()) for row in csv.reader(fweights, delimiter=',', quotechar='#')) except UnicodeDecodeError: with open(f_agg_weight, 'r') as fweights: reader = csv.reader(fweights.read().decode('utf-8', errors='replace'), delimiter=',', quotechar='#') - agg_weights = dict((row[0].lstrip().rstrip(), row[1]) for row in reader) + agg_weights = dict((row[0].strip(), row[1].strip()) for row in reader) pref = '^' + re.escape(get_common_prefix(list(agg_weights.keys()))) suff = re.escape(get_common_postfix(list(agg_weights.keys()))) + '$' - for key in agg_weights.keys(): - agg_weights[re.sub(suff, '', re.sub(pref, '', key))] = agg_weights.pop(key).strip() - + agg_weights = {re.sub(suff, '', re.sub(pref, '', key)):agg_weights[key] for key in agg_weights.keys()} for inp in inputs: if inp.uid not in agg_weights: - raise MRtrixError('aggregation weight not found for %s' % inp.uid) + raise MRtrixError('aggregation weight not found for input "%s"' % inp.uid) inp.aggregation_weight = agg_weights[inp.uid] app.console('Using aggregation weights ' + f_agg_weight) weights = [float(inp.aggregation_weight) for inp in inputs if inp.aggregation_weight is not None]