void RFIGuiController::PlotPowerTime() { if(IsImageLoaded()) { Plot2D &plot = _plotManager->NewPlot2D("Power over time"); plot.SetLogarithmicYAxis(true); TimeFrequencyData activeData = ActiveData(); Image2DCPtr image = activeData.GetSingleImage(); Mask2DPtr mask = Mask2D::CreateSetMaskPtr<false>(image->Width(), image->Height()); Plot2DPointSet &totalPlot = plot.StartLine("Total"); RFIPlots::MakePowerTimePlot(totalPlot, image, mask, MetaData()); mask = Mask2D::CreateCopy(activeData.GetSingleMask()); if(!mask->AllFalse()) { Plot2DPointSet &uncontaminatedPlot = plot.StartLine("Uncontaminated"); RFIPlots::MakePowerTimePlot(uncontaminatedPlot, image, mask, MetaData()); mask->Invert(); Plot2DPointSet &rfiPlot = plot.StartLine("RFI"); RFIPlots::MakePowerTimePlot(rfiPlot, image, mask, MetaData()); } _plotManager->Update(); } }
void RFIGuiController::plotMeanSpectrum(bool weight) { if(IsImageLoaded()) { std::string title = weight ? "Sum spectrum" : "Mean spectrum"; Plot2D &plot = _plotManager->NewPlot2D(title); TimeFrequencyData data = ActiveData(); Mask2DCPtr mask = Mask2D::CreateSetMaskPtr<false>(data.ImageWidth(), data.ImageHeight()); Plot2DPointSet &beforeSet = plot.StartLine("Without flagging"); if(weight) RFIPlots::MakeMeanSpectrumPlot<true>(beforeSet, data, mask, MetaData()); else RFIPlots::MakeMeanSpectrumPlot<false>(beforeSet, data, mask, MetaData()); mask = Mask2D::CreateCopy(data.GetSingleMask()); if(!mask->AllFalse()) { Plot2DPointSet &afterSet = plot.StartLine("Flagged"); if(weight) RFIPlots::MakeMeanSpectrumPlot<true>(afterSet, data, mask, MetaData()); else RFIPlots::MakeMeanSpectrumPlot<false>(afterSet, data, mask, MetaData()); } _plotManager->Update(); } }
void RFIGuiController::PlotPowerRMS() { if(IsImageLoaded()) { Plot2D &plot = _plotManager->NewPlot2D("Spectrum RMS"); plot.SetLogarithmicYAxis(true); TimeFrequencyData activeData = ActiveData(); Image2DCPtr image = activeData.GetSingleImage(); Mask2DPtr mask = Mask2D::CreateSetMaskPtr<false>(image->Width(), image->Height()); Plot2DPointSet &beforeSet = plot.StartLine("Before"); RFIPlots::MakeRMSSpectrumPlot(beforeSet, image, mask); mask = Mask2D::CreateCopy(activeData.GetSingleMask()); if(!mask->AllFalse()) { Plot2DPointSet &afterSet = plot.StartLine("After"); RFIPlots::MakeRMSSpectrumPlot(afterSet, image, mask); //mask->Invert(); //Plot2DPointSet &rfiSet = plot.StartLine("RFI"); //RFIPlots::MakeRMSSpectrumPlot(rfiSet, _timeFrequencyWidget.Image(), mask); } _plotManager->Update(); } }
void IterationsPlot::Add(TimeFrequencyData &data, TimeFrequencyMetaDataCPtr) { Item item; Mask2DCPtr mask = data.GetSingleMask(); item.mode = ThresholdTools::Mode(data.GetSingleImage(), mask); item.winsorizedMode = ThresholdTools::WinsorizedMode(data.GetSingleImage(), mask); item.flaggedRatio = (double) mask->GetCount<true>() / ((double) mask->Width() * (double) mask->Height()); _stats.push_back(item); }
void RFIGuiController::PlotPowerSpectrumComparison() { if(IsImageLoaded()) { Plot2D &plot = _plotManager->NewPlot2D("Power spectrum comparison"); TimeFrequencyData data = OriginalData(); Image2DCPtr image = data.GetSingleImage(); Mask2DCPtr mask = data.GetSingleMask(); Plot2DPointSet &originalSet = plot.StartLine("Original"); RFIPlots::MakePowerSpectrumPlot(originalSet, image, mask, MetaData()); data = ContaminatedData(); image = data.GetSingleImage(); mask = data.GetSingleMask(); Plot2DPointSet &alternativeSet = plot.StartLine("Alternative"); RFIPlots::MakePowerSpectrumPlot(alternativeSet, image, mask, MetaData()); _plotManager->Update(); } }
void RFIGuiController::PlotLogLogDist() { if(IsImageLoaded()) { TimeFrequencyData activeData = ActiveData(); HistogramCollection histograms(activeData.PolarisationCount()); for(unsigned p=0;p!=activeData.PolarisationCount();++p) { TimeFrequencyData *polData = activeData.CreateTFDataFromPolarisationIndex(p); Image2DCPtr image = polData->GetSingleImage(); Mask2DCPtr mask = Mask2D::CreateCopy(polData->GetSingleMask()); histograms.Add(0, 1, p, image, mask); } _rfiGuiWindow.ShowHistogram(histograms); } }
void UVImager::Image(const TimeFrequencyData &data, TimeFrequencyMetaDataCPtr metaData, unsigned frequencyIndex) { if(_uvReal == 0) Empty(); Image2DCPtr real = data.GetRealPart(), imaginary = data.GetImaginaryPart(); Mask2DCPtr flags = data.GetSingleMask(); for(unsigned i=0;i<data.ImageWidth();++i) { switch(_imageKind) { case Homogeneous: if(flags->Value(i, frequencyIndex)==0.0L) { num_t vr = real->Value(i, frequencyIndex), vi = imaginary->Value(i, frequencyIndex); if(std::isfinite(vr) && std::isfinite(vi)) { num_t u,v; GetUVPosition(u, v, i, frequencyIndex, metaData); SetUVValue(u, v, vr, vi, 1.0); SetUVValue(-u, -v, vr, -vi, 1.0); } } break; case Flagging: if((flags->Value(i, frequencyIndex)!=0.0L && !_invertFlagging) || (flags->Value(i, frequencyIndex)==0.0L && _invertFlagging)) { num_t u,v; GetUVPosition(u, v, i, frequencyIndex, metaData); SetUVValue(u, v, 1, 0, 1.0); SetUVValue(-u, -v, 1, 0, 1.0); } break; } } }
void ChangeResolutionAction::DecreaseTimeWithMask(TimeFrequencyData &data) { size_t polCount = data.PolarisationCount(); for(size_t i=0;i<polCount;++i) { TimeFrequencyData *polData = data.CreateTFDataFromPolarisationIndex(i); Mask2DCPtr mask = polData->GetSingleMask(); for(unsigned j=0;j<polData->ImageCount();++j) { Image2DCPtr image = polData->GetImage(j); polData->SetImage(j, ThresholdTools::ShrinkHorizontally(_timeDecreaseFactor, image, mask)); } delete polData; } size_t maskCount = data.MaskCount(); for(size_t i=0;i<maskCount;++i) { Mask2DCPtr mask = data.GetMask(i); Mask2DPtr newMask = mask->ShrinkHorizontallyForAveraging(_timeDecreaseFactor); data.SetMask(i, newMask); } }
void PlotAction::plotBaselineRMS(ArtifactSet &artifacts) { if(artifacts.PolarizationStatistics() == 0) throw BadUsageException("No polarization statistics in the artifact set"); TimeFrequencyData &data = artifacts.ContaminatedData(); TimeFrequencyMetaDataCPtr metaData = artifacts.MetaData(); double rms = 0.0; for(unsigned i=0;i<data.PolarisationCount();++i) { TimeFrequencyData *polarisation = data.CreateTFDataFromPolarisationIndex(i); Mask2DCPtr mask = polarisation->GetSingleMask(); for(unsigned j=0;j<polarisation->ImageCount();++j) { Image2DCPtr image = polarisation->GetImage(j); rms += ThresholdTools::RMS(image, mask); } delete polarisation; } rms /= data.PolarisationCount(); ; AOLogger::Info << "RMS of " << metaData->Antenna1().name << " x " << metaData->Antenna2().name << ": " << rms << '\n'; }
void RFIGuiController::PlotDist() { if(IsImageLoaded()) { Plot2D &plot = _plotManager->NewPlot2D("Distribution"); TimeFrequencyData activeData = ActiveData(); Image2DCPtr image = activeData.GetSingleImage(); Mask2DPtr mask = Mask2D::CreateSetMaskPtr<false>(image->Width(), image->Height()); Plot2DPointSet &totalSet = plot.StartLine("Total"); RFIPlots::MakeDistPlot(totalSet, image, mask); Plot2DPointSet &uncontaminatedSet = plot.StartLine("Uncontaminated"); mask = Mask2D::CreateCopy(activeData.GetSingleMask()); RFIPlots::MakeDistPlot(uncontaminatedSet, image, mask); mask->Invert(); Plot2DPointSet &rfiSet = plot.StartLine("RFI"); RFIPlots::MakeDistPlot(rfiSet, image, mask); _plotManager->Update(); } }
void RFIGuiController::PlotPowerSpectrum() { if(IsImageLoaded()) { Plot2D &plot = _plotManager->NewPlot2D("Power spectrum"); plot.SetLogarithmicYAxis(true); TimeFrequencyData data = ActiveData(); Image2DCPtr image = data.GetSingleImage(); Mask2DPtr mask = Mask2D::CreateSetMaskPtr<false>(image->Width(), image->Height()); Plot2DPointSet &beforeSet = plot.StartLine("Before"); RFIPlots::MakePowerSpectrumPlot(beforeSet, image, mask, MetaData()); mask = Mask2D::CreateCopy(data.GetSingleMask()); if(!mask->AllFalse()) { Plot2DPointSet &afterSet = plot.StartLine("After"); RFIPlots::MakePowerSpectrumPlot(afterSet, image, mask, MetaData()); } _plotManager->Update(); } }
void CalibratePassbandAction::calibrate(TimeFrequencyData& data) const { const size_t height = data.ImageHeight(); std::vector<num_t> stddev(_steps); for(size_t step=0; step!=_steps; ++step) { const size_t startY = step*height/_steps, endY = (step+1)*height/_steps; std::vector<num_t> dataVector((1+endY-startY) * data.ImageWidth() * data.ImageCount()); std::vector<num_t>::iterator vecIter = dataVector.begin(); const Mask2DCPtr maskPtr = data.GetSingleMask(); const Mask2D &mask = *maskPtr; for(size_t i=0; i!=data.ImageCount(); ++i) { const Image2D &image = *data.GetImage(i); for(size_t y=startY; y!=endY; ++y) { const num_t *inputPtr = image.ValuePtr(0, y); const bool *maskPtr = mask.ValuePtr(0, y); for(size_t x=0; x!=image.Width(); ++x) { if(!*maskPtr && std::isfinite(*inputPtr)) { *vecIter = *inputPtr; ++vecIter; } ++inputPtr; ++maskPtr; } } } dataVector.resize(vecIter - dataVector.begin()); num_t mean; ThresholdTools::WinsorizedMeanAndStdDev<num_t>(dataVector, mean, stddev[step]); } for(size_t i=0; i!=data.ImageCount(); ++i) { const Image2D &image = *data.GetImage(i); Image2D *destImage = Image2D::CreateUnsetImage(image.Width(), image.Height()); for(size_t step=0; step!=_steps; ++step) { const size_t startY = step*height/_steps, endY = (step+1)*height/_steps; float correctionFactor; if(stddev[step] == 0.0) correctionFactor = 0.0; else correctionFactor = 1.0 / stddev[step]; const __m128 corrFact4 = _mm_set_ps(correctionFactor, correctionFactor, correctionFactor, correctionFactor); for(size_t y=startY; y!=endY; ++y) { const float *inputPtr = image.ValuePtr(0, y); float *destPtr = destImage->ValuePtr(0, y); for(size_t x=0;x<image.Width();x+=4) { _mm_store_ps(destPtr, _mm_mul_ps(corrFact4, _mm_load_ps(inputPtr))); inputPtr += 4; destPtr += 4; } } } data.SetImage(i, Image2DPtr(destImage)); } }