public DensityArea(
			TangentalNormalizedDirectionAstrometry astrometry,
			int maxStarsInArea,
			double raFrom, 
			double raTo, 
			double deFrom, 
			double deTo,
            List<ulong> alwaysIncludeStars)
        {
            m_RAFrom = raFrom;
            m_RATo = raTo;
            m_DEFrom = deFrom;
            m_DETo = deTo;
            MarkedStars = 0;
            m_Astrometry = astrometry;

            m_MaxStarsInArea = maxStarsInArea;
            if (alwaysIncludeStars != null) m_AlwaysIncludeStars.AddRange(alwaysIncludeStars);

            double x1, y1, x2, y2;
            astrometry.GetImageCoordsFromRADE(raFrom, deFrom, out x1, out y1);
            astrometry.GetImageCoordsFromRADE(raTo, deTo, out x2, out y2);

            m_XFrom = x1;
            m_YFrom = y1;
            m_XTo = x2;
            m_YTo = y2;

            #if ASTROMETRY_DEBUG
            Trace.Assert(x1 < x2);
            Trace.Assert(y1 < y2);
            #endif
        }
Пример #2
0
        public DensityArea(
            TangentalNormalizedDirectionAstrometry astrometry,
            int maxStarsInArea,
            double raFrom,
            double raTo,
            double deFrom,
            double deTo)
        {
            m_RAFrom     = raFrom;
            m_RATo       = raTo;
            m_DEFrom     = deFrom;
            m_DETo       = deTo;
            MarkedStars  = 0;
            m_Astrometry = astrometry;

            m_MaxStarsInArea = maxStarsInArea;

            double x1, y1, x2, y2;

            astrometry.GetImageCoordsFromRADE(raFrom, deFrom, out x1, out y1);
            astrometry.GetImageCoordsFromRADE(raTo, deTo, out x2, out y2);

            m_XFrom = x1;
            m_YFrom = y1;
            m_XTo   = x2;
            m_YTo   = y2;

#if ASTROMETRY_DEBUG
            Trace.Assert(x1 < x2);
            Trace.Assert(y1 < y2);
#endif
        }
Пример #3
0
        private DensityArea ComputeAreaFromXYPixCoords(
            TangentalNormalizedDirectionAstrometry astrometry,
            double x1, double y1, double x2, double y2)
        {
            double ra1, de1, ra2, de2;

            astrometry.GetRADEFromImageCoords(x1, y1, out ra1, out de1);
            astrometry.GetRADEFromImageCoords(x2, y2, out ra2, out de2);
            DensityArea area = new DensityArea(astrometry, MAX_STARS_IN_AREA, ra1, ra2, de1, de2);

            area.DebugResolvedStarsWithAppliedExclusions = DebugResolvedStarsWithAppliedExclusions;

#if ASTROMETRY_DEBUG
            Trace.Assert(Math.Abs(area.XFrom - x1) < 1);
            Trace.Assert(Math.Abs(area.XTo - x2) < 1);
            Trace.Assert(Math.Abs(area.YFrom - y1) < 1);
            Trace.Assert(Math.Abs(area.YTo - y2) < 1);
#endif

            double xx1, yy1, xx2, yy2;
            astrometry.GetImageCoordsFromRADE(area.RAFrom, area.DEFrom, out xx1, out yy1);
            astrometry.GetImageCoordsFromRADE(area.RATo, area.DETo, out xx2, out yy2);

#if ASTROMETRY_DEBUG
            Trace.Assert(Math.Abs(area.XFrom - xx1) < 1);
            Trace.Assert(Math.Abs(area.YFrom - yy1) < 1);
            Trace.Assert(Math.Abs(area.XTo - xx2) < 1);
            Trace.Assert(Math.Abs(area.YTo - yy2) < 1);

            Trace.Assert(Math.Abs(x1 - xx1) < 1);
            Trace.Assert(Math.Abs(y1 - yy1) < 1);
            Trace.Assert(Math.Abs(x2 - xx2) < 1);
            Trace.Assert(Math.Abs(y2 - yy2) < 1);
#endif

            return(area);
        }
Пример #4
0
        private List <DensityArea> GetSurroundingAreas(
            DensityArea middleArea,
            TangentalNormalizedDirectionAstrometry astrometry,
            double xSide,
            double ySide)
        {
            var rv = new List <DensityArea>();

            // Top 3
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom - xSide, middleArea.YFrom - ySide, middleArea.XFrom, middleArea.YFrom));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom, middleArea.YFrom - ySide, middleArea.XTo, middleArea.YFrom));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XTo, middleArea.YFrom - ySide, middleArea.XTo + xSide, middleArea.YFrom));

            // Middle 2
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom - xSide, middleArea.YFrom, middleArea.XFrom, middleArea.YTo));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XTo, middleArea.YFrom, middleArea.XTo + xSide, middleArea.YTo));

            // Bottom 3
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom - xSide, middleArea.YTo, middleArea.XFrom, middleArea.YTo + ySide));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom, middleArea.YTo, middleArea.XTo, middleArea.YTo + ySide));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XTo, middleArea.YTo, middleArea.XTo + xSide, middleArea.YTo + ySide));

            return(rv);
        }
Пример #5
0
        public void Initialize(List <ulong> alwaysIncludeStars)
        {
            if (DebugResolvedStarsWithAppliedExclusions != null)
            {
                List <ulong> debugStarIds = DebugResolvedStarsWithAppliedExclusions.Values.ToList();
                List <IStar> missingstars = m_Stars.Where(s => !debugStarIds.Contains(s.StarNo)).ToList();
                Trace.Assert(missingstars.Count == 0,
                             string.Format("There are {0} of the debug stars not found among the initial pyramid stars", missingstars.Count));
            }

            if (alwaysIncludeStars != null && alwaysIncludeStars.Count > 0)
            {
                foreach (var starNo in alwaysIncludeStars.ToArray())
                {
                    if (m_Stars.FirstOrDefault(s => s.StarNo == starNo) == null)
                    {
                        Trace.WriteLine(string.Format("Cannot locate always include star {0}. Removing ...", starNo));
                        alwaysIncludeStars.Remove(starNo);
                    }
                }
            }

            double minDE = double.MaxValue;
            double maxDE = double.MinValue;
            double minRA = double.MaxValue;
            double maxRA = double.MinValue;

            for (int i = 0; i < m_Stars.Count; i++)
            {
                IStar star = m_Stars[i];
                if (star.RADeg > maxRA)
                {
                    maxRA = star.RADeg;
                }
                if (star.RADeg < minRA)
                {
                    minRA = star.RADeg;
                }
                if (star.DEDeg > maxDE)
                {
                    maxDE = star.DEDeg;
                }
                if (star.DEDeg < minDE)
                {
                    minDE = star.DEDeg;
                }
            }

            TangentalTransRotAstrometry            astrometryBase = new TangentalTransRotAstrometry(m_Image, m_RA0Deg, m_DE0Deg, 0);
            TangentalNormalizedDirectionAstrometry astrometry     = new TangentalNormalizedDirectionAstrometry(astrometryBase);
            DensityArea middleArea = new DensityArea(astrometry, MAX_STARS_IN_AREA, m_RA0Deg - m_XAreaSideDeg / 2, m_RA0Deg + m_XAreaSideDeg / 2, m_DE0Deg - m_YAreaSideDeg / 2, m_DE0Deg + m_YAreaSideDeg / 2);

            middleArea.DebugResolvedStarsWithAppliedExclusions = DebugResolvedStarsWithAppliedExclusions;

            double xSidePlatePix = Math.Abs(middleArea.XTo - middleArea.XFrom);
            double ySidePlatePix = Math.Abs(middleArea.YTo - middleArea.YFrom);

            double raInterval = astrometryBase.GetDistanceInArcSec(middleArea.XFrom, middleArea.YMiddle, middleArea.XTo, middleArea.YMiddle) / 3600.0;
            double deInterval = astrometryBase.GetDistanceInArcSec(middleArea.XMiddle, middleArea.YFrom, middleArea.XMiddle, middleArea.YTo) / 3600.0;

            List <DensityArea> areasToCheckFurther = new List <DensityArea>();

            areasToCheckFurther.Add(middleArea);
            Areas.Add(middleArea);

            do
            {
                DensityArea[] areasToCheckNow = areasToCheckFurther.ToArray();
                areasToCheckFurther.Clear();

                foreach (DensityArea area in areasToCheckNow)
                {
                    List <DensityArea> potentiallyNewAreas = GetSurroundingAreas(area, astrometry, xSidePlatePix, ySidePlatePix);
                    foreach (DensityArea par in potentiallyNewAreas)
                    {
                        bool areadyAdded = Areas.Exists(a => a.ContainsPoint(par.XMiddle, par.YMiddle));
                        if (!areadyAdded)
                        {
                            if (par.RAFrom + raInterval < minRA ||
                                par.RATo - raInterval > maxRA ||
                                par.DEFrom + deInterval < minDE ||
                                par.DETo - deInterval > maxDE)
                            {
                                // Area not in the coordinates of interest
                            }
                            else
                            {
                                areasToCheckFurther.Add(par);
                                Areas.Add(par);
                            }
                        }
                    }
                }
            }while (areasToCheckFurther.Count > 0);

            m_Stars.Sort((s1, s2) => s1.Mag.CompareTo(s2.Mag));
            var aiss = (alwaysIncludeStars != null && alwaysIncludeStars.Count > 0) ? m_Stars.Where(s => alwaysIncludeStars.Contains(s.StarNo)).ToArray() : new IStar[0];

            Areas.ForEach(a =>
            {
                foreach (var star in m_Stars)
                {
                    a.CheckAndAddStar(star);
                    if (a.IncludedStarNos.Count >= MAX_STARS_IN_AREA)
                    {
                        break;
                    }
                }

                foreach (var ais in aiss)
                {
                    if (a.CheckAndAddStar(ais))
                    {
                        if (!a.IncludedStarNos.Contains(ais.StarNo))
                        {
                            a.IncludedStarNos.Add(ais.StarNo);
                        }
                    }
                }
            });
        }
        private List<DensityArea> GetSurroundingAreas(
            DensityArea middleArea, 
            TangentalNormalizedDirectionAstrometry astrometry, 
            double xSide, 
            double ySide,
            List<ulong> alwaysIncludeStars)
        {
            var rv = new List<DensityArea>();

            // Top 3
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom - xSide, middleArea.YFrom - ySide, middleArea.XFrom, middleArea.YFrom, alwaysIncludeStars));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom, middleArea.YFrom - ySide, middleArea.XTo, middleArea.YFrom, alwaysIncludeStars));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XTo, middleArea.YFrom - ySide, middleArea.XTo + xSide, middleArea.YFrom, alwaysIncludeStars));

            // Middle 2
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom - xSide, middleArea.YFrom, middleArea.XFrom, middleArea.YTo, alwaysIncludeStars));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XTo, middleArea.YFrom, middleArea.XTo + xSide, middleArea.YTo, alwaysIncludeStars));

            // Bottom 3
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom - xSide, middleArea.YTo, middleArea.XFrom, middleArea.YTo + ySide, alwaysIncludeStars));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XFrom, middleArea.YTo, middleArea.XTo, middleArea.YTo + ySide, alwaysIncludeStars));
            rv.Add(ComputeAreaFromXYPixCoords(astrometry, middleArea.XTo, middleArea.YTo, middleArea.XTo + xSide, middleArea.YTo + ySide, alwaysIncludeStars));

            return rv;
        }
        private DensityArea ComputeAreaFromXYPixCoords(
			TangentalNormalizedDirectionAstrometry astrometry,
			double x1, double y1, double x2, double y2,
            List<ulong> alwaysIncludeStars)
        {
            double ra1, de1, ra2, de2;
            astrometry.GetRADEFromImageCoords(x1, y1, out ra1, out de1);
            astrometry.GetRADEFromImageCoords(x2, y2, out ra2, out de2);
            DensityArea area = new DensityArea(astrometry, MAX_STARS_IN_AREA, ra1, ra2, de1, de2, alwaysIncludeStars);
            area.DebugResolvedStarsWithAppliedExclusions = DebugResolvedStarsWithAppliedExclusions;

            #if ASTROMETRY_DEBUG
            Trace.Assert(Math.Abs(area.XFrom - x1) < 1);
            Trace.Assert(Math.Abs(area.XTo - x2) < 1);
            Trace.Assert(Math.Abs(area.YFrom - y1) < 1);
            Trace.Assert(Math.Abs(area.YTo - y2) < 1);
            #endif

            double xx1, yy1, xx2, yy2;
            astrometry.GetImageCoordsFromRADE(area.RAFrom, area.DEFrom, out xx1, out yy1);
            astrometry.GetImageCoordsFromRADE(area.RATo, area.DETo, out xx2, out yy2);

            #if ASTROMETRY_DEBUG
            Trace.Assert(Math.Abs(area.XFrom - xx1) < 1);
            Trace.Assert(Math.Abs(area.YFrom - yy1) < 1);
            Trace.Assert(Math.Abs(area.XTo - xx2) < 1);
            Trace.Assert(Math.Abs(area.YTo - yy2) < 1);

            Trace.Assert(Math.Abs(x1 - xx1) < 1);
            Trace.Assert(Math.Abs(y1 - yy1) < 1);
            Trace.Assert(Math.Abs(x2 - xx2) < 1);
            Trace.Assert(Math.Abs(y2 - yy2) < 1);
            #endif

            return area;
        }
        public void Initialize(List<ulong> alwaysIncludeStars)
        {
            if (DebugResolvedStarsWithAppliedExclusions != null)
            {
                List<ulong> debugStarIds = DebugResolvedStarsWithAppliedExclusions.Values.ToList();
                List<IStar> missingstars = m_Stars.Where(s => !debugStarIds.Contains(s.StarNo)).ToList();
                Trace.Assert(missingstars.Count == 0,
                    string.Format("There are {0} of the debug stars not found among the initial pyramid stars", missingstars.Count));
            }

            double minDE = double.MaxValue;
            double maxDE = double.MinValue;
            double minRA = double.MaxValue;
            double maxRA = double.MinValue;
            double averageRA = 0;
            double averageDE = 0;
            for (int i = 0; i < m_Stars.Count; i++)
            {
                IStar star = m_Stars[i];
                if (star.RADeg > maxRA) maxRA = star.RADeg;
                if (star.RADeg < minRA) minRA = star.RADeg;
                if (star.DEDeg > maxDE) maxDE = star.DEDeg;
                if (star.DEDeg < minDE) minDE = star.DEDeg;

                averageDE += star.DEDeg;
                averageRA += star.RADeg;
            }

            averageDE /= m_Stars.Count;
            averageRA /= m_Stars.Count;

            m_RA0Deg = averageRA;
            m_DE0Deg = averageDE;

            TangentalTransRotAstrometry astrometryBase = new TangentalTransRotAstrometry(m_Image, averageRA, averageDE, 0);
            TangentalNormalizedDirectionAstrometry astrometry = new TangentalNormalizedDirectionAstrometry(astrometryBase);
            DensityArea middleArea = new DensityArea(astrometry, MAX_STARS_IN_AREA, averageRA - m_XAreaSideDeg / 2, averageRA + m_XAreaSideDeg / 2, averageDE - m_YAreaSideDeg / 2, averageDE + m_YAreaSideDeg / 2, alwaysIncludeStars);
            middleArea.DebugResolvedStarsWithAppliedExclusions = DebugResolvedStarsWithAppliedExclusions;

            double xSidePlatePix = Math.Abs(middleArea.XTo - middleArea.XFrom);
            double ySidePlatePix = Math.Abs(middleArea.YTo - middleArea.YFrom);

            double raInterval = astrometryBase.GetDistanceInArcSec(middleArea.XFrom, middleArea.YMiddle, middleArea.XTo, middleArea.YMiddle) / 3600.0;
            double deInterval = astrometryBase.GetDistanceInArcSec(middleArea.XMiddle, middleArea.YFrom, middleArea.XMiddle, middleArea.YTo) / 3600.0;

            List<DensityArea> areasToCheckFurther = new List<DensityArea>();
            areasToCheckFurther.Add(middleArea);
            Areas.Add(middleArea);

            do
            {
                DensityArea[] areasToCheckNow = areasToCheckFurther.ToArray();
                areasToCheckFurther.Clear();

                foreach (DensityArea area in areasToCheckNow)
                {
                    List<DensityArea> potentiallyNewAreas = GetSurroundingAreas(area, astrometry, xSidePlatePix, ySidePlatePix, alwaysIncludeStars);
                    foreach(DensityArea par in potentiallyNewAreas)
                    {
                        bool areadyAdded = Areas.Exists(a => a.ContainsPoint(par.XMiddle, par.YMiddle));
                        if (!areadyAdded)
                        {
                            if (par.RAFrom + raInterval < minRA ||
                                par.RATo - raInterval > maxRA ||
                                par.DEFrom + deInterval < minDE ||
                                par.DETo - deInterval > maxDE)
                            {
                                // Area not in the coordinates of interest
                            }
                            else
                            {
                                areasToCheckFurther.Add(par);
                                Areas.Add(par);
                            }
                        }
                    }
                }
            }
            while (areasToCheckFurther.Count > 0);

            m_Stars.Sort((s1, s2) => s1.Mag.CompareTo(s2.Mag));
            int maxStars = MAX_STARS_IN_AREA + (alwaysIncludeStars != null ? alwaysIncludeStars.Count : 0);
            Areas.ForEach(a =>
            {
                foreach (var star in m_Stars)
                {
                    a.CheckAndAddStar(star);
                    if (a.IncludedStarNos.Count >= maxStars)
                        break;
                }
               });
        }