From 4c185ea20919a10a08d7ecec8e3e6bd4c7aa6b31 Mon Sep 17 00:00:00 2001 From: Gabriel Girard Date: Tue, 3 Dec 2024 16:15:53 -0500 Subject: [PATCH] NF - added add_json_args to the arguments, format the output json --- scripts/scil_volume_stats_in_ROI.py | 16 ++++++++-------- scripts/scil_volume_stats_in_labels.py | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/scil_volume_stats_in_ROI.py b/scripts/scil_volume_stats_in_ROI.py index 9fc6002bf..3e9bfe411 100755 --- a/scripts/scil_volume_stats_in_ROI.py +++ b/scripts/scil_volume_stats_in_ROI.py @@ -97,19 +97,19 @@ def main(): # Discussion about the way the normalization is done. # https://github.com/scilus/scilpy/pull/202#discussion_r411355609 # Summary: - # 1) We don't want to normalize with data = (data-min) / (max-min) because - # it zeroes out the minimal values of the array. This is not a large error - # source, but not preferable. - # 2) data = data / max(data) or data = data / sum(data): in practice, when - # we use them in numpy using their weights argument, leads to the same - # result. + # 1) We don't want to normalize with data = (data-min) / (max-min) + # because it zeroes out the minimal values of the array. This is + # not a large error source, but not preferable. + # 2) data = data / max(data) or data = data / sum(data): in practice, + # when we use them in numpy using their weights argument, leads to the + # same result. if args.normalize_weights: roi_data /= np.max(roi_data) elif args.bin: roi_data[np.where(roi_data > 0.0)] = 1.0 elif np.min(roi_data) < 0.0 or np.max(roi_data) > 1.0: - parser.error('ROI {} data should only contain values between 0 and 1. ' - 'Try --normalize_weights.' + parser.error('ROI {} data should only contain values between 0 ' + 'and 1. Try --normalize_weights.' .format(roi_filename)) # Load and process all metrics files. diff --git a/scripts/scil_volume_stats_in_labels.py b/scripts/scil_volume_stats_in_labels.py index 35d5c6c16..6a311459f 100755 --- a/scripts/scil_volume_stats_in_labels.py +++ b/scripts/scil_volume_stats_in_labels.py @@ -20,7 +20,7 @@ import numpy as np from scilpy.image.labels import get_data_as_labels, get_stats_in_label -from scilpy.io.utils import (add_overwrite_arg, add_verbose_arg, +from scilpy.io.utils import (add_json_args, add_overwrite_arg, add_verbose_arg, assert_inputs_exist, assert_headers_compatible) from scilpy.utils.filenames import split_name_with_nii @@ -43,7 +43,7 @@ def _build_arg_parser(): metavar='file', help='Metrics nifti filename. List of the names of the ' 'metrics file, \nin nifti format.') - + add_json_args(p) add_verbose_arg(p) add_overwrite_arg(p) @@ -69,7 +69,8 @@ def main(): for f in tmp_file_list] else: assert_inputs_exist(parser, [args.in_labels] + args.metrics_file_list) - assert_headers_compatible(parser, [args.in_labels] + args.metrics_file_list) + assert_headers_compatible(parser, + [args.in_labels] + args.metrics_file_list) # Loading label_data = get_data_as_labels(nib.load(args.in_labels)) @@ -90,7 +91,7 @@ def main(): if len(args.metrics_file_list) == 1: json_stats = json_stats[metric_name] - print(json.dumps(json_stats)) + print(json.dumps(json_stats, indent=args.indent, sort_keys=args.sort_keys)) if __name__ == "__main__":