示例#1
0
        private PlateConstantsFit LinearFitWithExcludingResiduals(FitOrder fitOrder, int minNumStars, double maxResidualLimit, out PlateConstantsFit firstPlateConstantsFit)
        {
            bool hasBadStars;
            PlateConstantsFit fit;

            firstPlateConstantsFit = null;

            for (int i = 0; i < m_Pairs.Count; i++)
            {
                m_Pairs[i].FitInfo.ExcludedForHighResidual = false;
            }

            do
            {
                hasBadStars = false;
                fit         = PlateConstantsFit.LeastSquareSolve(m_Pairs, m_Tangent_RA0, m_Tangent_DE0, fitOrder, minNumStars);
                if (firstPlateConstantsFit == null && fit != null)
                {
                    firstPlateConstantsFit = fit;
                }

                int    starToExclude = -1;
                double maxResidual   = 0;

                for (int i = 0; i < m_Pairs.Count; i++)
                {
                    if (!m_Pairs[i].FitInfo.UsedInSolution)
                    {
                        continue;
                    }

                    double residual =
                        Math.Sqrt(m_Pairs[i].FitInfo.ResidualRAArcSec * m_Pairs[i].FitInfo.ResidualRAArcSec +
                                  m_Pairs[i].FitInfo.ResidualDEArcSec * m_Pairs[i].FitInfo.ResidualDEArcSec);

                    if (residual > maxResidual)
                    {
                        maxResidual   = residual;
                        starToExclude = i;
                    }
                }

                // If any of the residuals are greater than 1px, then remove those stars and compute again
                if (maxResidual > maxResidualLimit &&
                    starToExclude != -1)
                {
                    m_Pairs[starToExclude].FitInfo.UsedInSolution          = false;
                    m_Pairs[starToExclude].FitInfo.ExcludedForHighResidual = true;
                    hasBadStars = true;
                    continue;
                }
            }while (hasBadStars && fit != null);

            return(fit);
        }
        public LeastSquareFittedAstrometry(
			AstroPlate image,
			double RA0Deg, double DE0Deg,
			PlateConstantsFit solution)
        {
            m_Image = image;

            this.m_RA0Deg = RA0Deg;
            this.m_DE0Deg = DE0Deg;

            m_SolvedConstants = solution;
            m_Variance = solution.Variance;
            m_StdDevRAArcSec = Math.Sqrt(solution.VarianceArcSecRA);
            m_StdDevDEArcSec = Math.Sqrt(solution.VarianceArcSecDE);
        }
示例#3
0
        public LeastSquareFittedAstrometry(
            AstroPlate image,
            double RA0Deg, double DE0Deg,
            PlateConstantsFit solution)
        {
            m_Image = image;

            this.m_RA0Deg = RA0Deg;
            this.m_DE0Deg = DE0Deg;

            m_SolvedConstants = solution;
            m_Variance        = solution.Variance;
            m_StdDevRAArcSec  = Math.Sqrt(solution.VarianceArcSecRA);
            m_StdDevDEArcSec  = Math.Sqrt(solution.VarianceArcSecDE);

            m_UncertaintyRAArcSec = solution.UncertaintyArcSecRA;
            m_UncertaintyDEArcSec = solution.UncertaintyArcSecDE;
        }
        public LeastSquareFittedAstrometry(SerializationInfo info, StreamingContext context)
        {
            m_RA0Deg = info.GetDouble("m_RA0Deg");
            m_DE0Deg = info.GetDouble("m_DE0Deg");

            byte[] data = (byte[])info.GetValue("m_Image", typeof(byte[]));

            BinaryFormatter fmt = new BinaryFormatter();
            using (MemoryStream mem = new MemoryStream(data))
            {
                m_Image = (AstroPlate)fmt.Deserialize(mem);
            }

            data = (byte[])info.GetValue("m_SolvedConstants", typeof(byte[]));
            using (MemoryStream mem = new MemoryStream(data))
            {
                m_SolvedConstants = (PlateConstantsFit)fmt.Deserialize(mem);
            }
        }
示例#5
0
        public LeastSquareFittedAstrometry(SerializationInfo info, StreamingContext context)
        {
            m_RA0Deg = info.GetDouble("m_RA0Deg");
            m_DE0Deg = info.GetDouble("m_DE0Deg");

            byte[] data = (byte[])info.GetValue("m_Image", typeof(byte[]));

            BinaryFormatter fmt = new BinaryFormatter();

            using (MemoryStream mem = new MemoryStream(data))
            {
                m_Image = (AstroPlate)fmt.Deserialize(mem);
            }

            data = (byte[])info.GetValue("m_SolvedConstants", typeof(byte[]));
            using (MemoryStream mem = new MemoryStream(data))
            {
                m_SolvedConstants = (PlateConstantsFit)fmt.Deserialize(mem);
            }
        }
示例#6
0
        public static LeastSquareFittedAstrometry FromReflectedObject(object reflObj)
        {
            var rv = new LeastSquareFittedAstrometry();

            rv.m_RA0Deg         = StarMap.GetPropValue <double>(reflObj, "m_RA0Deg");
            rv.m_DE0Deg         = StarMap.GetPropValue <double>(reflObj, "m_DE0Deg");
            rv.m_Variance       = StarMap.GetPropValue <double>(reflObj, "m_Variance");
            rv.m_StdDevRAArcSec = StarMap.GetPropValue <double>(reflObj, "m_StdDevRAArcSec");
            rv.m_StdDevDEArcSec = StarMap.GetPropValue <double>(reflObj, "m_StdDevDEArcSec");

            object image = StarMap.GetPropValue <object>(reflObj, "m_Image");

            rv.m_Image = AstroPlate.FromReflectedObject(image);

            object constants = StarMap.GetPropValue <object>(reflObj, "m_SolvedConstants");

            if (constants != null)
            {
                rv.m_SolvedConstants = PlateConstantsFit.FromReflectedObject(constants);
            }

            return(rv);
        }
示例#7
0
        private PlateConstantsFit LinearFitWithExcludingResiduals(FitOrder fitOrder, int minNumStars, double maxResidualLimit, out PlateConstantsFit firstPlateConstantsFit)
        {
            bool hasBadStars;
            PlateConstantsFit fit;
            firstPlateConstantsFit = null;

            for (int i = 0; i < m_Pairs.Count; i++)
                m_Pairs[i].FitInfo.ExcludedForHighResidual = false;

            do
            {
                hasBadStars = false;
                fit = PlateConstantsFit.LeastSquareSolve(m_Pairs, m_Tangent_RA0, m_Tangent_DE0, fitOrder, minNumStars);
                if (firstPlateConstantsFit == null && fit != null) firstPlateConstantsFit = fit;

                int starToExclude = -1;
                double maxResidual = 0;

                for (int i = 0; i < m_Pairs.Count; i++)
                {
                    if (!m_Pairs[i].FitInfo.UsedInSolution) continue;

                    double residual =
                        Math.Sqrt(m_Pairs[i].FitInfo.ResidualRAArcSec * m_Pairs[i].FitInfo.ResidualRAArcSec +
                                  m_Pairs[i].FitInfo.ResidualDEArcSec * m_Pairs[i].FitInfo.ResidualDEArcSec);

                    if (residual > maxResidual)
                    {
                        maxResidual = residual;
                        starToExclude = i;
                    }
                }

                // If any of the residuals are greater than 1px, then remove those stars and compute again
                if (maxResidual > maxResidualLimit &&
                    starToExclude != -1)
                {
                    m_Pairs[starToExclude].FitInfo.UsedInSolution = false;
                    m_Pairs[starToExclude].FitInfo.ExcludedForHighResidual = true;
                    hasBadStars = true;
                    continue;
                }

            }
            while (hasBadStars && fit != null);

            return fit;
        }
示例#8
0
        private LeastSquareFittedAstrometry SolveWithLinearRegression(FitOrder fitOrder, int minNumberOfStars, double maxResidual, bool upgradeIfPossible, out LeastSquareFittedAstrometry firstFit)
        {
            bool failed = false;

            try
            {
                PlateConstantsFit firstPlateConstantsFit = null;

                if (!upgradeIfPossible)
                {
                    PlateConstantsFit bestFit = LinearFitWithExcludingResiduals(fitOrder, minNumberOfStars, maxResidual, out firstPlateConstantsFit);

                    firstFit = firstPlateConstantsFit != null ? new LeastSquareFittedAstrometry(m_PlateConfig, m_Tangent_RA0, m_Tangent_DE0, firstPlateConstantsFit) : null;

                    if (bestFit != null)
                    {
                        return(new LeastSquareFittedAstrometry(m_PlateConfig, m_Tangent_RA0, m_Tangent_DE0, bestFit));
                    }
                }
                else
                {
                    // less than 11 stars - do a linear fit
                    // between 12 and 19 - do a quadratic fit
                    // more than 20 - do a cubic fit

                    PlateConstantsFit bestFit = null;

                    int numStars = m_Pairs.Count;
                    if (m_Pairs.Count >= MIN_STARS_FOR_CUBIC_FIT)
                    {
                        bestFit = LinearFitWithExcludingResiduals(FitOrder.Cubic, minNumberOfStars, maxResidual, out firstPlateConstantsFit);

                        if (bestFit != null)
                        {
                            numStars = bestFit.FitInfo.NumberOfStarsUsedInSolution();
                        }
                        else
                        {
                            numStars = MIN_STARS_FOR_CUBIC_FIT - 1;
                        }
                    }


                    if (numStars >= MIN_STARS_FOR_QUADRATIC_FIT && numStars < MIN_STARS_FOR_CUBIC_FIT)
                    {
                        bestFit = LinearFitWithExcludingResiduals(FitOrder.Quadratic, minNumberOfStars, maxResidual, out firstPlateConstantsFit);

                        if (bestFit != null)
                        {
                            numStars = bestFit.FitInfo.NumberOfStarsUsedInSolution();
                        }
                        else
                        {
                            numStars = MIN_STARS_FOR_QUADRATIC_FIT - 1;
                        }
                    }

                    if (numStars < MIN_STARS_FOR_QUADRATIC_FIT)
                    {
                        bestFit = LinearFitWithExcludingResiduals(FitOrder.Linear, minNumberOfStars, maxResidual, out firstPlateConstantsFit);
                    }

                    firstFit = firstPlateConstantsFit != null ? new LeastSquareFittedAstrometry(m_PlateConfig, m_Tangent_RA0, m_Tangent_DE0, firstPlateConstantsFit) : null;

                    if (bestFit != null)
                    {
                        return(new LeastSquareFittedAstrometry(m_PlateConfig, m_Tangent_RA0, m_Tangent_DE0, bestFit));
                    }
                }

                failed = true;
                return(null);
            }
            finally
            {
                m_IncludedInSolution.Clear();
                m_ExcludedForBadResiduals.Clear();

                for (int i = 0; i < m_Pairs.Count; i++)
                {
#if ASTROMETRY_DEBUG
                    Trace.Assert(!m_IncludedInSolution.ContainsKey(m_Pairs[i].StarNo));
#endif
                    m_IncludedInSolution.Add(m_Pairs[i].StarNo, m_Pairs[i].FitInfo.UsedInSolution);

#if ASTROMETRY_DEBUG
                    Trace.Assert(!m_ExcludedForBadResiduals.ContainsKey(m_Pairs[i].StarNo));
#endif
                    m_ExcludedForBadResiduals.Add(m_Pairs[i].StarNo, m_Pairs[i].FitInfo.ExcludedForHighResidual);
                }

                if (failed)
                {
                    if (TangraConfig.Settings.TraceLevels.PlateSolving.TraceInfo())
                    {
                        Trace.WriteLine(string.Format("Solution LeastSquareFit failed. {0} included stars, {1} excluded for high residuals.", m_IncludedInSolution.Count, m_ExcludedForBadResiduals.Count));
                    }
                }
            }
        }