Ejemplo n.º 1
0
        private static void ReconstructRandom(MeasurementData input, GriddingConstants c, float[,] psf, int blockSize, int iterCount, string file)
        {
            var cutFactor   = 8;
            var totalSize   = new Rectangle(0, 0, c.GridSize, c.GridSize);
            var psfCut      = PSF.Cut(psf, cutFactor);
            var maxSidelobe = PSF.CalcMaxSidelobe(psf, cutFactor);

            var maxLipschitzCut = PSF.CalcMaxLipschitz(psfCut);
            var lambda          = (float)(LAMBDA * PSF.CalcMaxLipschitz(psfCut));
            var lambdaTrue      = (float)(LAMBDA * PSF.CalcMaxLipschitz(psf));
            var alpha           = ALPHA;

            ApproxFast.LAMBDA_TEST = lambdaTrue;
            ApproxFast.ALPHA_TEST  = alpha;

            var metadata = Partitioner.CreatePartition(c, input.UVW, input.Frequencies);

            var random         = new Random(123);
            var approx         = new ApproxFast(totalSize, psfCut, 8, blockSize, 0.0f, 0.0f, false, true, false);
            var bMapCalculator = new PaddedConvolver(PSF.CalcPaddedFourierCorrelation(psfCut, totalSize), new Rectangle(0, 0, psfCut.GetLength(0), psfCut.GetLength(1)));
            var data           = new ApproxFast.TestingData(new StreamWriter(file + "_tmp.txt"));
            var xImage         = new float[c.GridSize, c.GridSize];
            var xCorr          = Copy(xImage);
            var residualVis    = input.Visibilities;

            var dirtyGrid  = IDG.GridW(c, metadata, residualVis, input.UVW, input.Frequencies);
            var dirtyImage = FFT.WStackIFFTFloat(dirtyGrid, c.VisibilitiesCount);

            FFT.Shift(dirtyImage);

            var maxDirty         = Residuals.GetMax(dirtyImage);
            var bMap             = bMapCalculator.Convolve(dirtyImage);
            var maxB             = Residuals.GetMax(bMap);
            var correctionFactor = Math.Max(maxB / (maxDirty * maxLipschitzCut), 1.0f);
            var currentSideLobe  = maxB * maxSidelobe * correctionFactor;
            var currentLambda    = (float)Math.Max(currentSideLobe / alpha, lambda);

            var gCorr  = new float[c.GridSize, c.GridSize];
            var shared = new ApproxFast.SharedData(currentLambda, alpha, 1, 1, 8, CountNonZero(psfCut), approx.psf2, approx.aMap, xImage, xCorr, bMap, gCorr, new Random());

            shared.ActiveSet               = ApproxFast.GetActiveSet(xImage, bMap, shared.YBlockSize, shared.XBlockSize, lambda, alpha, shared.AMap);
            shared.BlockLock               = new int[shared.ActiveSet.Count];
            shared.maxLipschitz            = (float)PSF.CalcMaxLipschitz(psfCut);
            shared.MaxConcurrentIterations = 1000;
            approx.DeconvolveConcurrentTest(data, 0, 0, 0.0, shared, 1, 1e-5f, Copy(xImage), dirtyImage, psfCut, psf);
            var output = Tools.LMC.CutN132Remnant(xImage);

            Tools.WriteToMeltCSV(output.Item1, file + "_1k.csv", output.Item2, output.Item3);
            FitsIO.Write(output.Item1, file + "_1k.fits");
            FitsIO.Write(xImage, file + "_1k2.fits");

            approx.DeconvolveConcurrentTest(data, 0, 0, 0.0, shared, iterCount, 1e-5f, Copy(xImage), dirtyImage, psfCut, psf);
            output = Tools.LMC.CutN132Remnant(xImage);
            Tools.WriteToMeltCSV(output.Item1, file + "_10k.csv", output.Item2, output.Item3);
            FitsIO.Write(output.Item1, file + "_10k.fits");
            FitsIO.Write(xImage, file + "_10k2.fits");
        }