Repository: GSTT-CSC/hazen

Issue:
Improve displaying results on terminal
PrettyPrinter could be replaced with `json.dumps()` that can format and display the result dictionary in a simple structured way with less configuration needed.

currently with PrettyPrint: (more compact)
<img width="759" alt="Screenshot 2023-07-15 at 18 27 16" src="https://github.com/GSTT-CSC/hazen/assets/15593138/f22dad3d-c0b2-4b41-88b1-1a48d52758cf">

with json.dumps: (more easy to understand)
<img width="686" alt="image" src="https://github.com/GSTT-CSC/hazen/assets/15593138/63af6d46-fddc-4acc-84fc-da5a92c936f5">


Discussion:

Patch:
diff --git a/hazenlib/__init__.py b/hazenlib/__init__.py
index dafcf1a..309c585 100644
--- a/hazenlib/__init__.py
+++ b/hazenlib/__init__.py
@@ -112,7 +112,7 @@ import importlib
 import inspect
 import logging
 import sys
-import pprint
+import json
 import os
 
 from docopt import docopt
@@ -156,7 +156,6 @@ def init_task(selected_task, files, report, report_dir):
 def main():
     arguments = docopt(__doc__, version=__version__)
     files = get_dicom_files(arguments['<folder>'])
-    pp = pprint.PrettyPrinter(indent=4, depth=1, width=1)
 
     # Set common options
     log_levels = {
@@ -203,7 +202,8 @@ def main():
         task = init_task(selected_task, files, report, report_dir)
         result = task.run()
 
-    print(pp.pformat(result))
+    result_string = json.dumps(result, indent=2)
+    print(result_string)
 
 
 if __name__ == "__main__":
diff --git a/hazenlib/tasks/acr_snr.py b/hazenlib/tasks/acr_snr.py
index 087c3de..4dc21b3 100644
--- a/hazenlib/tasks/acr_snr.py
+++ b/hazenlib/tasks/acr_snr.py
@@ -74,7 +74,7 @@ class ACRSNR(HazenTask):
                 traceback.print_exc(file=sys.stdout)
 
 
-        results = {self.key(snr_dcm): snr_results, 'reports': {'images': self.report_files}}
+        results = {self.key(snr_dcm): snr_results}
 
         # only return reports if requested
         if self.report:
diff --git a/hazenlib/tasks/uniformity.py b/hazenlib/tasks/uniformity.py
index 4e57e7e..e54d8b1 100644
--- a/hazenlib/tasks/uniformity.py
+++ b/hazenlib/tasks/uniformity.py
@@ -148,5 +148,5 @@ class Uniformity(HazenTask):
             fig.savefig(img_path)
             self.report_files.append(img_path)
 
-        return {'horizontal': {'IPEM': fractional_uniformity_horizontal},
-                'vertical': {'IPEM': fractional_uniformity_vertical}}
+        return {'horizontal': fractional_uniformity_horizontal,
+                'vertical': fractional_uniformity_vertical}


Test patch:
diff --git a/tests/test_uniformity.py b/tests/test_uniformity.py
index 8fe2611..2fa43ec 100644
--- a/tests/test_uniformity.py
+++ b/tests/test_uniformity.py
@@ -18,8 +18,8 @@ class TestUniformity(unittest.TestCase):
     def test_uniformity(self):
         results = self.uniformity_task.run()
         key = self.uniformity_task.key(self.uniformity_task.data[0])
-        horizontal_ipem = results[key]['horizontal']['IPEM']
-        vertical_ipem = results[key]['vertical']['IPEM']
+        horizontal_ipem = results[key]['horizontal']
+        vertical_ipem = results[key]['vertical']
 
         print("\ntest_uniformity.py::TestUniformity::test_uniformity")