/// <summary> /// Does the second step of the plate calibration: Least Square with the mapped celestrial stars (from step 1) /// </summary> /// <param name="fitOrder"></param> /// <returns></returns> public bool SolvePlateConstantsPhase2(FitOrder fitOrder, bool fineFit) { LeastSquareFittedAstrometry firstSolution; m_SolvedPlate = m_ConstantsSolver.SolveWithLinearRegression(m_AstrometrySettings, out firstSolution); if (firstSolution != null) { if (fineFit) { m_Context.InitialSecondAstrometricFit = LeastSquareFittedAstrometry.FromReflectedObject(firstSolution); m_Context.InitialSecondAstrometricFit.FitInfo.AllStarPairs.AddRange(firstSolution.FitInfo.AllStarPairs); } else { m_Context.InitialFirstAstrometricFit = LeastSquareFittedAstrometry.FromReflectedObject(firstSolution); m_Context.InitialFirstAstrometricFit.FitInfo.AllStarPairs.AddRange(firstSolution.FitInfo.AllStarPairs); } } if (m_SolvedPlate != null) { // TODO: Make this configurable if (m_ConstantsSolver.ExcludedForBadResidualsCount < 2 * m_ConstantsSolver.IncludedInSolutionCount) { LeastSquareFittedAstrometry lsfa = m_SolvedPlate as LeastSquareFittedAstrometry; // At least 33% of the stars should be included in the solution if (fineFit) { m_Context.SecondAstrometricFit = lsfa; } else { m_Context.FirstAstrometricFit = LeastSquareFittedAstrometry.FromReflectedObject(lsfa); m_Context.FirstAstrometricFit.FitInfo.AllStarPairs.AddRange(lsfa.FitInfo.AllStarPairs); } #if ASTROMETRY_DEBUG //foreach (PlateConstStarPair pair in lsfa.FitInfo.AllStarPairs) //{ // double x, y; // lsfa.GetImageCoordsFromRADE(pair.RADeg, pair.DEDeg, out x, out y); // double dist = lsfa.GetDistanceInArcSec(x, y, pair.x, pair.y); // Trace.Assert(Math.Abs(dist) < pair.FitInfo.ResidualArcSec*1.1); //} #endif return(true); } } return(false); }
public static CalibrationContext Deserialize(byte[] data) { CalibrationContext ctx = new CalibrationContext(); BinaryFormatter fmt = new BinaryFormatter(); using (MemoryStream memStr = new MemoryStream(data)) using (StreamReader rdr = new StreamReader(memStr)) { int version = (int)fmt.Deserialize(memStr); if (version > 0) { object obj = fmt.Deserialize(memStr); try { ctx.PlateConfig = (AstroPlate)obj; } catch (Exception) { ctx.PlateConfig = AstroPlate.FromReflectedObject(obj); } obj = fmt.Deserialize(memStr); try { ctx.StarMap = (StarMap)obj; } catch (Exception) { ctx.StarMap = Tangra.Model.Astro.StarMap.FromReflectedObject(obj); } int top = (int)fmt.Deserialize(memStr); int left = (int)fmt.Deserialize(memStr); int width = (int)fmt.Deserialize(memStr); int height = (int)fmt.Deserialize(memStr); ctx.FitExcludeArea = new Rectangle(top, left, width, height); obj = fmt.Deserialize(memStr); try { ctx.FieldSolveContext = (FieldSolveContext)obj; } catch (Exception) { ctx.FieldSolveContext = FieldSolveContext.FromReflectedObject(obj); } if (version > 1) { bool noNull = (bool)fmt.Deserialize(memStr); if (noNull) { obj = fmt.Deserialize(memStr); try { ctx.PreliminaryFit = (DirectTransRotAstrometry)obj; } catch (Exception) { ctx.PreliminaryFit = DirectTransRotAstrometry.FromReflectedObject(obj); } } noNull = (bool)fmt.Deserialize(memStr); if (noNull) { obj = fmt.Deserialize(memStr); try { ctx.FirstAstrometricFit = (LeastSquareFittedAstrometry)obj; } catch (Exception) { ctx.FirstAstrometricFit = LeastSquareFittedAstrometry.FromReflectedObject(obj); } } noNull = (bool)fmt.Deserialize(memStr); if (noNull) { obj = fmt.Deserialize(memStr); try { ctx.SecondAstrometricFit = (LeastSquareFittedAstrometry)obj; } catch (Exception) { ctx.SecondAstrometricFit = LeastSquareFittedAstrometry.FromReflectedObject(obj); } } noNull = (bool)fmt.Deserialize(memStr); if (noNull) { obj = fmt.Deserialize(memStr); try { ctx.DistanceBasedFit = (LeastSquareFittedAstrometry)obj; } catch (Exception) { ctx.DistanceBasedFit = LeastSquareFittedAstrometry.FromReflectedObject(obj); } } noNull = (bool)fmt.Deserialize(memStr); if (noNull) { obj = fmt.Deserialize(memStr); try { ctx.ImprovedDistanceBasedFit = (LeastSquareFittedAstrometry)obj; } catch (Exception) { ctx.ImprovedDistanceBasedFit = LeastSquareFittedAstrometry.FromReflectedObject(obj); } } if (version > 2) { FocalLengthFit flf = null; noNull = (bool)fmt.Deserialize(memStr); if (noNull) { obj = fmt.Deserialize(memStr); try { flf = (FocalLengthFit)obj; } catch (Exception) { flf = FocalLengthFit.FromReflectedObject(obj); } } ctx.ConstantsSolver = new PlateConstantsSolver(ctx.PlateConfig); ctx.ConstantsSolver.SetFocalLengthFit(flf); } } else { ctx.PreliminaryFit = (DirectTransRotAstrometry)fmt.Deserialize(memStr); } } } return(ctx); }