From 274162b064bc70364d29bec54df953a970f6aedf Mon Sep 17 00:00:00 2001
From: Alexander Drabent <alex@tls-tautenburg.de>
Date: Wed, 28 Oct 2020 13:57:40 +0100
Subject: [PATCH] add structure function

Former-commit-id: 635f6d0a11c4f6e7a11e14df0a9b3a200d7b310d
---
 steps/structure_function.cwl            | 62 +++++++++++++++++++++++++
 workflows/prefactor_target.cwl          |  2 +
 workflows/prefactor_target/finalize.cwl | 51 ++++++++++++++++++--
 3 files changed, 112 insertions(+), 3 deletions(-)
 create mode 100644 steps/structure_function.cwl

diff --git a/steps/structure_function.cwl b/steps/structure_function.cwl
new file mode 100644
index 00000000..434d75f0
--- /dev/null
+++ b/steps/structure_function.cwl
@@ -0,0 +1,62 @@
+class: CommandLineTool
+cwlVersion: v1.0
+$namespaces:
+  lofar: 'https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl'
+  sbg: 'https://www.sevenbridges.com/'
+id: structure_function
+baseCommand:
+  - python3
+  - /usr/local/bin/getStructure_from_phases.py
+inputs:
+  - format: 'lofar:#H5Parm'
+    id: h5parmFile
+    type: File
+    inputBinding:
+      position: 0
+    doc: List of h5parm files
+  - default: 'target'
+    id: solset
+    type: string?
+    inputBinding:
+      position: 0
+      prefix: '--solset'
+    doc: Input solset name
+  - default: 'phase000'
+    id: soltab
+    type: string?
+    inputBinding:
+      position: 0
+      prefix: '--soltab'
+    doc: Name of the soltab
+  - default: 'POINTING'
+    id: outbasename
+    type: string?
+    inputBinding:
+      position: 0
+      prefix: '--outbasename'
+    doc: Namebase of the output files
+outputs:
+  - id: structure_plot
+    doc: Output plot
+    type: File
+    outputBinding:
+      glob: $(inputs.outbasename+'_structure.png')
+  - id: structure_txt
+    doc: Output text
+    type: File
+    outputBinding:
+      glob: $(inputs.outbasename+'_structure.txt')
+  - id: log
+    type: File[]
+    outputBinding:
+      glob: 'structure_function*.log'
+label: structure_function
+requirements:
+  - class: InlineJavascriptRequirement
+hints:
+  - class: DockerRequirement
+    dockerPull: lofareosc/prefactor:HBAcalibrator
+stdout: structure_function.log
+stderr: structure_function_err.log
+$schema:
+  - 'https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl'
diff --git a/workflows/prefactor_target.cwl b/workflows/prefactor_target.cwl
index b1ab4477..f2082880 100644
--- a/workflows/prefactor_target.cwl
+++ b/workflows/prefactor_target.cwl
@@ -242,6 +242,7 @@ outputs:
   - id: inspection
     outputSource:
       - prep/inspection
+      - finalize/inspection
     type: 'File[]'
     linkMerge: merge_flattened
     'sbg:x': 2000
@@ -404,6 +405,7 @@ steps:
     out:
       - id: msout
       - id: solutions
+      - id: inspection
       - id: logfiles
     run: ./prefactor_target/finalize.cwl
     label: finalize
diff --git a/workflows/prefactor_target/finalize.cwl b/workflows/prefactor_target/finalize.cwl
index f4949a37..1b3ab905 100644
--- a/workflows/prefactor_target/finalize.cwl
+++ b/workflows/prefactor_target/finalize.cwl
@@ -46,22 +46,30 @@ outputs:
     outputSource:
       - apply_gsmcal/msout
     type: 'Directory[]'
-    'sbg:x': 1000
+    'sbg:x': 1300
     'sbg:y': 0
   - id: solutions
     outputSource:
       - h5parm_pointingname/outh5parm
     type: File
-    'sbg:x': 1000
+    'sbg:x': 1300
     'sbg:y': 200
   - id: logfiles
     outputSource:
       - concat_logfiles_applygsm/output
       - concat_logfiles_solutions/output
+      - concat_logfiles_structure/output
     type: 'File[]'
     linkMerge: merge_flattened
-    'sbg:x': 1000
+    'sbg:x': 1300
     'sbg:y': 800
+  - id: inspection
+    outputSource:
+      - structure_function/structure_plot
+    type: 'File[]?'
+    linkMerge: merge_flattened
+    'sbg:x': 1300
+    'sbg:y': 500
 steps:
   - id: add_missing_stations
     in:
@@ -169,6 +177,27 @@ steps:
     label: h5parm_pointingname
     'sbg:x': 400
     'sbg:y': 200
+  - id: structure_function
+    in:
+      - id: h5parmFile
+        source: write_solutions/outh5parm
+      - id: solset
+        default: 'target'
+      - id: soltab
+        source:
+          - skymodel_source
+          - gsmcal_step
+        valueFrom: $(self.join(''))
+      - id: outbasename
+        source: get_targetname/targetname
+    out:
+      - id: structure_plot
+      - id: structure_txt
+      - id: log
+    run: ../../steps/structure_function.cwl
+    label: structure_function
+    'sbg:x': 500
+    'sbg:y': 300
   - id: concat_logfiles_applygsm
     in:
       - id: file_list
@@ -200,6 +229,22 @@ steps:
     label: concat_logfiles_solutions
     'sbg:x': 500
     'sbg:y': 500
+  - id: concat_logfiles_structure
+    in:
+      - id: file_list
+        linkMerge: merge_flattened
+        source:
+          - structure_function/log
+          - structure_function/structure_txt
+      - id: file_prefix
+        source: get_targetname/targetname
+        valueFrom: $(self+'_structure')
+    out:
+      - id: output
+    run: ../../steps/concatenate_files.cwl
+    label: concat_logfiles_structure
+    'sbg:x': 950
+    'sbg:y': 500
   - id: get_targetname
     in:
       - id: msin
-- 
GitLab