示例#1
0
        //*** Optimize Exposure determines the best exposure time for the target star
        public static double OptimizeExposure()
        {
            //Get the best exposure time based on the target ADU
            //
            //Subrountine loops up to 4 times, taking an image, and calulating a new exposure that comes closest to meeting ADU goal
            //
            //Take an image with current exposure set from last guider exposure
            //If the max ADu is 100 or less, then there was no star at all.  Double the exposure upto MaxGuiderExposure
            //If the returned exposure is 64000 or more, then the star was probably saturated.  Halve the exposure down to no less than the minguider exposure.
            //If not within 20% of targetADU, then recalculate and rerun
            //If within 20% then recalculate and done, then update the exposure settings and return the exposure
            //
            LogEvent       lg          = new LogEvent();
            SessionControl openSession = new SessionControl();
            TargetPlan     tPlan       = new TargetPlan(openSession.CurrentTargetName);
            double         exposure    = tPlan.GuideExposure;
            double         tgtADU      = tPlan.GuideStarADU;
            double         maxExposure = tPlan.MaximumGuiderExposure;
            double         minExposure = tPlan.MinimumGuiderExposure;

            //set the maximum number of iterations based on the maximum number of halves or doubles that could be performed.
            lg.LogIt("Attempting to find optimal guide star exposure");

            //Only take at max 4 shots at getting a good exposure, otherwise return the max or min
            for (int i = 0; i < 4; i++)
            {
                //Start at the initial exposure.  This is a minimum.
                //Take a subframe image
                //Get maximum pixels ADU
                //
                double maxPixel = GetGuideStarADU(exposure);  //Uses SexTractor engine
                lg.LogIt("Guide star ADU at " + maxPixel.ToString())
                ;
                //Check through too low, too high and just right
                if (maxPixel < 500)  //way too low
                {
                    exposure = LimitMaxMin((exposure * 2), maxExposure, minExposure);
                    lg.LogIt("Guide Star exposure too low. Reset to " + exposure.ToString("0.00") + " secs");
                }
                else if (maxPixel > 60000.0)  //too close to saturation
                {
                    exposure = LimitMaxMin((exposure / 2), maxExposure, minExposure);
                    lg.LogIt("Guide Star exposure set too high. Reset to " + exposure.ToString("0.00") + " secs");
                }
                else if (!(NHUtil.CloseEnough(maxPixel, tgtADU, 20.0)))  //if not quite close enought recalculate exposure try again
                {
                    if (maxPixel > tgtADU)
                    {
                        exposure = LimitMaxMin(((tgtADU / maxPixel) * exposure), maxExposure, minExposure);
                        lg.LogIt("Guide Star ADU is " + maxPixel.ToString("0") + ": Exposure too high at " + exposure.ToString("0.00") + " secs");
                    }
                    else
                    {
                        exposure = LimitMaxMin(((tgtADU / maxPixel) * exposure), maxExposure, minExposure);
                        lg.LogIt("Guide Star ADU is " + maxPixel.ToString("0") + ": Exposure too low at " + exposure.ToString("0.00") + " secs");
                    }
                }
                else
                {
                    exposure = LimitMaxMin(((tgtADU / maxPixel) * exposure), maxExposure, minExposure);
                    break;
                }
            }
            lg.LogIt("Guide Star target exposure set to " + exposure.ToString("0.00") + " secs");
            return(LimitMaxMin(exposure, maxExposure, minExposure));
        }