From e14e45ff518e503ea3ee1864f6c7bc685f3cd225 Mon Sep 17 00:00:00 2001
From: Timo Millenaar <tmillenaar@gmail.com>
Date: Wed, 16 Oct 2024 14:22:56 +0200
Subject: [PATCH] Export quality in outputs.json from aggregate script

---
 aggregate_and_plot.cwl | 4 ++++
 aggregate_and_plot.py  | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/aggregate_and_plot.cwl b/aggregate_and_plot.cwl
index 7fc1214..536eff3 100644
--- a/aggregate_and_plot.cwl
+++ b/aggregate_and_plot.cwl
@@ -24,6 +24,10 @@ outputs:
   type: File
   outputBinding:
     glob: "outputs.txt"
+- id: quality
+  type: File
+  outputBinding:
+    glob: "outputs.json"
 - id: inspect
   type: File
   outputBinding:
diff --git a/aggregate_and_plot.py b/aggregate_and_plot.py
index 8588656..501e7ec 100644
--- a/aggregate_and_plot.py
+++ b/aggregate_and_plot.py
@@ -1,7 +1,11 @@
 #!/usr/bin/env python3
 import argparse
+import subprocess
+import json
 from lofar_quality.manipulate.common import join_inspect_ds
 from lofar_quality.inspect.inspect_dataset import plot_inspect_ds
+from lofar_quality.inspect.v2 import extract_quality_metrics
+from lofar_quality.inspect.common import store_metrics
 from pathlib import Path
 import logging
 
@@ -35,6 +39,9 @@ def main():
     join_inspect_ds(h5_paths, h5_output_path)
     plot_paths = plot_inspect_ds(h5_output_path, workdir, min_elevation=15)
 
+    quality = {"quality": extract_quality_metrics(h5_output_path)}
+    store_metrics("outputs.json", quality)
+
     with open("outputs.txt", "w") as file:
         file.write(str(h5_output_path) + "\n")
         for file_path in plot_paths:
@@ -43,3 +50,4 @@ def main():
 
 if __name__ == "__main__":
     main()
+
-- 
GitLab