diff --git a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/antennaflagcountplot.h b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/antennaflagcountplot.h index ec0419a08ba33e7278a4fcf64441c2b2ff3d9107..ce4718d18a136bbdba721f7fe46344492a8ea946 100644 --- a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/antennaflagcountplot.h +++ b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/antennaflagcountplot.h @@ -39,6 +39,7 @@ class AntennaFlagCountPlot{ void Report(); private: void WriteCounts(); + std::string formatPercentage(double percentage); struct MapItem { MapItem() : name(), autoCount(0), autoTotal(0), crossCount(0), crossTotal(0) diff --git a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/frequencyflagcountplot.h b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/frequencyflagcountplot.h index 8fb011628a85583fb6aa5dc6e031fcb552d476b1..d649e4912efc9826af1878347d28a5d26c283fde 100644 --- a/CEP/DP3/AOFlagger/include/AOFlagger/rfi/frequencyflagcountplot.h +++ b/CEP/DP3/AOFlagger/include/AOFlagger/rfi/frequencyflagcountplot.h @@ -36,11 +36,20 @@ class FrequencyFlagCountPlot{ void WriteCounts(); bool HasData() { return !_counts.empty(); } void MakePlot(); + void Report(); private: struct MapItem { MapItem() : count(0), total(0) { } long long count, total; }; + std::string formatPercentage(double percentage); + std::string formatFrequency(double frequencyHz); + void formatToThreeDigits(std::stringstream &stream, int number) + { + if(number < 100) stream << '0'; + if(number < 10) stream << '0'; + stream << number; + } // In lofar, the first channel of every subband is flagged, because it overlaps with // the previous subband. bool _ignoreFirstChannel; diff --git a/CEP/DP3/AOFlagger/include/AOFlagger/util/aologger.h b/CEP/DP3/AOFlagger/include/AOFlagger/util/aologger.h index d27db9df0f7f8afa2967e79ea7c18b897eb13f55..e7e30c8f1ac5fb21341b9eb6f300f4ca0022c7fc 100644 --- a/CEP/DP3/AOFlagger/include/AOFlagger/util/aologger.h +++ b/CEP/DP3/AOFlagger/include/AOFlagger/util/aologger.h @@ -36,6 +36,11 @@ class AOLogger { public: LogWriter() : _useLogger(false) { } + ~LogWriter() + { + if(_useLogger && _buffer.str().size() != 0) + Log(_buffer.str()); + } LogWriter &operator<<(const std::string &str) { if(_useLogger) diff --git a/CEP/DP3/AOFlagger/src/rfi/antennaflagcountplot.cpp b/CEP/DP3/AOFlagger/src/rfi/antennaflagcountplot.cpp index 591ea9fb3d43ee708d9fbc5f2b4d2020724db155..dab04bb7e3d4d8457a5ecb19decd23b93ce223da 100644 --- a/CEP/DP3/AOFlagger/src/rfi/antennaflagcountplot.cpp +++ b/CEP/DP3/AOFlagger/src/rfi/antennaflagcountplot.cpp @@ -112,7 +112,25 @@ void AntennaFlagCountPlot::Report() { for(std::map<int, MapItem>::const_iterator i=_counts.begin();i!=_counts.end();++i) { - AOLogger::Info << "Flagged in autocorrelations of antenna " << i->second.name << ": " << (100.0L * (long double) i->second.autoCount / (long double) i->second.autoTotal) - << "%\nFlagged in cross correlations with antenna " << i->second.name << ": " << (100.0L * (long double) i->second.crossCount / (long double) i->second.crossTotal) << "%\n"; + AOLogger::Info + << "Flagged in autocorrelations of antenna " + << i->second.name << ": " + << formatPercentage(100.0L * (long double) i->second.autoCount / (long double) i->second.autoTotal) + << "%\nFlagged in cross correlations with antenna " + << i->second.name << ": " + << formatPercentage(100.0L * (long double) i->second.crossCount / (long double) i->second.crossTotal) + << "%\n"; } } + +std::string AntennaFlagCountPlot::formatPercentage(double percentage) +{ + std::stringstream s; + if(percentage >= 1.0) + s << round(percentage*10.0)/10.0; + else if(percentage >= 0.1) + s << round(percentage*100.0)/100.0; + else + s << round(percentage*1000.0)/1000.0; + return s.str(); +} diff --git a/CEP/DP3/AOFlagger/src/rfi/frequencyflagcountplot.cpp b/CEP/DP3/AOFlagger/src/rfi/frequencyflagcountplot.cpp index 6eba17a303fac5b0f9a3959aba6a8b3fc0f80ddc..0a2e51d138b2f9e4a96c86836603f97fc833e504 100644 --- a/CEP/DP3/AOFlagger/src/rfi/frequencyflagcountplot.cpp +++ b/CEP/DP3/AOFlagger/src/rfi/frequencyflagcountplot.cpp @@ -22,6 +22,7 @@ #include <fstream> #include <iomanip> +#include <AOFlagger/util/aologger.h> #include <AOFlagger/util/plot.h> #include <AOFlagger/msio/timefrequencydata.h> @@ -78,3 +79,63 @@ void FrequencyFlagCountPlot::MakePlot() plot.Close(); plot.Show(); } + +void FrequencyFlagCountPlot::Report() +{ + size_t index = _ignoreFirstChannel ? 1 : 0; + for(std::map<double, struct MapItem>::const_iterator i=_counts.begin();i!=_counts.end();++i) + { + AOLogger::Info + << "RFI in channel " << index << " (" + << formatFrequency(i->first) << " Hz):" + << formatPercentage(100.0L * (long double) i->second.count / (long double) i->second.total) + << "%\n"; + ++index; + } +} + +std::string FrequencyFlagCountPlot::formatPercentage(double percentage) +{ + std::stringstream s; + if(percentage >= 1.0) + s << round(percentage*10.0)/10.0; + else if(percentage >= 0.1) + s << round(percentage*100.0)/100.0; + else + s << round(percentage*1000.0)/1000.0; + return s.str(); +} + +std::string FrequencyFlagCountPlot::formatFrequency(double frequencyHz) +{ + std::stringstream s; + bool commaPlaced = false; + if(frequencyHz > 1000000000.0) + { + s << (int) floor(frequencyHz / 1000000000.0) << ','; + commaPlaced = true; + } + if(frequencyHz > 1000000.0) + { + if(commaPlaced) + formatToThreeDigits(s, (int) floor(fmod(frequencyHz / 1000000.0, 1000.0))); + else + s << (int) floor(fmod(frequencyHz / 1000000.0, 1000.0)); + s << ','; + commaPlaced = true; + } + if(frequencyHz > 1000.0) + { + if(commaPlaced) + formatToThreeDigits(s, (int) floor(fmod(frequencyHz / 1000.0, 1000.0))); + else + s << (int) floor(fmod(frequencyHz / 1000.0, 1000.0)); + s << ','; + commaPlaced = true; + } + if(commaPlaced) + formatToThreeDigits(s, (int) floor(fmod(frequencyHz, 1000.0))); + else + s << (int) floor(fmod(frequencyHz, 1000.0)); + return s.str(); +} diff --git a/CEP/DP3/AOFlagger/src/rfi/strategy/strategy.cpp b/CEP/DP3/AOFlagger/src/rfi/strategy/strategy.cpp index 289357d4b2f635745a1f57923c8a5408c95afe13..a61711576c0e8dc5c6712ef33056de1681416010 100644 --- a/CEP/DP3/AOFlagger/src/rfi/strategy/strategy.cpp +++ b/CEP/DP3/AOFlagger/src/rfi/strategy/strategy.cpp @@ -185,9 +185,13 @@ namespace rfiStrategy { feBaseBlock->Add(new WriteFlagsAction()); - PlotAction *plotAction = new PlotAction(); - plotAction->SetPlotKind(PlotAction::AntennaFlagCountPlot); - feBaseBlock->Add(plotAction); + PlotAction *antennaPlotAction = new PlotAction(); + antennaPlotAction->SetPlotKind(PlotAction::AntennaFlagCountPlot); + feBaseBlock->Add(antennaPlotAction); + + PlotAction *frequencyPlotAction = new PlotAction(); + frequencyPlotAction->SetPlotKind(PlotAction::FrequencyFlagCountPlot); + feBaseBlock->Add(frequencyPlotAction); BaselineSelectionAction *baselineSelection = new BaselineSelectionAction(); baselineSelection->SetPreparationStep(false); @@ -203,9 +207,13 @@ namespace rfiStrategy { feBaseBlock->Add(new WriteFlagsAction()); - PlotAction *plotAction = new PlotAction(); - plotAction->SetPlotKind(PlotAction::AntennaFlagCountPlot); - feBaseBlock->Add(plotAction); + PlotAction *antennaPlotAction = new PlotAction(); + antennaPlotAction->SetPlotKind(PlotAction::AntennaFlagCountPlot); + feBaseBlock->Add(antennaPlotAction); + + PlotAction *frequencyPlotAction = new PlotAction(); + frequencyPlotAction->SetPlotKind(PlotAction::FrequencyFlagCountPlot); + feBaseBlock->Add(frequencyPlotAction); BaselineSelectionAction *baselineSelection = new BaselineSelectionAction(); baselineSelection->SetPreparationStep(false); @@ -221,9 +229,13 @@ namespace rfiStrategy { feBaseBlock->Add(new WriteFlagsAction()); - PlotAction *plotAction = new PlotAction(); - plotAction->SetPlotKind(PlotAction::AntennaFlagCountPlot); - feBaseBlock->Add(plotAction); + PlotAction *antennaPlotAction = new PlotAction(); + antennaPlotAction->SetPlotKind(PlotAction::AntennaFlagCountPlot); + feBaseBlock->Add(antennaPlotAction); + + PlotAction *frequencyPlotAction = new PlotAction(); + frequencyPlotAction->SetPlotKind(PlotAction::FrequencyFlagCountPlot); + feBaseBlock->Add(frequencyPlotAction); BaselineSelectionAction *baselineSelection = new BaselineSelectionAction(); baselineSelection->SetPreparationStep(false); diff --git a/CEP/DP3/AOFlagger/src/rficonsole.cpp b/CEP/DP3/AOFlagger/src/rficonsole.cpp index 8a6d2ead44d4e78789f7a98bdfd471950f95f7db..0651a2c6b422eb6120f79475bf522f8470458b22 100644 --- a/CEP/DP3/AOFlagger/src/rficonsole.cpp +++ b/CEP/DP3/AOFlagger/src/rficonsole.cpp @@ -206,6 +206,8 @@ int main(int argc, char **argv) overallStrategy.FinishAll(); set->AntennaFlagCountPlot()->Report(); + set->FrequencyFlagCountPlot()->Report(); + delete set->AntennaFlagCountPlot(); delete set->FrequencyFlagCountPlot(); delete set->TimeFlagCountPlot();