From acc3a3d522ac7705e82cf715de235eb87c17898d Mon Sep 17 00:00:00 2001
From: AK <kutkin@gmail.com>
Date: Wed, 11 Aug 2021 12:59:11 +0000
Subject: [PATCH] add option to clip model after cleaning

---
 imcal.py  | 10 ++++++----
 imcal.yml |  5 +++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/imcal.py b/imcal.py
index 3571699..613ebc9 100755
--- a/imcal.py
+++ b/imcal.py
@@ -282,15 +282,15 @@ def view_sols(h5param, outname=None):
     # plt.show()
 
 # TODO
-def model_apply_threshold(model, threshold=0.0, out=None):
+def remove_model_components_below_level(model, level=0.0, out=None):
     """
-    Clip the model to be above the given threshold
+    Clip the model to be above the given level
 
     Parameters
     ----------
     model : STR, model file name
         the input model file name
-    threshold : FLOAT, optional
+    level : FLOAT, optional
         the threshold above which the components are kept. The default is 0.0.
     out : STR, optional
         The output model filename. The default is None (the model file will be overwritten).
@@ -299,10 +299,12 @@ def model_apply_threshold(model, threshold=0.0, out=None):
     -------
     None.
     """
+    if level is None:
+        return model
     out = out or model
     logging.warning('Overwriting the model')
     df = pd.read_csv(model, skipinitialspace=True)
-    new = df.query('I>@threshold')
+    new = df.query('I>@level')
     new.to_csv(out, index=False)
     return out
 
diff --git a/imcal.yml b/imcal.yml
index e28bb2a..f4f911d 100644
--- a/imcal.yml
+++ b/imcal.yml
@@ -25,6 +25,7 @@ clean1: # wsclean setup
     automask: 20
     autothresh: 5
     multiscale: False
+    clip_model_level: None # use a float number to clip the model to above this level
     kwstring: '-use-wgridder -parallel-deconvolution 1400' # use this for additional wsclean options, e.g. '-weight uniform -use-idg' 
 
 dical1: # DPPP setup for direction independent calibration
@@ -40,6 +41,7 @@ clean2:
     automask: 10
     autothresh: 5
     multiscale: True
+    clip_model_level: None
     kwstring: '-use-wgridder -parallel-deconvolution 1400 -parallel-gridding 8 -deconvolution-channels 3'
     
 dical2:
@@ -55,6 +57,7 @@ clean3:
     automask: 7
     autothresh: 3.5
     multiscale: True
+    clip_model_level: None
     kwstring: '-use-wgridder -parallel-deconvolution 1400 -parallel-gridding 8 -deconvolution-channels 3'
     
 dical3:
@@ -70,6 +73,7 @@ clean4:
     automask: 4.5
     autothresh: 0.5
     multiscale: True
+    clip_model_level: None
     kwstring: '-use-wgridder -parallel-deconvolution 1400 -parallel-gridding 8 -deconvolution-channels 3 -weight briggs 0.0'
 
 ####################### CLUSTERING #######################
@@ -100,6 +104,7 @@ clean5:
     autothresh: 0.5
     multiscale: True
     fitsmask: 'mask2.fits'
+    clip_model_level: None
     kwstring: '-use-wgridder -parallel-deconvolution 1400 -parallel-gridding 8 -deconvolution-channels 3 -weight briggs 0.0'    
     
 ### END
-- 
GitLab