Skip to content
Snippets Groups Projects
Commit 0292d680 authored by Matthijs van der Wild's avatar Matthijs van der Wild Committed by alex
Browse files

Updated the strategy files with AOflaggers latest versions.

parent 82681dfc
No related branches found
No related tags found
1 merge request!166Updated the strategy files with AOflaggers latest versions.
Pipeline #57437 failed
......@@ -2,18 +2,17 @@
This is the LOFAR strategy. It is almost equal to the
generic "minimal" AOFlagger strategy, version 2020-06-14.
Author: André Offringa
]]--
]]
function execute(input)
--
-- Generic settings
--
local base_threshold = 1.0 -- lower means more sensitive detection
local base_threshold = 1.0 -- lower means more sensitive detection
-- How to flag complex values, options are: phase, amplitude, real, imaginary, complex
local representation = "amplitude"
local iteration_count = 3 -- how many iterations to perform?
local iteration_count = 3 -- how many iterations to perform?
local threshold_factor_step = 2.0 -- How much to increase the sensitivity each iteration?
local frequency_resize_factor = 3.0 -- Amount of "extra" smoothing in frequency direction
local transient_threshold_factor = 1.0 -- decreasing this value makes detection of transient RFI more aggressive
......@@ -27,22 +26,21 @@ function execute(input)
input:clear_mask()
-- For collecting statistics. Note that this is done after clear_mask(),
-- so that the statistics ignore any flags in the input data.
-- so that the statistics ignore any flags in the input data.
local copy_of_input = input:copy()
for ipol,polarization in ipairs(inpPolarizations) do
for ipol, polarization in ipairs(inpPolarizations) do
local data = input:convert_to_polarization(polarization)
data = data:convert_to_complex(representation)
local original_data = data:copy()
for i=1,iteration_count-1 do
local threshold_factor = math.pow(threshold_factor_step, iteration_count-i)
for i = 1, iteration_count - 1 do
local threshold_factor = threshold_factor_step ^ (iteration_count - i)
local sumthr_level = threshold_factor * base_threshold
aoflagger.sumthreshold(data, sumthr_level, sumthr_level*transient_threshold_factor, true, true)
aoflagger.sumthreshold(data, sumthr_level, sumthr_level * transient_threshold_factor, true, true)
-- Do timestep & channel flagging
local chdata = data:copy()
aoflagger.threshold_timestep_rms(data, 3.5)
......@@ -59,21 +57,20 @@ function execute(input)
tmp:set_mask(data)
data = tmp
aoflagger.set_progress((ipol-1)*iteration_count+i, #inpPolarizations*iteration_count )
aoflagger.set_progress((ipol - 1) * iteration_count + i, #inpPolarizations * iteration_count)
end -- end of iterations
aoflagger.sumthreshold(data, base_threshold, base_threshold*transient_threshold_factor, true, true)
aoflagger.sumthreshold(data, base_threshold, base_threshold * transient_threshold_factor, true, true)
if input:is_complex() then
data = data:convert_to_complex("complex")
end
input:set_polarization_data(polarization, data)
aoflagger.set_progress(ipol, #inpPolarizations )
aoflagger.set_progress(ipol, #inpPolarizations)
end -- end of polarization iterations
aoflagger.scale_invariant_rank_operator(input, 0.2, 0.2)
aoflagger.threshold_timestep_rms(input, 4.0)
input:flag_nans()
end
--[[
This is a LBA AOFlagger strategy for combined subbands, version 2021-03-30
Author: André Offringa
]]--
]]
aoflagger.require_min_version("3.1")
function execute(input)
--
-- Generic settings
--
......@@ -17,51 +16,56 @@ function execute(input)
-- { 'I', 'Q' } to flag only on Stokes I and Q
local flag_polarizations = input:get_polarizations()
local base_threshold = 1.2 -- lower means more sensitive detection
local base_threshold = 1.2 -- lower means more sensitive detection
-- How to flag complex values, options are: phase, amplitude, real, imaginary, complex
-- May have multiple values to perform detection multiple times
local flag_representations = { "amplitude" }
local iteration_count = 5 -- how many iterations to perform?
local iteration_count = 5 -- how many iterations to perform?
local threshold_factor_step = 2.0 -- How much to increase the sensitivity each iteration?
-- If the following variable is true, the strategy will consider existing flags
-- as bad data. It will exclude flagged data from detection, and make sure that any existing
-- flags on input will be flagged on output. If set to false, existing flags are ignored.
local exclude_original_flags = true
local transient_threshold_factor = 1.0 -- decreasing this value makes detection of transient RFI more aggressive
--
-- End of generic settings
--
local inpPolarizations = input:get_polarizations()
if(not exclude_original_flags) then
if not exclude_original_flags then
input:clear_mask()
end
-- For collecting statistics. Note that this is done after clear_mask(),
-- so that the statistics ignore any flags in the input data.
-- so that the statistics ignore any flags in the input data.
local copy_of_input = input:copy()
aoflagger.normalize_bandpass(input)
for ipol,polarization in ipairs(flag_polarizations) do
for ipol, polarization in ipairs(flag_polarizations) do
local pol_data = input:convert_to_polarization(polarization)
local original_data
for _,representation in ipairs(flag_representations) do
for _, representation in ipairs(flag_representations) do
data = pol_data:convert_to_complex(representation)
original_data = data:copy()
for i=1,iteration_count-1 do
local threshold_factor = math.pow(threshold_factor_step, iteration_count-i)
for i = 1, iteration_count - 1 do
local threshold_factor = threshold_factor_step ^ (iteration_count - i)
local sumthr_level = threshold_factor * base_threshold
if(exclude_original_flags) then
aoflagger.sumthreshold_masked(data, original_data, sumthr_level, sumthr_level*transient_threshold_factor, true, true)
if exclude_original_flags then
aoflagger.sumthreshold_masked(
data,
original_data,
sumthr_level,
sumthr_level * transient_threshold_factor,
true,
true
)
else
aoflagger.sumthreshold(data, sumthr_level, sumthr_level*transient_threshold_factor, true, true)
aoflagger.sumthreshold(data, sumthr_level, sumthr_level * transient_threshold_factor, true, true)
end
-- Do timestep & channel flagging
......@@ -72,7 +76,7 @@ function execute(input)
-- High pass filtering steps
data:set_visibilities(original_data)
if(exclude_original_flags) then
if exclude_original_flags then
data:join_mask(original_data)
end
......@@ -82,31 +86,40 @@ function execute(input)
-- the following visualize function will add the current result
-- to the list of displayable visualizations.
-- If the script is not running inside rfigui, the call is ignored.
aoflagger.visualize(data, "Fit #"..i, i-1)
aoflagger.visualize(data, "Fit #" .. i, i - 1)
local tmp = original_data - data
tmp:set_mask(data)
data = tmp
aoflagger.visualize(data, "Residual #"..i, i+iteration_count)
aoflagger.set_progress((ipol-1)*iteration_count+i, #flag_polarizations*iteration_count )
aoflagger.visualize(data, "Residual #" .. i, i + iteration_count)
aoflagger.set_progress((ipol - 1) * iteration_count + i, #flag_polarizations * iteration_count)
end -- end of iterations
if(exclude_original_flags) then
aoflagger.sumthreshold_masked(data, original_data, base_threshold, base_threshold*transient_threshold_factor, true, true)
if exclude_original_flags then
aoflagger.sumthreshold_masked(
data,
original_data,
base_threshold,
base_threshold * transient_threshold_factor,
true,
true
)
else
aoflagger.sumthreshold(data, base_threshold, base_threshold*transient_threshold_factor, true, true)
aoflagger.sumthreshold(data, base_threshold, base_threshold * transient_threshold_factor, true, true)
end
end -- end of complex representation iteration
if(exclude_original_flags) then
if exclude_original_flags then
data:join_mask(original_data)
end
-- Helper function used below
function contains(arr, val)
for _,v in ipairs(arr) do
if v == val then return true end
for _, v in ipairs(arr) do
if v == val then
return true
end
end
return false
end
......@@ -120,11 +133,11 @@ function execute(input)
input:join_mask(data)
end
aoflagger.visualize(data, "Residual #"..iteration_count, 2*iteration_count)
aoflagger.set_progress(ipol, #flag_polarizations )
aoflagger.visualize(data, "Residual #" .. iteration_count, 2 * iteration_count)
aoflagger.set_progress(ipol, #flag_polarizations)
end -- end of polarization iterations
if(exclude_original_flags) then
if exclude_original_flags then
aoflagger.scale_invariant_rank_operator_masked(input, copy_of_input, 0.2, 0.2)
else
aoflagger.scale_invariant_rank_operator(input, 0.2, 0.2)
......@@ -140,4 +153,3 @@ function execute(input)
end
input:flag_nans()
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment