public LCStateMachine(ReduceLightCurveOperation videoOperation, IVideoController videoController) { m_VideoController = videoController; VideoOperation = videoOperation; m_CurrentStateObject = new LCStateSelectMeasuringStars(this); m_CurrentState = LightCurvesState.SelectMeasuringStars; m_CurrentStateObject.Initialize(); }
internal void Initialize(ReduceLightCurveOperation videoOperation, ITracker tracker, VideoController videoController) { m_LightCurvesVideoOperation = videoOperation; m_VideoController = videoController; m_Tracker = tracker; if (m_Tracker.SupportsManualCorrections) { m_VideoController.SetPictureBoxCursor(CustomCursors.PanCursor); } m_State = CorrectTrackingState.Normal; m_Mode = CorrectTrackingMode.All; for (int i = 0; i < tracker.TrackedObjects.Count; i++) { m_LightCurvesVideoOperation.SetManualTrackingCorrection(i, 0, 0); } m_VideoController.RefreshCurrentFrame(); }
private LCMeasurement ProcessSingleUnit( LCMeasurement reading, bool useLowPass, bool useLowPassDiff, int newFitMatrixSize, float newSignalAperture, bool fixedAperture, MeasurementsHelper measurer, IImagePixel[] groupCenters, float[] aperturesInGroup) { reading.ReProcessingPsfFitMatrixSize = newFitMatrixSize; TrackedObjectConfig objConfig = Footer.TrackedObjects[reading.TargetNo]; ImagePixel center = new ImagePixel(reading.X0, reading.Y0); int areaSize = groupCenters != null && groupCenters.Length > 1 ? 35 : 17; if (Context.Filter != LightCurveContext.FilterType.NoFilter) { areaSize += 2; } uint[,] data = BitmapFilter.CutArrayEdges(reading.PixelData, (35 - areaSize) / 2); var filter = TangraConfig.PreProcessingFilter.NoFilter; if (useLowPassDiff) { filter = TangraConfig.PreProcessingFilter.LowPassDifferenceFilter; } else if (useLowPass) { filter = TangraConfig.PreProcessingFilter.LowPassFilter; } NotMeasuredReasons rv = ReduceLightCurveOperation.MeasureObject( center, data, reading.PixelData, Context.BitPix, measurer, filter, Context.SignalMethod, Context.PsfQuadratureMethod, Context.PsfFittingMethod, newSignalAperture, objConfig.RefinedFWHM, Footer.RefinedAverageFWHM, reading, groupCenters, aperturesInGroup, Footer.ReductionContext.FullDisappearance); reading.SetIsMeasured(rv); reading.TotalReading = (uint)measurer.TotalReading; reading.TotalBackground = (uint)measurer.TotalBackground; reading.ApertureX = measurer.XCenter; reading.ApertureY = measurer.YCenter; reading.ApertureSize = measurer.Aperture; return(reading); }
private bool GetFitInMatrix(ITrackedObjectPsfFit gaussian, ref int matirxSize, float preselectedAperture) { rbGuidingStar.Text = "Guiding/Comparison Star"; m_IsBrightEnoughForAutoGuidingStar = false; if (m_Aperture == null) { if (gaussian != null && !double.IsNaN(gaussian.FWHM) && TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM) { m_Aperture = (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture); } else { m_Aperture = (float)(TangraConfig.Settings.Photometry.DefaultSignalAperture); } } else if ( gaussian != null && !double.IsNaN(gaussian.FWHM) && TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM && m_Aperture < (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture)) { m_Aperture = (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture); } nudFitMatrixSize.ValueChanged -= nudFitMatrixSize_ValueChanged; try { uint[,] autoStarsPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35); m_AutoStarsInLargerArea = StarFinder.GetStarsInArea( ref autoStarsPixels, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, m_AstroImage.MedianNoise, LightCurveReductionContext.Instance.DigitalFilter); m_ProcessingPixels = ImageFilters.CutArrayEdges(autoStarsPixels, 9); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 17); m_AutoStarsInArea = new List <PSFFit>(); foreach (PSFFit autoStar in m_AutoStarsInLargerArea) { if (autoStar.XCenter > 9 && autoStar.XCenter < 9 + 17 && autoStar.YCenter > 9 && autoStar.YCenter < 9 + 17) { // Don't change original star so use a clone PSFFit clone = autoStar.Clone(); clone.SetNewFieldCenterFrom35PixMatrix(8, 8); m_AutoStarsInArea.Add(clone); } } int oldMatirxSize = matirxSize; if (m_AutoStarsInArea.Count == 0) { rbGuidingStar.Text = "Guiding/Comparison Star"; // There are no stars that are bright enough. Simply let the user do what they want, but still try to default to a sensible aperture size MeasurementsHelper measurement = ReduceLightCurveOperation.DoConfiguredMeasurement(m_ProcessingPixels, m_Aperture.Value, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, 3.0, ref matirxSize); if (measurement.FoundBestPSFFit != null && measurement.FoundBestPSFFit.IsSolved && measurement.FoundBestPSFFit.Certainty > 0.1) { m_X0 = measurement.XCenter; m_Y0 = measurement.YCenter; m_FWHM = (float)measurement.FoundBestPSFFit.FWHM; } else { m_X0 = 8; m_Y0 = 8; m_FWHM = 6; } m_Gaussian = null; nudFitMatrixSize.SetNUDValue(11); } else if (m_AutoStarsInArea.Count == 1) { // There is exactly one good star found. Go and do a fit in a wider area double bestFindTolerance = 3.0; for (int i = 0; i < 2; i++) { MeasurementsHelper measurement = ReduceLightCurveOperation.DoConfiguredMeasurement(m_ProcessingPixels, m_Aperture.Value, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, bestFindTolerance, ref matirxSize); if (measurement != null && matirxSize != -1) { if (matirxSize < 5) { // Do a centroid in the full area, and get another matix centered at the centroid ImagePixel centroid = new ImagePixel(m_Center.X, m_Center.Y); m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(centroid); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(centroid); m_X0 = centroid.X; m_Y0 = centroid.Y; m_FWHM = 6; m_Gaussian = null; nudFitMatrixSize.SetNUDValue(11); } else { m_X0 = measurement.XCenter; m_Y0 = measurement.YCenter; if (measurement.FoundBestPSFFit != null) { m_FWHM = (float)measurement.FoundBestPSFFit.FWHM; m_Gaussian = measurement.FoundBestPSFFit; } else { m_FWHM = 6; m_Gaussian = null; } m_ProcessingPixels = measurement.PixelData; nudFitMatrixSize.SetNUDValue(matirxSize); } } else { matirxSize = oldMatirxSize; return(false); } if (m_Gaussian != null) { if (IsBrightEnoughtForGuidingStar()) { rbGuidingStar.Text = "Guiding/Comparison Star"; m_IsBrightEnoughForAutoGuidingStar = true; } break; } } } else if (m_AutoStarsInArea.Count > 1) { rbGuidingStar.Text = "Guiding/Comparison Star"; // There are more stars found. double xBest = m_Gaussian != null ? m_Gaussian.XCenter : m_IsEdit ? ObjectToAdd.ApertureMatrixX0 : 8.5; double yBest = m_Gaussian != null ? m_Gaussian.YCenter : m_IsEdit ? ObjectToAdd.ApertureMatrixY0 : 8.5; // by default use the one closest to the original location PSFFit closestFit = m_AutoStarsInArea[0]; double closestDist = double.MaxValue; foreach (PSFFit star in m_AutoStarsInArea) { double dist = Math.Sqrt((star.XCenter - xBest) * (star.XCenter - xBest) + (star.YCenter - yBest) * (star.YCenter - yBest)); if (closestDist > dist) { closestDist = dist; closestFit = star; } } m_X0 = (float)closestFit.XCenter; m_Y0 = (float)closestFit.YCenter; m_FWHM = (float)closestFit.FWHM; m_Gaussian = closestFit; nudFitMatrixSize.SetNUDValue(m_IsEdit ? ObjectToAdd.PsfFitMatrixSize : closestFit.MatrixSize); } //if (m_Gaussian == null && gaussian.Certainty > 0.1 && ImagePixel.ComputeDistance(gaussian.X0_Matrix, 8, gaussian.Y0_Matrix, 8) < 3) //{ // // Id we failed to locate a bright enough autostar, but the default Gaussian is still certain enough and close enought to the center, we present it as a starting point // m_X0 = (float)gaussian.X0_Matrix; // m_Y0 = (float)gaussian.Y0_Matrix; // m_FWHM = (float)gaussian.FWHM; // m_Gaussian = gaussian; //} decimal appVal; if (float.IsNaN(preselectedAperture)) { if (float.IsNaN(m_Aperture.Value)) { appVal = Convert.ToDecimal(TangraConfig.Settings.Photometry.DefaultSignalAperture); } else { appVal = Convert.ToDecimal(m_Aperture.Value); if (nudAperture1.Maximum < appVal) { nudAperture1.Maximum = appVal + 1; } } } else { appVal = (decimal)preselectedAperture; } if ((float)appVal > m_Aperture) { m_Aperture = (float)appVal; } nudAperture1.SetNUDValue(Math.Round(appVal, 2)); PlotSingleTargetPixels(); PlotGaussian(); return(true); } finally { nudFitMatrixSize.ValueChanged += nudFitMatrixSize_ValueChanged; } }
public void OpenLcFile(string fileName) { var fi = new FileInfo(fileName); double expectedMemoryMbNeeded = 500 /* For Tangra to operate*/ + 20 * fi.Length / (1024 * 1024) /* For the .lc file to be unpacked and loaded in memory */; double availableMemoryMb = CrossPlaform.GetAvailableMemoryInMegabytes(); if (expectedMemoryMbNeeded > availableMemoryMb) { if (MessageBox.Show( m_MainFormView, string.Format("It appears that you may be running in a low memory conditions and opening this file will require at least {0}Gb of free memory. Do you wish to continue?", (Math.Ceiling(expectedMemoryMbNeeded / 512.0) / 2).ToString("0.0")), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } m_MainFormView.Cursor = Cursors.WaitCursor; LCFile lcFile = null; try { m_MainFormView.Update(); lcFile = LCFile.Load(fileName, m_VideoController); if (lcFile != null) { ReduceLightCurveOperation operation = (ReduceLightCurveOperation)m_VideoController.SetOperation <ReduceLightCurveOperation>(this, false); operation.SetLCFile(lcFile); bool flipVertically; bool flipHorizontally; FramePlayer.TranslateFlipRotate(lcFile.Footer.RotateFlipType, out flipVertically, out flipHorizontally); object videoFile = GetVideoFileMatchingLcFile(lcFile, fileName); if (videoFile is string && !string.IsNullOrEmpty((string)videoFile) && File.Exists((string)videoFile)) { if (m_VideoController.OpenVideoFile((string)videoFile, new TangraOpenFileArgs { FrameRate = lcFile.Header.FramesPerSecond, BitPix = lcFile.Footer.DataBitPix, SerTiming = lcFile.Header.SerTimingType })) { TangraContext.Current.CanPlayVideo = false; m_VideoController.UpdateViews(); } } else if (videoFile is string[] && ((string[])videoFile).Length > 0) { var fitsFiles = (string[])videoFile; if (m_VideoController.OpenFitsFileSequence(Path.GetDirectoryName(fitsFiles[0]), fitsFiles, new LCFITSTimeStampReader(lcFile), null, 0, flipVertically, flipHorizontally, (int)lcFile.Data[0][0].CurrFrameNo)) { TangraContext.Current.CanPlayVideo = false; if (lcFile.Footer.FitsDynamicFromValue != -1 && lcFile.Footer.FitsDynamicToValue != -1) { m_VideoController.SetDisplayIntensifyMode(DisplayIntensifyMode.Dynamic, lcFile.Footer.FitsDynamicFromValue, lcFile.Footer.FitsDynamicToValue); } m_VideoController.UpdateViews(); } } else { // NOTE: No video file found, just show the saved averaged frame bool oldCanProcessLightCurvePixels = TangraContext.Current.CanProcessLightCurvePixels; TangraContext.Current.Reset(); TangraContext.Current.CanProcessLightCurvePixels = oldCanProcessLightCurvePixels; if (lcFile.Footer.AveragedFrameBytes != null) { if (m_VideoController.SingleBitmapFile(lcFile)) { TangraContext.Current.CanPlayVideo = false; m_VideoController.UpdateViews(); PSFFit.SetDataRange(lcFile.Footer.DataBitPix, lcFile.Footer.DataAav16NormVal); } } TangraContext.Current.CanPlayVideo = false; TangraContext.Current.CanScrollFrames = false; m_VideoController.UpdateViews(); } m_Context = new LightCurveContext(lcFile); m_LightCurveForm = new frmLightCurve(this, m_AddinsController, lcFile, fileName); m_LightCurveForm.SetGeoLocation(m_VideoController.GeoLocation); m_LightCurveForm.Show(m_MainFormView); m_LightCurveForm.Update(); // TODO: Review the VideoController-LightCurveController-ReduceLightCurveOperation relation and how they are initialized // TODO: Provide a clean way of initializing the controller/operation state when opening an .lc file! operation.EnterViewLightCurveMode(lcFile, m_VideoController, m_VideoController.ControlerPanel); RegisterRecentFile(RecentFileType.LightCurve, fileName); if (!string.IsNullOrEmpty(m_VideoController.CurrentVideoFileType)) { // Move to the first frame in the light curve m_VideoController.MoveToFrame((int)lcFile.Header.MinFrame); } TangraContext.Current.FileName = Path.GetFileName(fileName); TangraContext.Current.FileFormat = m_lcFile.Header.SourceInfo; m_VideoController.UpdateViews(); } } catch (IOException ioex) { MessageBox.Show(ioex.Message, "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { m_MainFormView.Cursor = Cursors.Default; } }