Skip to content

Commit

Permalink
NF - added add_json_args to the arguments, format the output json
Browse files Browse the repository at this point in the history
  • Loading branch information
gabknight committed Dec 3, 2024
1 parent 1f7e21f commit 4c185ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions scripts/scil_volume_stats_in_ROI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions scripts/scil_volume_stats_in_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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))
Expand All @@ -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__":
Expand Down

0 comments on commit 4c185ea

Please sign in to comment.