From 2b2a2007ce495e4f656fa7126d9070dba41597e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Offringa?= <offringa@astron.nl>
Date: Thu, 30 Sep 2010 08:47:36 +0000
Subject: [PATCH] Bug 1491: Improved time convolution

---
 .../include/AOFlagger/rfi/strategy/action.h   |  2 ++
 .../strategy/foreachcomplexcomponentaction.h  |  4 ++-
 .../rfi/strategy/timeconvolutionaction.h      | 27 ++++++++++++++-----
 CEP/DP3/AOFlagger/src/gui/mswindow.cpp        |  2 +-
 4 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/action.h b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/action.h
index 08b0c1d3fc1..1f2bc547cca 100644
--- a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/action.h
+++ b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/action.h
@@ -35,6 +35,7 @@ namespace rfiStrategy {
 		CombineFlagResultsType,
 		CutAreaActionType,
 		ForEachBaselineActionType,
+		ForEachComplexComponentActionType,
 		ForEachMSActionType,
 		ForEachPolarisationBlockType,
 		FrequencySelectionActionType,
@@ -51,6 +52,7 @@ namespace rfiStrategy {
 		StrategyType,
 		SVDActionType,
 		ThresholdActionType,
+		TimeConvolutionActionType,
 		TimeSelectionActionType,
 		WriteFlagsActionType
 	};
diff --git a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/foreachcomplexcomponentaction.h b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/foreachcomplexcomponentaction.h
index 7b98905c25a..27e7793fdae 100644
--- a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/foreachcomplexcomponentaction.h
+++ b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/foreachcomplexcomponentaction.h
@@ -23,6 +23,8 @@
 #include "artifactset.h"
 #include "actionblock.h"
 
+#include <AOFlagger/rfi/strategy/action.h>
+
 namespace rfiStrategy {
 
 	class ForEachComplexComponentAction : public ActionBlock
@@ -35,7 +37,7 @@ namespace rfiStrategy {
 			{
 				return "For each complex component";
 			}
-			virtual ActionType Type() const { return AdapterType; }
+			virtual ActionType Type() const { return ForEachComplexComponentActionType; }
 			virtual void Perform(ArtifactSet &artifacts, class ProgressListener &listener)
 			{
 				size_t taskCount = 0;
diff --git a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/timeconvolutionaction.h b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/timeconvolutionaction.h
index 4190894a383..214457a8efd 100644
--- a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/timeconvolutionaction.h
+++ b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/strategy/timeconvolutionaction.h
@@ -23,6 +23,8 @@
 #include "artifactset.h"
 #include "actionblock.h"
 
+#include <AOFlagger/rfi/strategy/action.h>
+
 #include <AOFlagger/rfi/thresholdtools.h>
 
 namespace rfiStrategy {
@@ -37,20 +39,31 @@ namespace rfiStrategy {
 			{
 				return "Time convolution";
 			}
-			virtual ActionType Type() const { return AdapterType; }
+			virtual ActionType Type() const { return TimeConvolutionActionType; }
 			virtual void Perform(ArtifactSet &artifacts, class ProgressListener &)
 			{
 				TimeFrequencyData data = artifacts.ContaminatedData();
 				Image2DCPtr image = data.GetSingleImage();
-				num_t *row = new num_t[image->Width()];
+				num_t *row = new num_t[image->Width()*3];
 				Image2DPtr newImage = Image2D::CreateEmptyImagePtr(image->Width(), image->Height());
+				unsigned width = image->Width();
+				num_t sign;
+				if(data.PhaseRepresentation() == TimeFrequencyData::RealPart)
+					sign = 1.0;
+				else if(data.PhaseRepresentation() == TimeFrequencyData::ImaginaryPart)
+					sign = -1.0;
+				else
+					throw BadUsageException("Data is not real or imaginary");
 				for(unsigned y=0;y<image->Height();++y)
 				{
-					for(unsigned x=0;x<image->Width();++x)
-						row[x] = image->Value(x, y);
-					ThresholdTools::OneDimensionalSincConvolution(row, image->Width(), _sincSize);
-					for(unsigned x=0;x<image->Width();++x)
-						newImage->SetValue(x, y, row[x]);
+					for(unsigned x=0;x<width;++x) {
+						row[x] = sign * image->Value(x, y);
+						row[x+width] = image->Value(x, y);
+						row[x+2*width] = sign * image->Value(x, y);
+					}
+					ThresholdTools::OneDimensionalSincConvolution(row, width*3, _sincSize);
+					for(unsigned x=0;x<width;++x)
+						newImage->SetValue(x, y, row[x+width]);
 				}
 				delete[] row;
 				
diff --git a/CEP/DP3/AOFlagger/src/gui/mswindow.cpp b/CEP/DP3/AOFlagger/src/gui/mswindow.cpp
index 9a32ffd69e0..f9be3500000 100644
--- a/CEP/DP3/AOFlagger/src/gui/mswindow.cpp
+++ b/CEP/DP3/AOFlagger/src/gui/mswindow.cpp
@@ -1382,7 +1382,7 @@ void MSWindow::onSimulateCorrelation()
 void MSWindow::onSimulateDoubledBaselineCorrelation()
 {
 	Model model;
-	model.loadUrsaMajor();
+	//model.loadUrsaMajor();
 	model.loadUrsaMajorDistortingSource();
 
 	WSRTObservatorium wsrtObservatorium(0,5);
-- 
GitLab