예제 #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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        public static PlateConstantsFit LeastSquareSolve(
            List <PlateConstStarPair> pairs,
            double ra0Deg,
            double de0Deg,
            FitOrder fitOrder,
            int minNumberOfStars)
        {
            if (fitOrder == FitOrder.Linear)
            {
                PlateConstantsLinearFit linearFit = new PlateConstantsLinearFit(pairs);
                try
                {
                    if (linearFit.LeastSquareSolve(ra0Deg, de0Deg, minNumberOfStars))
                    {
                        return(linearFit);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("{0} exception during PlateConstantsFit.", ex.GetType().Name);
                    return(null);
                }
            }

            if (fitOrder == FitOrder.Quadratic)
            {
                PlateConstantsQadraticFit qadraticFit = new PlateConstantsQadraticFit(pairs);
                try
                {
                    if (qadraticFit.LeastSquareSolve(ra0Deg, de0Deg, minNumberOfStars))
                    {
                        return(qadraticFit);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("{0} exception during PlateConstantsFit.", ex.GetType().Name);
                    return(null);
                }
            }

            return(null);
        }
예제 #4
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));
                }
            }
        }
예제 #5
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;
        }
예제 #6
0
 public LeastSquareFittedAstrometry SolveWithLinearRegression(FitOrder fitOrder, int minNumberOfStars, double maxResidual, out LeastSquareFittedAstrometry firstFit)
 {
     return SolveWithLinearRegression(fitOrder, minNumberOfStars, maxResidual, false, out firstFit);
 }
예제 #7
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));
                    }
                }
            }
        }
예제 #8
0
 public LeastSquareFittedAstrometry SolveWithLinearRegression(FitOrder fitOrder, int minNumberOfStars, double maxResidual, out LeastSquareFittedAstrometry firstFit)
 {
     return(SolveWithLinearRegression(fitOrder, minNumberOfStars, maxResidual, false, out firstFit));
 }
예제 #9
0
        public static PlateConstantsFit LeastSquareSolve(
			List<PlateConstStarPair> pairs,
			double ra0Deg,
			double de0Deg,
			FitOrder fitOrder,
			int minNumberOfStars)
        {
            if (fitOrder == FitOrder.Linear)
            {
                PlateConstantsLinearFit linearFit = new PlateConstantsLinearFit(pairs);
                try
                {
                    if (linearFit.LeastSquareSolve(ra0Deg, de0Deg, minNumberOfStars))
                        return linearFit;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("{0} exception during PlateConstantsFit.", ex.GetType().Name);
                    return null;
                }
            }

            if (fitOrder == FitOrder.Quadratic)
            {
                PlateConstantsQadraticFit qadraticFit = new PlateConstantsQadraticFit(pairs);
                try
                {
                    if (qadraticFit.LeastSquareSolve(ra0Deg, de0Deg, minNumberOfStars))
                        return qadraticFit;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("{0} exception during PlateConstantsFit.", ex.GetType().Name);
                    return null;
                }
            }

            return null;
        }
예제 #10
0
        /// <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;
        }