From 7365542dd1cfbd645796c1a5cd573ac8740f51ba Mon Sep 17 00:00:00 2001
From: mancini <mancini@astron.nl>
Date: Tue, 14 Jan 2020 10:11:46 +0100
Subject: [PATCH] Add Smooth step

Former-commit-id: 382cea5b2a969c4c6e530a32cf2dc0b1de5a79da
---
 .gitlab-ci.yml               |  6 +++
 steps/LoSoTo.Smooth.cwl      | 86 ++++++++++++++++++++++++++++++++++++
 test_jobs/losoto_smooth.json |  6 +++
 3 files changed, 98 insertions(+)
 create mode 100644 steps/LoSoTo.Smooth.cwl
 create mode 100644 test_jobs/losoto_smooth.json

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d31f3ae7..ba19298f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -109,6 +109,12 @@ losoto_reset:
   script:
     - cwl-runner --no-container steps/LoSoTo.Reset.cwl test_jobs/losoto_reset.json
 
+losoto_smooth:
+  stage: test_steps
+  allow_failure: true
+  script:
+    - cwl-runner --no-container steps/LoSoTo.Smooth.cwl test_jobs/losoto_smooth.json
+
 losoto_clip:
   stage: test_steps
   allow_failure: true
diff --git a/steps/LoSoTo.Smooth.cwl b/steps/LoSoTo.Smooth.cwl
new file mode 100644
index 00000000..cdf67851
--- /dev/null
+++ b/steps/LoSoTo.Smooth.cwl
@@ -0,0 +1,86 @@
+#!/usr/bin/env cwl-runner
+
+class: CommandLineTool
+cwlVersion: v1.0
+id: losoto_smooth
+
+$namespaces:
+  lofar: https://git.astron.nl/eosc/ontologies/raw/master/schema/lofar.owl
+doc: |
+  A smoothing function: running-median on an arbitrary number of axes, running
+  polyfit and Savitzky-Golay on one axis, or set all solutions to the
+  mean/median value.
+  WEIGHT: flag ready.
+
+
+
+requirements:
+  InlineJavascriptRequirement:
+    expressionLib:
+      - { $include: utils.js}
+  InitialWorkDirRequirement:
+    listing:
+      - entryname: 'parset.config'
+        entry: $(get_losoto_config('SMOOTH').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: axesToSmooth
+    type: string[]
+    doc: Axes used to compute the smoothing function.
+  - id: size
+    type: int[]?
+    doc: |
+      Window size for the runningmedian, savitzky-golay, and runningpoly (array
+      of same size of axesToSmooth), by default [].
+  - id: mode
+    default: 'runningmedian'
+    type:
+      type: enum
+      symbols:
+        - 'runningmedian'
+        - 'runningpoly'
+        - 'savitzky-golay'
+        - 'mean'
+        - 'median'
+    doc: Runningmedian or runningpoly or Savitzky-Golay or mean or median (these last two values set all the solutions to the mean/median), by default "runningmedian".
+  - id: degree
+    type: int?
+    doc: Degrees of the polynomia for the runningpoly or savitzky-golay modes, by default 1.
+  - id: replace
+    type: boolean?
+    doc: Flagged data are replaced with smoothed value and unflagged, by default False.
+  - id: log
+    type: boolean?
+    doc: clip is done in log10 space, by default False
+  - id: refAnt
+    type: string?
+    doc: Reference antenna for phases. By default None.
+
+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_smooth.json b/test_jobs/losoto_smooth.json
new file mode 100644
index 00000000..00672d3c
--- /dev/null
+++ b/test_jobs/losoto_smooth.json
@@ -0,0 +1,6 @@
+{
+  "input_h5parm": {"class": "File", "path": "/data/example.h5", "format": "lofar:#H5Parm"},
+  "soltab":  "sol000/phase000",
+  "axesToSmooth": ["time"],
+  "mode": "median"
+}
-- 
GitLab