コード例 #1
0
        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);
        }
コード例 #2
0
        public byte[] Serialize()
        {
            BinaryFormatter fmt = new BinaryFormatter();

            using (MemoryStream memStr = new MemoryStream())
            {
                fmt.Serialize(memStr, SERIALIZATION_VERSION);
                fmt.Serialize(memStr, PlateConfig);

                StarMap sMap = StarMap as StarMap;
                fmt.Serialize(memStr, sMap);

                fmt.Serialize(memStr, FitExcludeArea.Top);
                fmt.Serialize(memStr, FitExcludeArea.Left);
                fmt.Serialize(memStr, FitExcludeArea.Width);
                fmt.Serialize(memStr, FitExcludeArea.Height);

                fmt.Serialize(memStr, FieldSolveContext);

                DirectTransRotAstrometry trRot = PreliminaryFit as DirectTransRotAstrometry;
                fmt.Serialize(memStr, trRot != null);
                if (trRot != null)
                {
                    fmt.Serialize(memStr, trRot);
                }

                fmt.Serialize(memStr, FirstAstrometricFit != null);
                if (FirstAstrometricFit != null)
                {
                    fmt.Serialize(memStr, FirstAstrometricFit);
                }

                fmt.Serialize(memStr, SecondAstrometricFit != null);
                if (SecondAstrometricFit != null)
                {
                    fmt.Serialize(memStr, SecondAstrometricFit);
                }

                fmt.Serialize(memStr, DistanceBasedFit != null);
                if (DistanceBasedFit != null)
                {
                    fmt.Serialize(memStr, DistanceBasedFit);
                }

                fmt.Serialize(memStr, ImprovedDistanceBasedFit != null);
                if (ImprovedDistanceBasedFit != null)
                {
                    fmt.Serialize(memStr, ImprovedDistanceBasedFit);
                }


                FocalLengthFit flf = null;
                if (ConstantsSolver != null)
                {
                    flf = ConstantsSolver.ComputeFocalLengthFit();
                }

                fmt.Serialize(memStr, flf != null);
                if (flf != null)
                {
                    fmt.Serialize(memStr, flf);
                }


                memStr.Flush();

                return(memStr.ToArray());
            }
        }
コード例 #3
0
        public LeastSquareFittedAstrometry SolvePlateConstantsPhase4(double pyramidLimitMag)
        {
            double ra0deg, de0Deg;

            m_SolvedPlate.GetRADEFromImageCoords(m_SolvedPlate.Image.CenterXImage, m_SolvedPlate.Image.CenterYImage, out ra0deg, out de0Deg);

            FocalLengthFit distFit = m_ConstantsSolver.ComputeFocalLengthFit();

            m_Context.PlateConfig.EffectiveFocalLength = m_Context.FieldSolveContext.FocalLength;
            distFit.GetFocalParameters(m_Context.PlateConfig.EffectiveFocalLength, out m_Context.PlateConfig.EffectivePixelWidth, out m_Context.PlateConfig.EffectivePixelHeight);

            DistanceBasedAstrometrySolver distMatch = new DistanceBasedAstrometrySolver(
                m_AstrometryController,
                m_Context.PlateConfig,
                m_AstrometrySettings,
                m_Context.FieldSolveContext.CatalogueStars,
                m_Context.FieldSolveContext.RADeg,
                m_Context.FieldSolveContext.DEDeg,
                m_Context.FieldSolveContext.DetermineAutoLimitMagnitude);

            distMatch.SetMinMaxMagOfStarsForAstrometry(CorePyramidConfig.Default.DefaultMinAstrometryMagnitude, 18);

            distMatch.SetMinMaxMagOfStarsForPyramidAlignment(CorePyramidConfig.Default.DefaultMinPyramidMagnitude, pyramidLimitMag);
            Trace.WriteLine(string.Format("Stars for alignment in range: {0:0.0} - {1:0.0} mag", CorePyramidConfig.Default.DefaultMinPyramidMagnitude, pyramidLimitMag));

            Dictionary <PSFFit, IStar> manualStars = null;
            var threeStarFit = m_Context.PreliminaryFit as ThreeStarAstrometry;

            if (threeStarFit != null)
            {
                manualStars = new Dictionary <PSFFit, IStar>();
                foreach (var kvp in threeStarFit.UserStars)
                {
                    PSFFit psfFit;
                    m_Context.StarMap.GetPSFFit(kvp.Key.X, kvp.Key.Y, PSFFittingMethod.NonLinearFit, out psfFit);
                    if (psfFit != null && psfFit.IsSolved)
                    {
                        manualStars.Add(psfFit, kvp.Value);
                    }
                }
            }

            distMatch.InitNewMatch(m_Context.StarMap, PyramidMatchType.PlateSolve, manualStars);

#if ASTROMETRY_DEBUG
            Dictionary <int, ulong> debugInfo = new Dictionary <int, ulong>();

            var starList = m_Context.SecondAstrometricFit.FitInfo.AllStarPairs
                           .Where(p => !p.FitInfo.ExcludedForHighResidual);

            foreach (var x in starList)
            {
                if (!debugInfo.ContainsKey(x.FeatureId))
                {
                    debugInfo.Add(x.FeatureId, x.StarNo);
                }
            }

            foreach (var f in m_Context.StarMap.Features)
            {
                Trace.WriteLine(string.Format("{0} - {1}", f.FeatureId, debugInfo.ContainsKey(f.FeatureId) ? "INCLUDED" : "MISSING"));
            }

            distMatch.SetDebugData(new DistanceBasedAstrometrySolver.PyramidDebugContext()
            {
                ResolvedStars       = debugInfo,
                ResolvedFocalLength = m_Context.SecondAstrometricFit.FitInfo.FittedFocalLength
            });
#endif

            LeastSquareFittedAstrometry fit         = null;
            LeastSquareFittedAstrometry improvedFit = null;
            PlateConstantsSolver        solver;
            distMatch.PerformMatch(out fit, out improvedFit, out solver);

            m_Context.DistanceBasedFit         = fit;
            m_Context.ImprovedDistanceBasedFit = improvedFit;

            if (fit != null)
            {
                m_Context.PlateConstants = new TangraConfig.PersistedPlateConstants
                {
                    EffectiveFocalLength = m_Context.PlateConfig.EffectiveFocalLength,
                    EffectivePixelWidth  = m_Context.PlateConfig.EffectivePixelWidth,
                    EffectivePixelHeight = m_Context.PlateConfig.EffectivePixelHeight
                };

                m_Context.ConstantsSolver = solver;

                if (improvedFit != null)
                {
                    foreach (var pair in improvedFit.FitInfo.AllStarPairs)
                    {
                        if (pair.FitInfo.ExcludedForHighResidual)
                        {
                            continue;
                        }

                        Trace.WriteLine(string.Format("{6}; {0}; {1}; {2}; {3}; ({4}\", {5}\")",
                                                      pair.RADeg, pair.DEDeg, pair.x.ToString("0.00"), pair.y.ToString("0.00"),
                                                      pair.FitInfo.ResidualRAArcSec.ToString("0.00"), pair.FitInfo.ResidualDEArcSec.ToString("0.00"),
                                                      pair.StarNo));

                        double x, y;
                        improvedFit.GetImageCoordsFromRADE(pair.RADeg, pair.DEDeg, out x, out y);
                        double dist = improvedFit.GetDistanceInArcSec(x, y, pair.x, pair.y);
                    }
                }
            }
            else
            {
                m_Context.PlateConstants = null;
            }

            return(fit);
        }