From 4e0c9a8908ea2fb09008834b9dba5936d916d21d Mon Sep 17 00:00:00 2001
From: Alexander Drabent <alex@tls-tautenburg.de>
Date: Wed, 15 Apr 2020 18:58:52 +0200
Subject: [PATCH] add losoto steps for PA

Former-commit-id: 247e0e9118f48386559cbf554430826cf6c4cde7
Former-commit-id: 56d7d7f7dfd500ff6f00776f5d63a5d953979ed0
---
 lofar-cwl/steps/LoSoTo.Duplicate.cwl    |   8 +-
 lofar-cwl/steps/LoSoTo.Plot.cwl         |  12 +-
 lofar-cwl/steps/LoSoTo.Polalign.cwl     |   8 +-
 lofar-cwl/steps/LoSoTo.Residual.cwl     |  10 +-
 lofar-cwl/steps/ddecal.cwl              |   2 +-
 steps/h5parmcat.cwl                     |  87 +++++++
 subworkflow/pol_align.cwl               | 115 +++++----
 workflows/HBA_calibrator.cwl            |  47 ++--
 workflows/prefactor_calibrator.cwl      | 109 +++-----
 workflows/prefactor_calibrator/pa.cwl   | 315 ++++++++++++++++++++++++
 workflows/prefactor_calibrator/prep.cwl |  61 +----
 11 files changed, 572 insertions(+), 202 deletions(-)
 create mode 100644 steps/h5parmcat.cwl
 create mode 100644 workflows/prefactor_calibrator/pa.cwl

diff --git a/lofar-cwl/steps/LoSoTo.Duplicate.cwl b/lofar-cwl/steps/LoSoTo.Duplicate.cwl
index 2219758c..7fe56b03 100644
--- a/lofar-cwl/steps/LoSoTo.Duplicate.cwl
+++ b/lofar-cwl/steps/LoSoTo.Duplicate.cwl
@@ -30,7 +30,7 @@ arguments:
 
 hints:
   DockerRequirement:
-    dockerPull: lofareosc/lofar-pipeline-ci:latest
+    dockerPull: lofareosc/prefactor:HBAcalibrator
 
 inputs:
   - id: input_h5parm
@@ -48,8 +48,12 @@ outputs:
     format: lofar:#H5Parm
     outputBinding:
       glob: $(inputs.input_h5parm.basename)
+  - id: log
+    type: File
+    outputBinding:
+      glob: $(inputs.input_h5parm.basename)-losoto.log
 
-
+stdout: $(inputs.input_h5parm.basename)-losoto.log
 $namespaces:
   lofar: https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl
 $schema:
diff --git a/lofar-cwl/steps/LoSoTo.Plot.cwl b/lofar-cwl/steps/LoSoTo.Plot.cwl
index d3d07743..7f3a77e4 100644
--- a/lofar-cwl/steps/LoSoTo.Plot.cwl
+++ b/lofar-cwl/steps/LoSoTo.Plot.cwl
@@ -15,7 +15,7 @@ requirements:
   InitialWorkDirRequirement:
     listing:
       - entryname: 'parset.config'
-        entry: $(get_losoto_config().join('\n'))
+        entry: $(get_losoto_config('PLOT').join('\n'))
       - entryname: $(inputs.input_h5parm.basename)
         entry: $(inputs.input_h5parm)
         writable: true
@@ -29,14 +29,14 @@ arguments:
 
 hints:
   DockerRequirement:
-    dockerPull: lofareosc/lofar-pipeline-ci:latest
+    dockerPull: lofareosc/prefactor:HBAcalibrator
 
 inputs:
   - id: input_h5parm
     type: File
     format: lofar:#H5Parm
   - id: soltab
-    type: string[]
+    type: string
     doc: "Tabs to plot"
 
   - id: axesInPlot
@@ -125,6 +125,12 @@ outputs:
     type: File[]
     outputBinding:
       glob: "$(inputs.prefix)*.png"
+  - id: logfile
+    type: File
+    outputBinding:
+      glob: $(inputs.input_h5parm.basename)-losoto.log
+
+stdout: $(inputs.input_h5parm.basename)-losoto.log      
 
 
 $namespaces:
diff --git a/lofar-cwl/steps/LoSoTo.Polalign.cwl b/lofar-cwl/steps/LoSoTo.Polalign.cwl
index a6a65068..0c53cba5 100755
--- a/lofar-cwl/steps/LoSoTo.Polalign.cwl
+++ b/lofar-cwl/steps/LoSoTo.Polalign.cwl
@@ -48,7 +48,7 @@ arguments:
 
 hints:
   DockerRequirement:
-    dockerPull: lofareosc/lofar-pipeline-ci:latest
+    dockerPull: lofareosc/prefactor:HBAcalibrator
 
 inputs:
   - id: input_h5parm
@@ -88,5 +88,9 @@ outputs:
     format: lofar:#H5Parm
     outputBinding:
       glob: $(inputs.input_h5parm.basename)
+  - id: log
+    type: File
+    outputBinding:
+      glob: $(inputs.input_h5parm.basename)-losoto.log
 
-
+stdout: $(inputs.input_h5parm.basename)-losoto.log
diff --git a/lofar-cwl/steps/LoSoTo.Residual.cwl b/lofar-cwl/steps/LoSoTo.Residual.cwl
index 9dd82a8a..7a8b8ba5 100644
--- a/lofar-cwl/steps/LoSoTo.Residual.cwl
+++ b/lofar-cwl/steps/LoSoTo.Residual.cwl
@@ -29,7 +29,7 @@ arguments:
 
 hints:
   DockerRequirement:
-    dockerPull: lofareosc/lofar-pipeline-ci:latest
+    dockerPull: lofareosc/prefactor:HBAcalibrator
 
 inputs:
   - id: input_h5parm
@@ -49,9 +49,15 @@ inputs:
 outputs:
   - id: output_h5parm
     type: File
-    format: lofar#H5Parm
+    format: lofar:#H5Parm
     outputBinding:
       glob: $(inputs.input_h5parm.basename)
+  - id: log
+    type: File
+    outputBinding:
+      glob: $(inputs.input_h5parm.basename)-losoto.log
+
+stdout: $(inputs.input_h5parm.basename)-losoto.log
 
 $namespaces:
   lofar: https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl
diff --git a/lofar-cwl/steps/ddecal.cwl b/lofar-cwl/steps/ddecal.cwl
index cee6e89b..e2620ffe 100644
--- a/lofar-cwl/steps/ddecal.cwl
+++ b/lofar-cwl/steps/ddecal.cwl
@@ -14,7 +14,7 @@ requirements:
 
 hints:
   DockerRequirement:
-    dockerPull: lofareosc/lofar-pipeline-ci:latest
+    dockerPull: lofareosc/prefactor:HBAcalibrator
 
 arguments:
   - steps=[ddecal]
diff --git a/steps/h5parmcat.cwl b/steps/h5parmcat.cwl
new file mode 100644
index 00000000..bd3861c1
--- /dev/null
+++ b/steps/h5parmcat.cwl
@@ -0,0 +1,87 @@
+class: CommandLineTool
+cwlVersion: v1.0
+$namespaces:
+  sbg: 'https://www.sevenbridges.com/'
+  lofar: https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl
+$schema:
+  - https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl
+
+id: h5parmcat
+
+baseCommand:
+  - H5parm_collector.py
+inputs:
+  - id: h5parmFiles
+    type: File
+    format: lofar:#H5Parm
+    inputBinding:
+      position: 0
+    doc: List of h5parm files
+  - default: sol000
+    id: insolset
+    type: string?
+    inputBinding:
+      position: 0
+      prefix: '--insolset'
+    doc: Input solset name
+  - default: sol000
+    id: outsolset
+    type: string?
+    inputBinding:
+      position: 0
+      prefix: '--outsolset'
+    doc: Output solset name
+  - id: insoltab
+    type: string?
+    inputBinding:
+      position: 0
+      prefix: '--insoltab'
+    doc: Output solset name
+
+  - default: cal_solutions.h5
+    id: outh5parmname
+    type: string
+    inputBinding:
+      position: 0
+      prefix: '--outh5parm'
+    doc: Output h5parm name
+  - id: squeeze
+    type: boolean
+    default: false
+    inputBinding:
+      position: 0
+      prefix: '-q'
+    doc: removes all axes with the length of 1
+  - default: true
+    id: verbose
+    type: boolean
+    inputBinding:
+      position: 0
+      prefix: '-v'
+    doc: verbose output
+  - default: true
+    id: clobber
+    type: boolean
+    inputBinding:
+      position: 0
+      prefix: '-c'
+    doc: overwrite output
+    
+outputs:
+  - id: outh5parm
+    doc: Output h5parm
+    type: File
+    format: lofar:#H5Parm
+    outputBinding:
+      glob: $(inputs.outh5parmname)
+  - id: log
+    type: File
+    outputBinding:
+      glob: $(inputs.outh5parmname)-parm_collector_output.log
+label: H5parmcat
+hints:
+  - class: DockerRequirement
+    dockerPull: 'lofareosc/prefactor:HBAcalibrator'
+stdout: $(inputs.outh5parmname)-parm_collector_output.log
+requirements:
+  - class: InlineJavascriptRequirement
\ No newline at end of file
diff --git a/subworkflow/pol_align.cwl b/subworkflow/pol_align.cwl
index 5a879a4e..ec67ee23 100644
--- a/subworkflow/pol_align.cwl
+++ b/subworkflow/pol_align.cwl
@@ -1,60 +1,83 @@
 class: Workflow
 cwlVersion: v1.0
-id: pa
-label: pa
+id: pol_align
+label: PolAlign
 $namespaces:
   sbg: 'https://www.sevenbridges.com/'
+  lofar: 'https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl'
 inputs:
-  - id: msin
-    type: 'Directory[]'
-    'sbg:x': -1000
-    'sbg:y': -100
-  - id: do_smooth
-    type: boolean
-    'sbg:x': -1000
-    'sbg:y': 0
-  - id: sourcedb
+  - id: refAnt
+    type: string?
+    'sbg:x': -451.3746643066406
+    'sbg:y': -493.92510986328125
+  - id: input_h5parm
     type: File
-    'sbg:x': -1000
-    'sbg:y': 100
+    'sbg:x': -743.1871948242188
+    'sbg:y': -316.5615234375
 outputs:
-  - id: blsmooth.log
+  - id: output_h5parm
     outputSource:
-      - concat_logfiles_blsmooth/output
+      - losoto_residual/output_h5parm
     type: File
-    'sbg:x': 1000
-    'sbg:y': 100
+    format: lofar:#H5Parm
+    'sbg:x': 152.59103393554688
+    'sbg:y': -289.2899169921875
+  - id: logfiles
+    outputSource:
+      - losoto_duplicate/log
+      - losoto_polalign/log
+      - losoto_residual/log
+    linkMerge: merge_flattened
+    type: 'File[]'
+
 steps:
-  - id: calibrate_first
+  - id: losoto_duplicate
+    in:
+      - id: input_h5parm
+        source: input_h5parm
+      - id: soltab
+        default: sol000/phase000
+      - id: soltabOut
+        default: phaseOrig
+    out:
+      - id: output_h5parm
+      - id: log
+    run: ../lofar-cwl/steps/LoSoTo.Duplicate.cwl
+    'sbg:x': -423.6229248046875
+    'sbg:y': -287.8958435058594
+  - id: losoto_polalign
     in:
-      - id: msin
-        source: msin
-      - id: do_smooth
-        source: do_smooth
-      - id: sourcedb
-        source: sourcedb
+      - id: input_h5parm
+        source: losoto_duplicate/output_h5parm
+      - id: soltab
+        default: sol000/phase000
+      - id: soltabout
+        default: polalign
+      - id: average
+        default: true
+      - id: replace
+        default: true
+      - id: refAnt
+        source: refAnt
     out:
-      - id: msout
-      - id: blsmooth.log
-    run: ../subworkflow/calibrate_first.cwl
-    label: calibrate_first
-    scatter:
-      - msin
-    'sbg:x': -500
-    'sbg:y': 0
-  - id: concat_logfiles_blsmooth
+      - id: output_h5parm
+      - id: log
+    run: ../lofar-cwl/steps/LoSoTo.Polalign.cwl
+    'sbg:x': -203.663818359375
+    'sbg:y': -292.61700439453125
+  - id: losoto_residual
     in:
-      - id: file_list
-        source:
-          - calibrate_first/blsmooth.log
-      - id: file_prefix
-        default: blsmooth
+      - id: input_h5parm
+        source: losoto_polalign/output_h5parm
+      - id: soltab
+        default: sol000/phase000
+      - id: soltabsToSub
+        default:
+          - polalign
     out:
-      - id: output
-    run: ../steps/concatenate_files.cwl
-    label: concat_logfiles_blsmooth
-    'sbg:x': 0
-    'sbg:y': 300
-requirements:
-  - class: SubworkflowFeatureRequirement
-  - class: ScatterFeatureRequirement
+      - id: output_h5parm
+      - id: log
+    run: ../lofar-cwl/steps/LoSoTo.Residual.cwl
+    'sbg:x': -0.012040258385241032
+    'sbg:y': -287.7294006347656
+requirements: []
diff --git a/workflows/HBA_calibrator.cwl b/workflows/HBA_calibrator.cwl
index 835efc46..fda22fbe 100644
--- a/workflows/HBA_calibrator.cwl
+++ b/workflows/HBA_calibrator.cwl
@@ -192,10 +192,10 @@ inputs:
     'sbg:x': -1000
     'sbg:y': 1900
 outputs:
-  - id: instrument.h5
+  - id: solutions
     outputSource:
-      - prefactor/instrument.h5
-    type: File
+      - save_solutions/log_dir
+    type: Directory
     'sbg:x': 1500
     'sbg:y': -200
   - id: msout
@@ -304,19 +304,11 @@ steps:
       - id: bandpass_freqresolution
         source: bandpass_freqresolution
     out:
-      - id: check_Ateam_separation.png
-      - id: check_Ateam_separation.log
-      - id: make_sourcedb_ateam.log
+      - id: logfiles
       - id: msout
-      - id: logfile_prep_cal
       - id: parset
-      - id: find_skymodel_cal.log
-      - id: make_sourcedb.log
-      - id: BLsmooth.log
-      - id: predict_cal.log
-      - id: calib_cal.log
-      - id: h5parm_collector.log
       - id: instrument.h5
+      - id: inspection
     run: ./prefactor_calibrator.cwl
     label: prefactor_calibrator
     'sbg:x': 0
@@ -326,17 +318,9 @@ steps:
       - id: log_files
         linkMerge: merge_flattened
         source:
-          - prefactor/check_Ateam_separation.log
-          - prefactor/make_sourcedb_ateam.log
-          - prefactor/find_skymodel_cal.log
-          - prefactor/make_sourcedb.log
-          - prefactor/logfile_prep_cal
-          - prefactor/BLsmooth.log
-          - prefactor/predict_cal.log
-          - prefactor/calib_cal.log
-          - prefactor/h5parm_collector.log
+          - prefactor/logfiles
       - id: sub_directory_name
-        default: logs
+        default: results/logs
     out:
       - id: log_dir
     run: ./../steps/collectlog.cwl
@@ -348,15 +332,28 @@ steps:
       - id: log_files
         linkMerge: merge_flattened
         source:
-          - prefactor/check_Ateam_separation.png
+          - prefactor/inspection
       - id: sub_directory_name
-        default: inspection
+        default: results/inspection
     out:
       - id: log_dir
     run: ./../steps/collectlog.cwl
     label: save_inspection
     'sbg:x': 1000
     'sbg:y': 1200
+  - id: save_solutions
+    in:
+      - id: log_files
+        source:
+          - prefactor/instrument.h5
+      - id: sub_directory_name
+        default: results/cal_values
+    out:
+      - id: log_dir
+    run: ./../steps/collectlog.cwl
+    label: save_solutions
+    'sbg:x': 1000
+    'sbg:y': 1400
 requirements:
   - class: SubworkflowFeatureRequirement
   - class: MultipleInputFeatureRequirement
diff --git a/workflows/prefactor_calibrator.cwl b/workflows/prefactor_calibrator.cwl
index ff1b5c5e..04316e70 100644
--- a/workflows/prefactor_calibrator.cwl
+++ b/workflows/prefactor_calibrator.cwl
@@ -192,84 +192,40 @@ inputs:
     'sbg:x': -1000
     'sbg:y': 1900
 outputs:
-  - id: instrument.h5
-    outputSource:
-      - prep/instrument.h5
-    type: File
-    'sbg:x': 1000
-    'sbg:y': -500
-  - id: h5parm_collector.log
-    outputSource:
-      - prep/h5parm_collector.log
-    type: File
-    'sbg:x': 1000
-    'sbg:y': -400
-  - id: check_Ateam_separation.png
+  - id: inspection
+    linkMerge: merge_flattened
     outputSource:
-      - prep/check_Ateam_separation.png
-    type: File
+      - prep/check_Ateam_separation.png 
+      - pa/inspection
+    type: File[]
     'sbg:x': 1000
-    'sbg:y': -300
-  - id: check_Ateam_separation.log
+    'sbg:y': -600
+  - id: instrument.h5
     outputSource:
-      - prep/check_Ateam_separation.log
+      - pa/output_h5parm
     type: File
     'sbg:x': 1000
-    'sbg:y': -200
-  - id: make_sourcedb_ateam.log
-    outputSource:
-      - prep/make_sourcedb_ateam.log
-    type: File?
-    'sbg:x': 1000
-    'sbg:y': -100
+    'sbg:y': -500
   - id: msout
     outputSource:
-      - prep/msout
+      - pa/msout
     type: 'Directory[]'
     'sbg:x': 1000
     'sbg:y': 0
-  - id: logfile_prep_cal
-    outputSource:
-      - prep/logfile_prep_cal
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 100
   - id: parset
     outputSource:
       - prep/parset
     type: 'File[]'
     'sbg:x': 1000
     'sbg:y': 200
-  - id: find_skymodel_cal.log
-    outputSource:
-      - prep/find_skymodel_cal.log
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 300
-  - id: make_sourcedb.log
+  - id: logfiles
     outputSource:
-      - prep/make_sourcedb.log
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 400
-  - id: BLsmooth.log
-    outputSource:
-      - prep/BLsmooth.log
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 500
-  - id: predict_cal.log
-    outputSource:
-      - prep/predict_cal.log
-    type: File
+      - prep/logfiles
+      - pa/logfiles
+    type: 'File[]'
+    linkMerge: merge_flattened
     'sbg:x': 1000
     'sbg:y': 600
-  - id: calib_cal.log
-    outputSource:
-      - prep/calib_cal.log
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 700
 steps:
   - id: prep
     in:
@@ -278,8 +234,6 @@ steps:
           - msin
       - id: filter_baselines
         source: filter_baselines
-      - id: do_smooth
-        source: do_smooth
       - id: raw_data
         source: raw_data
       - id: propagatesolutions
@@ -316,28 +270,41 @@ steps:
         source: overhead
       - id: min_separation
         source: min_separation
+      - id: do_smooth
+        source: do_smooth
       - id: max_separation_arcmin
         source: max_separation_arcmin
       - id: A-Team_skymodel
         source: A-Team_skymodel
     out:
+      - id: instrument.h5
+      - id: logfiles
       - id: check_Ateam_separation.png
-      - id: check_Ateam_separation.log
-      - id: make_sourcedb_ateam.log
       - id: msout
-      - id: logfile_prep_cal
       - id: parset
-      - id: find_skymodel_cal.log
-      - id: make_sourcedb.log
       - id: sourcedb
-      - id: BLsmooth.log
-      - id: predict_cal.log
-      - id: calib_cal.log
-      - id: h5parm_collector.log
-      - id: instrument.h5
     run: ./prefactor_calibrator/prep.cwl
     label: prep
     'sbg:x': 0
     'sbg:y': 0
+  - id: pa
+    in:
+      - id: msin
+        source:
+          - prep/msout
+      - id: h5parm
+        source:
+          - prep/instrument.h5
+      - id: refant
+        source: refant
+    out:
+      - id: msout
+      - id: output_h5parm
+      - id: inspection
+      - id: logfiles
+    run: ./prefactor_calibrator/pa.cwl
+    label: PA
+    'sbg:x': 500
+    'sbg:y': 0
 requirements:
   - class: SubworkflowFeatureRequirement
diff --git a/workflows/prefactor_calibrator/pa.cwl b/workflows/prefactor_calibrator/pa.cwl
new file mode 100644
index 00000000..c2951b3d
--- /dev/null
+++ b/workflows/prefactor_calibrator/pa.cwl
@@ -0,0 +1,315 @@
+class: Workflow
+cwlVersion: v1.0
+id: pa
+label: PA
+$namespaces:
+  sbg: 'https://www.sevenbridges.com/'
+inputs:
+  - id: msin
+    type: 'Directory[]'
+    'sbg:x': -1000
+    'sbg:y': -100
+  - id: h5parm
+    type: File
+    'sbg:x': -1000
+    'sbg:y': 0
+  - id: refant
+    type: string?
+    'sbg:x': -1000
+    'sbg:y': 100
+outputs:
+  - id: msout
+    outputSource:
+      - msin
+    type: 'Directory[]'
+    'sbg:x': 1000
+    'sbg:y': -100
+  - id: inspection
+    outputSource:
+      - losoto_plot_P3/output_plots
+      - losoto_plot_Pd/output_plots
+      - losoto_plot_Rot3/output_plots
+      - losoto_plot_A3/output_plots
+      - losoto_plot_Align/output_plots
+      - losoto_plot_Pr/output_plots
+      - losoto_plot_Pr2/output_plots
+    type: 'File[]'
+    linkMerge: merge_flattened
+    'sbg:x': 1000
+    'sbg:y': 0
+  - id: output_h5parm
+    outputSource:
+      - write_solutions/outh5parm
+    type: File
+    'sbg:x': 1000
+    'sbg:y': 100
+  - id: logfiles
+    outputSource:
+      - concat_logfiles_pa/output
+    type: 'File[]'
+    linkMerge: merge_flattened
+    'sbg:x': 1000
+    'sbg:y': 200
+steps:
+  - id: pol_align
+    in:
+      - id: refAnt
+        default: CS001HBA0
+        source: refant
+      - id: input_h5parm
+        source: h5parm
+    out:
+      - id: output_h5parm
+      - id: logfiles
+    run: ../../subworkflow/pol_align.cwl
+    label: PolAlign
+    'sbg:x': -500
+    'sbg:y': 0
+  - id: losoto_plot_P3
+    in:
+      - id: input_h5parm
+        source: pol_align/output_h5parm
+      - id: soltab
+        default: sol000/phaseOrig
+      - id: axesInPlot
+        default:
+          - time
+          - freq
+      - id: axisInTable
+        default: ant
+      - id: minmax
+        default:
+          - -3.14
+          - 3.14
+      - id: plotFlag
+        default: true
+      - id: refAnt
+        source: refant
+      - id: prefix
+        default: polalign_ph_
+    out:
+      - id: output_plots
+      - id: logfile
+    run: ../../lofar-cwl/steps/LoSoTo.Plot.cwl
+    label: losoto_plot_P3
+    'sbg:x': 0
+    'sbg:y': -200
+  - id: losoto_plot_Pd
+    in:
+      - id: input_h5parm
+        source: pol_align/output_h5parm
+      - id: soltab
+        default: sol000/phaseOrig
+      - id: axesInPlot
+        default:
+          - time
+          - freq
+      - id: axisInTable
+        default: ant
+      - id: axisDiff
+        default: pol
+      - id: minmax
+        default:
+          - -3.14
+          - 3.14
+      - id: plotFlag
+        default: true
+      - id: refAnt
+        source: refant
+      - id: prefix
+        default: polalign_ph_poldif
+    out:
+      - id: output_plots
+      - id: logfile
+    run: ../../lofar-cwl/steps/LoSoTo.Plot.cwl
+    label: losoto_plot_Pd
+    'sbg:x': 0
+    'sbg:y': -100
+  - id: losoto_plot_Rot3
+    in:
+      - id: input_h5parm
+        source: pol_align/output_h5parm
+      - id: soltab
+        default: sol000/rotation000
+      - id: axesInPlot
+        default:
+          - time
+          - freq
+      - id: axisInTable
+        default: ant
+      - id: plotFlag
+        default: true
+      - id: refAnt
+        source: refant
+      - id: prefix
+        default: polalign_rotangle
+    out:
+      - id: output_plots
+      - id: logfile
+    run: ../../lofar-cwl/steps/LoSoTo.Plot.cwl
+    label: losoto_plot_Rot3
+    'sbg:x': 0
+    'sbg:y': 0
+  - id: losoto_plot_A3
+    in:
+      - id: input_h5parm
+        source: pol_align/output_h5parm
+      - id: soltab
+        default: sol000/amplitude000
+      - id: axesInPlot
+        default:
+          - time
+          - freq
+      - id: axisInTable
+        default: ant
+      - id: plotFlag
+        default: true
+      - id: prefix
+        default: polalign_amp
+    out:
+      - id: output_plots
+      - id: logfile
+    run: ../../lofar-cwl/steps/LoSoTo.Plot.cwl
+    label: losoto_plot_A3
+    'sbg:x': 0
+    'sbg:y': 100
+  - id: losoto_plot_Align
+    in:
+      - id: input_h5parm
+        source: pol_align/output_h5parm
+      - id: soltab
+        default: sol000/polalign
+      - id: axesInPlot
+        default:
+          - time
+          - freq
+      - id: axisInTable
+        default: ant
+      - id: axisDiff
+        default: pol
+      - id: minmax
+        default:
+          - -3.14
+          - 3.14
+      - id: plotFlag
+        default: true
+      - id: refAnt
+        source: refant
+      - id: prefix
+        default: polalign
+    out:
+      - id: output_plots
+      - id: logfile
+    run: ../../lofar-cwl/steps/LoSoTo.Plot.cwl
+    label: losoto_plot_Align
+    'sbg:x': 0
+    'sbg:y': 200
+  - id: losoto_plot_Pr
+    in:
+      - id: input_h5parm
+        source: pol_align/output_h5parm
+      - id: soltab
+        default: sol000/phase000
+      - id: axesInPlot
+        default:
+          - time
+          - freq
+      - id: axisInTable
+        default: ant
+      - id: axisDiff
+        default: pol
+      - id: minmax
+        default:
+          - -3.14
+          - 3.14
+      - id: plotFlag
+        default: true
+      - id: refAnt
+        source: refant
+      - id: prefix
+        default: polalign_ph-res_poldif
+    out:
+      - id: output_plots
+      - id: logfile
+    run: ../../lofar-cwl/steps/LoSoTo.Plot.cwl
+    label: losoto_plot_Pr
+    'sbg:x': 0
+    'sbg:y': 300
+  - id: losoto_plot_Pr2
+    in:
+      - id: input_h5parm
+        source: pol_align/output_h5parm
+      - id: soltab
+        default: sol000/phase000
+      - id: axesInPlot
+        default:
+          - time
+          - freq
+      - id: axisInTable
+        default: ant
+      - id: axisInCol
+        default: pol
+      - id: minmax
+        default:
+          - -3.14
+          - 3.14
+      - id: plotFlag
+        default: true
+      - id: refAnt
+        source: refant
+      - id: prefix
+        default: polalign_ph-res_
+    out:
+      - id: output_plots
+      - id: logfile
+    run: ../../lofar-cwl/steps/LoSoTo.Plot.cwl
+    label: losoto_plot_Pr2
+    'sbg:x': 0
+    'sbg:y': 400
+  - id: concat_logfiles_pa
+    in:
+      - id: file_list
+        linkMerge: merge_flattened
+        source:
+          - pol_align/logfiles
+          - losoto_plot_P3/logfile
+          - losoto_plot_Pd/logfile
+          - losoto_plot_Rot3/logfile
+          - losoto_plot_A3/logfile
+          - losoto_plot_Align/logfile
+          - losoto_plot_Pr/logfile
+          - losoto_plot_Pr2/logfile
+          - write_solutions/log
+      - id: file_prefix
+        default: losoto_PA
+    out:
+      - id: output
+    run: ../../steps/concatenate_files.cwl
+    label: concat_logfiles_PA
+    'sbg:x': 500
+    'sbg:y': 500
+  - id: write_solutions
+    in:
+      - id: h5parmFiles
+        source:
+          - pol_align/output_h5parm
+      - id: outh5parmname
+        default: cal_solutions.h5
+      - id: outsolset
+        default: calibrator
+      - id: insoltab
+        default: polalign
+      - id: squeeze
+        default: true
+      - id: verbose
+        default: true
+    out:
+      - id: outh5parm
+      - id: log
+    run: ../../steps/h5parmcat.cwl
+    label: write_solutions
+    'sbg:x': 0
+    'sbg:y': 500
+requirements:
+  - class: SubworkflowFeatureRequirement
+  - class: MultipleInputFeatureRequirement
diff --git a/workflows/prefactor_calibrator/prep.cwl b/workflows/prefactor_calibrator/prep.cwl
index 8e121862..538c2be3 100644
--- a/workflows/prefactor_calibrator/prep.cwl
+++ b/workflows/prefactor_calibrator/prep.cwl
@@ -116,82 +116,43 @@ outputs:
     type: File
     'sbg:x': 1000
     'sbg:y': -500
-  - id: h5parm_collector.log
-    outputSource:
-      - h5parm_collector/log
-    type: File
-    'sbg:x': 1000
-    'sbg:y': -400
   - id: check_Ateam_separation.png
     outputSource:
       - check_ateam_separation/output_imag
     type: File
     'sbg:x': 1000
     'sbg:y': -300
-  - id: check_Ateam_separation.log
-    outputSource:
-      - check_ateam_separation/logfile
-    type: File
-    'sbg:x': 1000
-    'sbg:y': -200
-  - id: make_sourcedb_ateam.log
-    outputSource:
-      - make_sourcedb_ateam/log
-    type: File?
-    'sbg:x': 1000
-    'sbg:y': -100
   - id: msout
     outputSource:
       - predict_calibrate/msout
     type: 'Directory[]'
     'sbg:x': 1000
     'sbg:y': 0
-  - id: logfile_prep_cal
-    outputSource:
-      - concat_logfiles_prep_cal/output
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 100
   - id: parset
     outputSource:
       - ndppp_prep_cal/parset
     type: 'File[]'
     'sbg:x': 1000
     'sbg:y': 200
-  - id: find_skymodel_cal.log
-    outputSource:
-      - find_skymodel_cal/logfile
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 300
-  - id: make_sourcedb.log
-    outputSource:
-      - make_sourcedb/log
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 400
   - id: sourcedb
     outputSource:
       - make_sourcedb/sourcedb
     type: File
     'sbg:x': 1000
     'sbg:y': 500
-  - id: BLsmooth.log
-    outputSource:
-      - concat_logfiles_blsmooth/output
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 600
-  - id: predict_cal.log
-    outputSource:
-      - concat_logfiles_predict/output
-    type: File
-    'sbg:x': 1000
-    'sbg:y': 700
-  - id: calib_cal.log
+  - id: logfiles
+    linkMerge: merge_flattened
     outputSource:
       - concat_logfiles_calib/output
-    type: File
+      - concat_logfiles_predict/output
+      - concat_logfiles_blsmooth/output
+      - make_sourcedb/log
+      - find_skymodel_cal/logfile
+      - concat_logfiles_prep_cal/output
+      - make_sourcedb_ateam/log
+      - check_ateam_separation/logfile
+      - h5parm_collector/log
+    type: 'File[]'
     'sbg:x': 1000
     'sbg:y': 800
 steps:
-- 
GitLab