private void GenerateAVIVideo(ModelConfig modelConfig, List <IStar> stars) { TangraVideo.CloseAviFile(); TangraVideo.StartNewAviFile(modelConfig.FileName, modelConfig.FrameWidth, modelConfig.FrameHeight, 8, 25, false); m_MagnitudeToPeakDict = null; try { //Pixelmap pixmap = new Pixelmap(modelConfig.FrameWidth, modelConfig.FrameHeight, bitPix, new uint[modelConfig.FrameWidth * modelConfig.FrameHeight], null, null); //AddOnScreenText(bmp, modelConfig, "The simulated video stars from the next frame"); //TangraVideo.AddAviVideoFrame(pixmap, modelConfig.Gamma, null); uint maxSignalValue = (uint)(255 * modelConfig.Integration); Random rndGen = new Random((int)DateTime.Now.Ticks); m_SimulatedDarkFrame = new int[modelConfig.FrameWidth, modelConfig.FrameHeight]; for (int x = 0; x < modelConfig.FrameWidth; x++) { for (int y = 0; y < modelConfig.FrameHeight; y++) { if (modelConfig.DarkFrameMean > 0) { double randomPeak = rndGen.Next(0, 100) == 66 ? 255 : 0; double darkPixel = Math.Abs(VideoModelUtils.Random((modelConfig.DarkFrameMean + randomPeak) * modelConfig.Integration, 1)); double bgPixel = Math.Min(maxSignalValue, Math.Max(0, darkPixel)); m_SimulatedDarkFrame[x, y] = (int)bgPixel; } else { m_SimulatedDarkFrame[x, y] = 0; } } } for (int i = 0; i <= modelConfig.TotalFrames; i++) { using (Pixelmap pixmap = new Pixelmap(modelConfig.FrameWidth, modelConfig.FrameHeight, 16, new uint[modelConfig.FrameWidth * modelConfig.FrameHeight], null, null)) { pixmap.SetMaxSignalValue(maxSignalValue); VideoModelUtils.GenerateNoise(pixmap, m_SimulatedDarkFrame, modelConfig.NoiseMean * modelConfig.Integration, modelConfig.NoiseStdDev * modelConfig.Integration); GenerateFrame(pixmap, stars, modelConfig); TangraVideo.AddAviVideoFrame(pixmap, modelConfig.LinearityCoefficient, (int)pixmap.MaxSignalValue); } InvokeUpdateUI(2, (int)(100.0 * i / modelConfig.TotalFrames), true); } } finally { TangraVideo.CloseAviFile(); } }
private Pixelmap GenerateFrame(double percentDone, int frameNo, ModelConfig modelConfig) { float I1 = (float)modelConfig.StandardStarIntensity; float I2 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag2); float I3 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag3); float I4 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag4); float I5 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag5); int IPB1 = (int)Math.Round((double)modelConfig.StandardStarIntensity / Math.Pow(10, (modelConfig.PassByMag1 - modelConfig.StandardStarMag) / 2.5)); int IPB2 = (int)Math.Round((double)modelConfig.StandardStarIntensity / Math.Pow(10, (modelConfig.PassByMag2 - modelConfig.StandardStarMag) / 2.5)); float fwhm1 = (float)modelConfig.FWHM; // NOTE: Use the same FWHM to get accurate photometry //float fwhm2 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag2) * FWHM_GAIN_PER_MAG); //float fwhm3 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag3) * FWHM_GAIN_PER_MAG); //float fwhm4 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag4) * FWHM_GAIN_PER_MAG); //float fwhm5 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag5) * FWHM_GAIN_PER_MAG); float fwhm_pb1 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.PassByMag1) * FWHM_GAIN_PER_MAG); float fwhm_pb2 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.PassByMag2) * FWHM_GAIN_PER_MAG); if (modelConfig.FlickeringStdDev > 0) { I1 = (int)Math.Round(VideoModelUtils.Random(I1, modelConfig.FlickeringStdDev)); I2 = (int)Math.Round(VideoModelUtils.Random(I2, modelConfig.FlickeringStdDev)); I3 = (int)Math.Round(VideoModelUtils.Random(I3, modelConfig.FlickeringStdDev)); I4 = (int)Math.Round(VideoModelUtils.Random(I4, modelConfig.FlickeringStdDev)); I5 = (int)Math.Round(VideoModelUtils.Random(I5, modelConfig.FlickeringStdDev)); } int[,] simulatedBackground = new int[300, 200]; for (int x = 0; x < 300; x++) { for (int y = 0; y < 200; y++) { simulatedBackground[x, y] = 0; } } using (Bitmap bmp = new Bitmap(300, 200, PixelFormat.Format24bppRgb)) { if (modelConfig.SimulateMovingBackground) { simulatedBackground = m_BgModelGen.GenerateBackground(modelConfig.PolyBgOrder, modelConfig.PolyBgFreq, modelConfig.PolyBgShift, modelConfig.TotalFrames * percentDone, 110, 100, 35); } VideoModelUtils.GenerateNoise(bmp, simulatedBackground, modelConfig.NoiseMean, modelConfig.NoiseStdDev); VideoModelUtils.GenerateStar(bmp, 25, 160, (float)fwhm1, I1); if (modelConfig.SimulateStar2) { VideoModelUtils.GenerateStar(bmp, 75, 160, (float)fwhm1, I2); } if (modelConfig.SimulateStar3) { VideoModelUtils.GenerateStar(bmp, 125, 160, (float)fwhm1, I3); } if (modelConfig.SimulateStar4) { VideoModelUtils.GenerateStar(bmp, 175, 160, (float)fwhm1, I4); } if (modelConfig.SimulateStar5) { VideoModelUtils.GenerateStar(bmp, 225, 160, (float)fwhm1, I5); } if (modelConfig.SimulatePassBy) { double maxVerticaldistance = Math.Sqrt(modelConfig.MaxDistance * modelConfig.MaxDistance - modelConfig.PassByDist * modelConfig.PassByDist); bool isOcculted = false; if (modelConfig.OccultedNumberOfFrames > 0 && Math.Abs(modelConfig.PassByDist) < 0.2) { int firstOccFrame = (modelConfig.TotalFrames / 2) - modelConfig.OccultedNumberOfFrames; int lastOccFrame = (modelConfig.TotalFrames / 2) - 1; isOcculted = frameNo >= firstOccFrame && frameNo <= lastOccFrame; } if (!isOcculted) { VideoModelUtils.GenerateStar(bmp, 110, 100, fwhm_pb1, IPB1); } VideoModelUtils.GenerateStar(bmp, 110 + (float)modelConfig.PassByDist, (float)(100 - maxVerticaldistance + (2 * maxVerticaldistance) * percentDone), fwhm_pb2, IPB2); } AddOnScreenText(bmp, modelConfig); return(Pixelmap.ConstructFromBitmap(bmp, TangraConfig.ColourChannel.Red)); } }
private void InitStarAmplitudeModelling(ModelConfig modelConfig, float accuracy, int bitPix, uint maxSignalValue) { if (m_MagnitudeToPeakDict != null) { return; } m_MagnitudeToPeakDict = new Dictionary <double, int>(); m_MagnitudeToPeakMags = new List <double>(); m_MagnitudeToPeakPeaks = new List <int>(); var mea = new MeasurementsHelper( bitPix, TangraConfig.BackgroundMethod.BackgroundMedian, TangraConfig.Settings.Photometry.SubPixelSquareSize, TangraConfig.Settings.Photometry.Saturation.GetSaturationForBpp(bitPix, maxSignalValue)); float apertureSize = APERTURE; float annulusInnerRadius = (GAP + APERTURE) / APERTURE; int annulusMinPixels = (int)(Math.PI * (Math.Pow(ANNULUS + GAP + APERTURE, 2) - Math.Pow(GAP + APERTURE, 2))); mea.SetCoreProperties(annulusInnerRadius, annulusMinPixels, CorePhotometrySettings.Default.RejectionBackgroundPixelsStdDev, 2 /* TODO: This must be configurable */); int peak = (int)(maxSignalValue - (modelConfig.NoiseMean + modelConfig.DarkFrameMean) * modelConfig.Integration); int TOTAL_STEPS = 100; double step = Math.Log10(peak) / TOTAL_STEPS; double zeroMag = double.NaN; for (int ii = 0; ii < TOTAL_STEPS; ii++) { int amplitude = (int)Math.Round(Math.Pow(10, Math.Log10(peak) - ii * step)); Pixelmap pixmap = new Pixelmap(64, 64, bitPix, new uint[64 * 64], null, null); VideoModelUtils.GenerateStar(pixmap, 32, 32, (float)modelConfig.FWHM, amplitude, 0 /* Gaussian */); PSFFit fit = new PSFFit(32, 32); AstroImage img = new AstroImage(pixmap); uint[,] data = img.GetMeasurableAreaPixels(32, 32, 17); uint[,] backgroundPixels = img.GetMeasurableAreaPixels(32, 32, 35); fit.Fit(data); var result = mea.MeasureObject(new ImagePixel(32, 32), data, backgroundPixels, pixmap.BitPixCamera, TangraConfig.PreProcessingFilter.NoFilter, TangraConfig.PhotometryReductionMethod.AperturePhotometry, TangraConfig.PsfQuadrature.NumericalInAperture, TangraConfig.PsfFittingMethod.DirectNonLinearFit, apertureSize, modelConfig.FWHM, (float)modelConfig.FWHM, new FakeIMeasuredObject(fit), null, null, false); if (result == NotMeasuredReasons.TrackedSuccessfully && !mea.HasSaturatedPixels) { // Add value for fitting double measurement = mea.TotalReading - mea.TotalBackground; if (double.IsNaN(zeroMag)) { zeroMag = modelConfig.BrighestUnsaturatedStarMag + 2.5 * Math.Log10(measurement); } double magnitude = -2.5 * Math.Log10(measurement) + zeroMag; m_MagnitudeToPeakDict[magnitude] = amplitude; m_MagnitudeToPeakMags.Add(magnitude); m_MagnitudeToPeakPeaks.Add(amplitude); } } }
private void GenerateFrame(Pixelmap pixmap, List <IStar> stars, ModelConfig modelConfig) { var mea = new MeasurementsHelper( pixmap.BitPixCamera, TangraConfig.BackgroundMethod.BackgroundMedian, TangraConfig.Settings.Photometry.SubPixelSquareSize, TangraConfig.Settings.Photometry.Saturation.GetSaturationForBpp(pixmap.BitPixCamera, pixmap.MaxSignalValue)); float apertureSize = APERTURE; float annulusInnerRadius = (GAP + APERTURE) / APERTURE; int annulusMinPixels = (int)(Math.PI * (Math.Pow(ANNULUS + GAP + APERTURE, 2) - Math.Pow(GAP + APERTURE, 2))); mea.SetCoreProperties(annulusInnerRadius, annulusMinPixels, CorePhotometrySettings.Default.RejectionBackgroundPixelsStdDev, 2 /* TODO: This must be configurable */); var measurements = new Dictionary <IStar, double>(); foreach (IStar star in stars) { double x, y; GetOnPlateCoordinates(star.RADeg, star.DEDeg, modelConfig, out x, out y); if (x < 0 || x > modelConfig.FrameWidth || y < 0 || y > modelConfig.FrameHeight) { continue; } float starMag = GetStarMag(star, modelConfig.PhotometricFilter); float iMax = ModelStarAmplitude(star, starMag, modelConfig, pixmap.BitPixCamera, pixmap.MaxSignalValue); if (!float.IsNaN(iMax)) { VideoModelUtils.GenerateStar(pixmap, (float)x, (float)y, (float)modelConfig.FWHM, iMax, 0 /*Use Gaussian */); if (modelConfig.CheckMagnitudes) { var image = new AstroImage(pixmap); uint[,] data = image.GetMeasurableAreaPixels((int)x, (int)y, 17); uint[,] backgroundPixels = image.GetMeasurableAreaPixels((int)x, (int)y, 35); PSFFit fit = new PSFFit((int)x, (int)y); fit.Fit(data); var result = mea.MeasureObject(new ImagePixel(x, y), data, backgroundPixels, pixmap.BitPixCamera, TangraConfig.PreProcessingFilter.NoFilter, TangraConfig.PhotometryReductionMethod.AperturePhotometry, TangraConfig.PsfQuadrature.NumericalInAperture, TangraConfig.PsfFittingMethod.DirectNonLinearFit, apertureSize, modelConfig.FWHM, (float)modelConfig.FWHM, new FakeIMeasuredObject(fit), null, null, false); if (result == NotMeasuredReasons.TrackedSuccessfully && !mea.HasSaturatedPixels) { // Add value for fitting measurements.Add(star, mea.TotalReading - mea.TotalBackground); } } } } if (modelConfig.CheckMagnitudes) { CalculateGagnitudeFit(measurements, modelConfig.BVSlope); } }
private void GenerateAAVVideo(ModelConfig modelConfig, List <IStar> stars) { AavFileCreator.CloseFile(); AavFileCreator.StartNewFile(modelConfig.FileName, modelConfig.FrameWidth, modelConfig.FrameHeight, modelConfig.Integration); m_MagnitudeToPeakDict = null; try { //Pixelmap pixmap = new Pixelmap(modelConfig.FrameWidth, modelConfig.FrameHeight, bitPix, new uint[modelConfig.FrameWidth * modelConfig.FrameHeight], null, null); //AddOnScreenText(bmp, modelConfig, "The simulated video stars from the next frame"); //TangraVideo.AddAviVideoFrame(pixmap, modelConfig.Gamma, null); DateTime zeroFrameDT = DateTime.UtcNow; uint maxSignalValue = (uint)(255 * modelConfig.Integration); Random rndGen = new Random((int)DateTime.Now.Ticks); m_SimulatedDarkFrame = new int[modelConfig.FrameWidth, modelConfig.FrameHeight]; for (int x = 0; x < modelConfig.FrameWidth; x++) { for (int y = 0; y < modelConfig.FrameHeight; y++) { if (modelConfig.DarkFrameMean > 0) { double randomPeak = rndGen.Next(0, 100) == 66 ? 255 : 0; double darkPixel = Math.Abs(VideoModelUtils.Random((modelConfig.DarkFrameMean + randomPeak) * modelConfig.Integration, 1)); double bgPixel = Math.Min(maxSignalValue, Math.Max(0, darkPixel)); m_SimulatedDarkFrame[x, y] = (int)bgPixel; } else { m_SimulatedDarkFrame[x, y] = 0; } } } for (int i = 0; i <= modelConfig.TotalFrames; i++) { using (Pixelmap pixmap = new Pixelmap(modelConfig.FrameWidth, modelConfig.FrameHeight, 16, new uint[modelConfig.FrameWidth * modelConfig.FrameHeight], null, null)) { pixmap.SetMaxSignalValue(maxSignalValue); VideoModelUtils.GenerateNoise(pixmap, m_SimulatedDarkFrame, modelConfig.NoiseMean * modelConfig.Integration, modelConfig.NoiseStdDev * modelConfig.Integration); GenerateFrame(pixmap, stars, modelConfig); DateTime startDT = zeroFrameDT.AddMilliseconds(40 * modelConfig.Integration * i); if (Math.Abs(modelConfig.LinearityCoefficient - 1) > 0.0001) { uint maxVal = pixmap.MaxSignalValue; double gammaCoeff = maxVal / Math.Pow((double)maxVal, modelConfig.LinearityCoefficient); for (int x = 0; x < pixmap.Width; x++) { for (int y = 0; y < pixmap.Height; y++) { uint nonLinVal = (uint)Math.Round(gammaCoeff * Math.Pow(pixmap[x, y], modelConfig.LinearityCoefficient)); pixmap[x, y] = Math.Min(maxVal, Math.Max(0, nonLinVal)); } } } AavFileCreator.AddVideoFrame(startDT, startDT.AddMilliseconds(40 * modelConfig.Integration), pixmap); } InvokeUpdateUI(2, (int)(100.0 * i / modelConfig.TotalFrames), true); } } finally { AavFileCreator.CloseFile(); } }