From 1d7b892ef4457c23b03e878490781714615981b9 Mon Sep 17 00:00:00 2001
From: mancini <mancini@astron.nl>
Date: Fri, 10 Jan 2020 14:27:50 +0100
Subject: [PATCH] Add LoSoTo Flag step

Former-commit-id: 7bc9bb09a5cfab206a38ce6b38d8e12910467b9f
---
 .gitlab-ci.yml             |   6 ++-
 steps/LoSoTo.Flag.cwl      | 105 +++++++++++++++++++++++++++++++++++++
 test_jobs/losoto_flag.json |   6 +++
 3 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 steps/LoSoTo.Flag.cwl
 create mode 100644 test_jobs/losoto_flag.json

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 78e53fe0..e82264fd 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -86,7 +86,11 @@ losoto_plot:
   allow_failure: true
   script:
     - cwl-runner --no-container steps/LoSoTo.Plot.cwl test_jobs/losoto_plot.json
-
+losoto_flag:
+  stage: test_steps
+  allow_failure: true
+  script:
+    - cwl-runner --no-container steps/LoSoTo.Flag.cwl test_jobs/losoto_flag.json
 losoto_norm:
   stage: test_steps
   allow_failure: true
diff --git a/steps/LoSoTo.Flag.cwl b/steps/LoSoTo.Flag.cwl
new file mode 100644
index 00000000..30dbd164
--- /dev/null
+++ b/steps/LoSoTo.Flag.cwl
@@ -0,0 +1,105 @@
+#!/usr/bin/env cwl-runner
+
+class: CommandLineTool
+cwlVersion: v1.0
+id: losoto_flag
+
+$namespaces:
+  lofar: https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl
+doc: |
+  This operation for LoSoTo implement a flagging procedure
+  WEIGHT: compliant
+
+
+requirements:
+  InlineJavascriptRequirement:
+    expressionLib:
+      - { $include: utils.js}
+  InitialWorkDirRequirement:
+    listing:
+      - entryname: 'parset.config'
+        entry: $(get_losoto_config('FLAG').join('\n'))
+
+      - entryname: $(inputs.input_h5parm.basename)
+        entry: $(inputs.input_h5parm)
+        writable: true
+
+baseCommand: "losoto"
+
+arguments:
+  - $(inputs.input_h5parm.basename)
+  - parset.config
+
+hints:
+  DockerRequirement:
+    dockerPull: lofareosc/lofar-pipeline-ci:latest
+
+inputs:
+  - id: input_h5parm
+    type: File
+    format: lofar:#H5Parm
+  - id: soltab
+    type: string
+    doc: "Solution table"
+  - id: axesToFlag
+    type: string[]
+    doc: Axes along which to smooth+find outlier (e.g. ['time', 'freq']), max 2 values.
+  - id: order
+    type: int[]
+    doc: |
+      Order of the function fitted during detrending.
+      Array must have same size of axesToFlag.
+      If mode=smooth these are the window of the running median (0=all axis).
+  - id: maxCycles
+    type: int?
+    doc: Max number of independent flagging cycles, by default 5.
+  - id: maxRms
+    type: float?
+    doc: Rms to clip outliers, by default 5.
+  - id: maxRmsNoise
+    type: float?
+    doc: |
+      Do a running rms and then flag those regions that have a rms higher
+      than MaxRmsNoise*rms_of_rmses, by default 0 (ignored).
+  - id: fixRms
+    type: float?
+    doc: Instead of calculating rms use this value, by default 0 (ignored).
+  - id: fixRmsNoise
+    type: float?
+    doc: |
+      Instead of calculating rms of the rmses use this value
+      (it will not be multiplied by the MaxRmsNoise), by default 0 (ignored).
+  - id: windowNoise
+    type: int?
+    doc: Window size for the running rms, by default 11.
+
+  - id: replace
+    type: boolean?
+    doc: |
+      Replace bad values with the interpolated ones,
+      instead of flagging them. By default False.
+  - id: preflagzeros
+    type: boolean?
+    doc:
+      Flag zeros/ones (bad solutions in BBS/DPPP).
+      They should be flagged at import time. By default False.
+  - id: mode
+    type: string?
+    doc: |
+      Detrending/fitting algorithm: smooth / poly / spline.
+      By default smooth.
+  - id: refAnt
+    type: string?
+    doc: Reference antenna, by default None.
+  - id: ncpu
+    type: int?
+    doc: Number of cpu to use, by default all available.
+
+outputs:
+  - id: output_h5parm
+    type: File
+    format: lofar:#H5Parm
+    outputBinding:
+      glob: $(inputs.input_h5parm.basename)
+$schema:
+  - https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl
diff --git a/test_jobs/losoto_flag.json b/test_jobs/losoto_flag.json
new file mode 100644
index 00000000..f1ce6b2f
--- /dev/null
+++ b/test_jobs/losoto_flag.json
@@ -0,0 +1,6 @@
+{
+  "input_h5parm": {"class": "File", "path": "/data/example.h5", "format": "lofar:#H5Parm"},
+  "soltab":  "sol000/phase000",
+  "axesToFlag": ["time"],
+  "order": [0]
+}
-- 
GitLab