Esempio n. 1
0
	void ChangeResolutionAction::IncreaseFrequency(TimeFrequencyData &originalData, TimeFrequencyData &changedData, bool restoreImage, bool restoreMask)
	{
		if(restoreImage)
		{
			size_t imageCount = originalData.ImageCount();
			if(imageCount != changedData.ImageCount())
				throw std::runtime_error("When restoring resolution in change resolution action, original data and changed data do not have the same number of images");
			for(size_t i=0;i<imageCount;++i)
			{
				Image2DCPtr image = changedData.GetImage(i);
				Image2DPtr newImage = image->EnlargeVertically(_frequencyDecreaseFactor, originalData.ImageHeight());
				originalData.SetImage(i, newImage);
			}
		}
		if(restoreMask)
		{
			originalData.SetMask(changedData);
			size_t maskCount = originalData.MaskCount();
			for(size_t i=0;i<maskCount;++i)
			{
				Mask2DCPtr mask = changedData.GetMask(i);
				Mask2DPtr newMask = Mask2D::CreateUnsetMaskPtr(originalData.ImageWidth(), originalData.ImageHeight());
				newMask->EnlargeVerticallyAndSet(mask, _frequencyDecreaseFactor);
				originalData.SetMask(i, newMask);
			}
		}
	}
Esempio n. 2
0
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();
	}
}
Esempio n. 3
0
void RFIGuiController::OpenTestSet(unsigned index, bool gaussianTestSets)
{
	unsigned width = 1024*16, height = 1024;
	if(IsImageLoaded())
	{
		TimeFrequencyData activeData = ActiveData();
		width = activeData.ImageWidth();
		height = activeData.ImageHeight();
	}
	Mask2DPtr rfi = Mask2D::CreateSetMaskPtr<false>(width, height);
	Image2DPtr testSetReal(MitigationTester::CreateTestSet(index, rfi, width, height, gaussianTestSets));
	Image2DPtr testSetImaginary(MitigationTester::CreateTestSet(2, rfi, width, height, gaussianTestSets));
	TimeFrequencyData data(SinglePolarisation, testSetReal, testSetImaginary);
	data.SetGlobalMask(rfi);
	
	_rfiGuiWindow.GetTimeFrequencyWidget().SetNewData(data, MetaData());
	_rfiGuiWindow.GetTimeFrequencyWidget().Update();
}
Esempio n. 4
0
	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));
		}
	}