From 72bb624b2aa1e5dee2fba545551b7a81d33f7b14 Mon Sep 17 00:00:00 2001
From: Alexander Drabent <alex@tls-tautenburg.de>
Date: Fri, 28 May 2021 11:31:39 +0200
Subject: [PATCH] bugfix missing frequencies

---
 lofar-cwl/steps/applybeam.cwl              |  2 +-
 lofar-cwl/steps/check_ateam_separation.cwl | 42 ----------------------
 lofar-cwl/steps/dpppconcat.cwl             | 15 +++++---
 steps/check_ateam_separation.cwl           |  5 ++-
 steps/filter_ms_group.cwl                  | 32 +++++++++++++----
 subworkflow/concat.cwl                     |  5 ++-
 workflows/prefactor_calibrator/prep.cwl    |  2 +-
 workflows/prefactor_target/prep.cwl        |  2 +-
 8 files changed, 46 insertions(+), 59 deletions(-)
 delete mode 100755 lofar-cwl/steps/check_ateam_separation.cwl

diff --git a/lofar-cwl/steps/applybeam.cwl b/lofar-cwl/steps/applybeam.cwl
index 099f62ce..a69a628f 100644
--- a/lofar-cwl/steps/applybeam.cwl
+++ b/lofar-cwl/steps/applybeam.cwl
@@ -2,7 +2,7 @@ class: CommandLineTool
 cwlVersion: v1.0
 $namespaces:
   sbg: 'https://www.sevenbridges.com/'
-id: applycal
+id: applybeam
 baseCommand:
   - DPPP
 inputs:
diff --git a/lofar-cwl/steps/check_ateam_separation.cwl b/lofar-cwl/steps/check_ateam_separation.cwl
deleted file mode 100755
index c8d801c9..00000000
--- a/lofar-cwl/steps/check_ateam_separation.cwl
+++ /dev/null
@@ -1,42 +0,0 @@
-class: CommandLineTool
-cwlVersion: v1.0
-id: check_ateam_separation
-baseCommand:
-  - python3
-  - /usr/local/bin/check_Ateam_separation.py
-inputs:
-  - id: ms
-    type:
-      - Directory
-      - type: array
-        items: Directory
-    inputBinding:
-      position: 0
-    doc: Input measurement set
-  - default: Ateam_separation.png
-    id: output_image_name
-    type: string?
-    inputBinding:
-      position: 2
-      prefix: '--outputimage'
-  - id: min_separation
-    type: int
-    inputBinding:
-      position: 1
-      prefix: '--min_separation'
-outputs:
-  - id: output_imag
-    doc: Output image
-    type: File?
-    outputBinding:
-      glob: $(inputs.output_image_name)
-  - id: logfile
-    type: File?
-    outputBinding:
-      glob: Ateam_separation.log
-label: check_Ateam_separation
-hints:
-  - class: DockerRequirement
-    dockerPull: lofareosc/prefactor:HBAcalibrator
-  - class: InlineJavascriptRequirement
-stdout: Ateam_separation.log
diff --git a/lofar-cwl/steps/dpppconcat.cwl b/lofar-cwl/steps/dpppconcat.cwl
index 34b78840..0fca5fbf 100644
--- a/lofar-cwl/steps/dpppconcat.cwl
+++ b/lofar-cwl/steps/dpppconcat.cwl
@@ -8,13 +8,16 @@ baseCommand:
 inputs:
   - id: msin
     type: 'Directory[]'
+    doc: Input Measurement Set
+  - id: msin_fname
+    doc: Input Measurement Set string (including dummy.ms)
+    type: 'string[]'
     inputBinding:
       position: 0
       prefix: msin=
       separate: false
       itemSeparator: ','
-      valueFrom: $(concatenate_path(self))
-    doc: Input Measurement Set
+      valueFrom: "[$(self.join(','))]"
   - id: msout_name
     type: string
     inputBinding:
@@ -87,7 +90,7 @@ inputs:
   - id: missingdata
     type: boolean
     inputBinding:
-      prefix: msout.missingdata=True
+      prefix: msin.missingdata=True
       separate: false
       shellQuote: false
       position: 0
@@ -127,7 +130,7 @@ outputs:
       glob: concat*.log
 arguments:
   - 'steps=[filter,avg,count]'
-  - msout.orderms=False
+  - msin.orderms=False
   - avg.type=average
 requirements:
   - class: ShellCommandRequirement
@@ -137,5 +140,9 @@ requirements:
 hints:
   - class: DockerRequirement
     dockerPull: 'lofareosc/prefactor:HBAcalibrator'
+  - class: InitialWorkDirRequirement
+    listing:
+      - entry: $(inputs.msin)
+        writable: false
 stdout: concat.log
 stderr: concat_err.log
diff --git a/steps/check_ateam_separation.cwl b/steps/check_ateam_separation.cwl
index 516beb61..00275869 100644
--- a/steps/check_ateam_separation.cwl
+++ b/steps/check_ateam_separation.cwl
@@ -1,11 +1,10 @@
 class: CommandLineTool
 cwlVersion: v1.0
-$namespaces:
-  sbg: 'https://www.sevenbridges.com/'
 id: check_ateam_separation
 baseCommand:
   - python3
-  - /usr/local/bin/check_Ateam_separation.py
+  - -m
+  - check_Ateam_separation
 inputs:
   - id: ms
     type:
diff --git a/steps/filter_ms_group.cwl b/steps/filter_ms_group.cwl
index d51dcf69..e09eec16 100644
--- a/steps/filter_ms_group.cwl
+++ b/steps/filter_ms_group.cwl
@@ -22,8 +22,14 @@ outputs:
     type: Directory[]
     outputBinding:
       loadContents: true
-      glob: selected_ms.json
+      glob: 'selected_ms.json'
       outputEval: '$(JSON.parse(self[0].contents))'
+  - id: selected_ms
+    type: string[]
+    outputBinding:
+        loadContents: true
+        glob: 'out.json'
+        outputEval: $(JSON.parse(self[0].contents).selected_ms)
 label: filter_ms_group
 
 requirements:
@@ -39,20 +45,34 @@ requirements:
         group_id = "$(inputs.group_id)"
         json_file = sys.argv[1]
         ms_list = sys.argv[2:]
-        
+
         ms_by_name = { ms.split(os.path.sep)[-1]:
                        {'class':'Directory', 'path': ms} for ms in ms_list}
-        
+                       
         output_file = 'selected_ms.json'
         
         with open(json_file, 'r') as f_stream:
             selected_ms = json.load(f_stream)[group_id]
-        print(selected_ms, ms_by_name)
-        selected_ms = [ms_by_name[os.path.basename(ms_name)] for ms_name in selected_ms]
+            
+        selected_ms = [os.path.basename(ms_name) for ms_name in selected_ms]
+        cwl_output  = {'selected_ms': selected_ms}
+
+        with open('./out.json', 'w') as fp:
+            json.dump(cwl_output, fp)
+            
+        selected_ms = [ms_by_name[ms_name] for ms_name in selected_ms if ms_name != 'dummy.ms']
             
         
         with open(output_file, 'w') as f_stream:
             json.dump(selected_ms, f_stream)
-               
+              
         
+
+hints:
+  - class: InitialWorkDirRequirement
+    listing:
+      - entry: $(inputs.measurement_sets)
+        writable: true
     
+stdout: filter_ms_by_group.log
+stderr: filter_ms_by_group_err.log
\ No newline at end of file
diff --git a/subworkflow/concat.cwl b/subworkflow/concat.cwl
index c1c00803..d2224d34 100644
--- a/subworkflow/concat.cwl
+++ b/subworkflow/concat.cwl
@@ -58,6 +58,7 @@ steps:
           - msin
     out:
       - id: output
+      - id: selected_ms
     run: ../steps/filter_ms_group.cwl
     label: filter_ms_group
     'sbg:x': -500
@@ -66,7 +67,9 @@ steps:
     in:
       - id: msin
         source:
-          - filter_ms_group/output
+          - msin
+      - id: msin_fname
+        source: filter_ms_group/selected_ms
       - id: msout_name
         source: group_id
       - id: msin_datacolumn
diff --git a/workflows/prefactor_calibrator/prep.cwl b/workflows/prefactor_calibrator/prep.cwl
index 57ff28b8..4d40b75b 100644
--- a/workflows/prefactor_calibrator/prep.cwl
+++ b/workflows/prefactor_calibrator/prep.cwl
@@ -311,7 +311,7 @@ steps:
     out:
       - id: output_imag
       - id: logfile
-    run: ../../lofar-cwl/steps/check_ateam_separation.cwl
+    run: ../../steps/check_ateam_separation.cwl
     label: check_Ateam_separation
     'sbg:x': 254.234375
     'sbg:y': 1440
diff --git a/workflows/prefactor_target/prep.cwl b/workflows/prefactor_target/prep.cwl
index a068460a..73a796aa 100644
--- a/workflows/prefactor_target/prep.cwl
+++ b/workflows/prefactor_target/prep.cwl
@@ -225,7 +225,7 @@ steps:
     out:
       - id: output_imag
       - id: logfile
-    run: ../../lofar-cwl/steps/check_ateam_separation.cwl
+    run: ../../steps/check_ateam_separation.cwl
     label: check_Ateam_separation
     'sbg:x': -500
     'sbg:y': -300
-- 
GitLab