//SexTractor-based method for getting the ADU of a guide star public static double GetGuideStarADU(double exposure) { //Determines the ADU for the X/Y centroid of the maximum FWHM star in a subframe // //Take a subframe image on the guider using TSX guide star coordinates and trackbox size LogEvent lg = new LogEvent(); SessionControl openSession = new SessionControl(); TargetPlan tPlan = new TargetPlan(openSession.CurrentTargetName); lg.LogIt("Creating Guider Subframe Image"); AstroImage asti = new AstroImage { Camera = AstroImage.CameraType.Guider, SubFrame = 1, Frame = AstroImage.ImageType.Light, BinX = tPlan.GuiderBinning, BinY = tPlan.GuiderBinning, Delay = 0, Exposure = exposure }; //Set image reduction if (tPlan.GuiderAutoDarkEnabled) { asti.ImageReduction = AstroImage.ReductionType.AutoDark; } else { asti.ImageReduction = AstroImage.ReductionType.None; } TSXLink.Camera gCam = new TSXLink.Camera(asti) { AutoSaveOn = 1//Turn on autosave so we can extract a star inventory via ShowInventory() }; //Center up AO, just in case and if enabled if (tPlan.AOEnabled) { gCam.CenterAO(); } //Compute the subframe from the trackbox size int sizeX = gCam.TrackBoxX; int sizeY = gCam.TrackBoxY; gCam.SubframeTop = (int)(tPlan.GuideStarY * tPlan.GuiderBinning) - (sizeY / 2); gCam.SubframeBottom = (int)(tPlan.GuideStarY * tPlan.GuiderBinning) + (sizeY / 2); gCam.SubframeLeft = (int)(tPlan.GuideStarX * tPlan.GuiderBinning) - (sizeX / 2); gCam.SubframeRight = (int)(tPlan.GuideStarX * tPlan.GuiderBinning) + (sizeX / 2); //Take an image f int tstat = gCam.GetImage(); if (tstat != 0) { lg.LogIt("Autoguider Image Error: " + tstat.ToString()); return(0); } lg.LogIt("Guider Subframe image successful"); //Next step is to generate the collection of stars in the subframe TSXLink.SexTractor sEx = new TSXLink.SexTractor(); int xStat = sEx.SourceExtractGuider(); lg.LogIt("Light source extraction complete"); List <double> FWHMlist = sEx.GetSourceExtractionList(TSXLink.SexTractor.SourceExtractionType.sexFWHM); List <double> CenterX = sEx.GetSourceExtractionList(TSXLink.SexTractor.SourceExtractionType.sexX); List <double> CenterY = sEx.GetSourceExtractionList(TSXLink.SexTractor.SourceExtractionType.sexY); int iMax = sEx.GetListLargest(FWHMlist); double maxStarADU = 0; try { maxStarADU = sEx.GetPixelADU((int)CenterX[iMax], (int)CenterY[iMax]); } catch (Exception ex) { lg.LogIt("Light Source error -- no stars?"); } if (maxStarADU == 0) { maxStarADU = gCam.MaximumPixel; } return(maxStarADU); }
//Fires up the autoguider including picking a star and optimizing the exposure time public static void AutoGuideStart() { //Turns on autoguiding, assuming that everything has been initialized correctly LogEvent lg = new LogEvent(); SessionControl openSession = new SessionControl(); TargetPlan tPlan = new TargetPlan(openSession.CurrentTargetName); double autoguideExposureTime = tPlan.GuideExposure; lg.LogIt("Starting Autoguiding"); LogVectors(); AstroImage asti = new AstroImage { Camera = AstroImage.CameraType.Guider, BinX = tPlan.GuiderBinning, BinY = tPlan.GuiderBinning, Frame = AstroImage.ImageType.Light, Exposure = tPlan.GuideExposure }; //Set image reduction if (tPlan.GuiderAutoDarkEnabled) { asti.ImageReduction = AstroImage.ReductionType.AutoDark; } else { asti.ImageReduction = AstroImage.ReductionType.None; } //Compute delay based on guider cycle time. Zero means no delay; double agDelay = tPlan.GuiderCycleTime; if (agDelay > asti.Exposure) { asti.Delay = agDelay - asti.Exposure; } else { asti.Delay = 0; } //Create new guider object for running the guider //then center the AO, if enabled TSXLink.Camera gCam = new TSXLink.Camera(asti) { AutoSaveOn = 0 } ; if (tPlan.AOEnabled) { try { gCam.CenterAO(); } catch (Exception e) { lg.LogIt("AO Centering Error: " + e.Message); } } //guide star and exposure should have already been run //turn on guiding int agstat = gCam.AutoGuiderOn(); if (agstat != 0) { lg.LogIt("Autoguide start up error " + agstat.ToString()); } lg.LogIt("Autoguiding Started"); }
//*** SetAutoGuideStar picks a guide star and places a subframe around it public static bool SetAutoGuideStar() { // Subroutine takes a picture, picks a guide star, computes a subframe to put around it, // loads the location and subframe into the autoguider // // Subroutine picks a guide star, computes a subframe to put around it based on current TSX settings // and loads the location and subframe into the autoguider // int MagWeight = 1; int FWHMWeight = 1; int ElpWeight = 1; int ClsWeight = 1; // Algorithm: // // Compute optimality and normalizaton values (see below) // Eliminate all points near edge and with neighbors // Compute optimality differential and normalize, and add // Select best (least sum) point // // Normalized deviation from optimal where optimal is the best value for each of the four catagories: // Magnitude optimal is lowest magnitude // FWHM optimal is average FWHM // Ellipticity optimal is lowest ellipticity // Class optimal is lowest class // // Normalized means adjusted against the range of highest to lowest becomes 1 to 0, unless there is only one datapoint // // LogEvent lg = new LogEvent(); SessionControl openSession = new SessionControl(); TargetPlan tPlan = new TargetPlan(openSession.CurrentTargetName); lg.LogIt("Finding guide star coordinates"); AstroImage asti = new AstroImage { Camera = AstroImage.CameraType.Guider, SubFrame = 0, Frame = AstroImage.ImageType.Light, BinX = tPlan.GuiderBinning, BinY = tPlan.GuiderBinning, Delay = 0, Exposure = tPlan.GuideExposure }; //Set image reduction if (tPlan.GuiderAutoDarkEnabled) { asti.ImageReduction = AstroImage.ReductionType.AutoDark; } else { asti.ImageReduction = AstroImage.ReductionType.None; } TSXLink.Camera guider = new TSXLink.Camera(asti) { AutoSaveOn = 1 }; //Center AO, if configured if (tPlan.AOEnabled) { guider.CenterAO(); } //Take an image f int camResult = guider.GetImage(); //acquire the current trackbox size (need it later) int TrackBoxSize = guider.TrackBoxX; TSXLink.SexTractor tsex = new TSXLink.SexTractor(); try { int sStat = tsex.SourceExtractGuider(); } catch (Exception ex) { // Just close up, TSX will spawn error window lg.LogIt("Some problem with guider image: " + ex.Message); tsex.Close(); return(false); } int Xsize = tsex.WidthInPixels; int Ysize = tsex.HeightInPixels; // Collect astrometric light source data from the image linking into single index arrays: // magnitude, fmhm, ellipsicity, x and y positionc // double[] MagArr = tsex.GetSourceExtractionArray(TSXLink.SexTractor.SourceExtractionType.sexMagnitude); int starCount = MagArr.Length; if (starCount == 0) { lg.LogIt("No astrometric sources found"); tsex.Close(); return(false); } double[] FWHMArr = tsex.GetSourceExtractionArray(TSXLink.SexTractor.SourceExtractionType.sexFWHM); double[] XPosArr = tsex.GetSourceExtractionArray(TSXLink.SexTractor.SourceExtractionType.sexX); double[] YPosArr = tsex.GetSourceExtractionArray(TSXLink.SexTractor.SourceExtractionType.sexY); double[] ElpArr = tsex.GetSourceExtractionArray(TSXLink.SexTractor.SourceExtractionType.sexEllipticity); double[] ClsArr = tsex.GetSourceExtractionArray(TSXLink.SexTractor.SourceExtractionType.sexClass); // Get some useful statistics // Max and min magnitude // Max and min FWHM // Max and min ellipticity // max and min class // Average FWHM double maxMag = MagArr[0]; double minMag = MagArr[0]; double maxFWHM = FWHMArr[0]; double minFWHM = FWHMArr[0]; double maxElp = ElpArr[0]; double minElp = ElpArr[0]; double maxCls = ClsArr[0]; double minCls = ClsArr[0]; double avgFWHM = 0; double avgMag = 0; for (int i = 0; i < starCount; i++) { if (MagArr[i] < minMag) { minMag = MagArr[i]; } if (MagArr[i] > maxMag) { maxMag = MagArr[i]; } if (FWHMArr[i] < minFWHM) { minFWHM = FWHMArr[i]; } if (FWHMArr[i] > maxFWHM) { maxFWHM = FWHMArr[i]; } if (ElpArr[i] < minElp) { minElp = ElpArr[i]; } if (ElpArr[i] > maxElp) { maxElp = ElpArr[i]; } if (ClsArr[i] < minCls) { minCls = ClsArr[i]; } if (ClsArr[i] > maxCls) { maxCls = ClsArr[i]; } avgFWHM += FWHMArr[i]; avgMag += MagArr[i]; } avgFWHM /= starCount; avgMag /= starCount; // Create a set of "best" values double optMag = minMag; // Magnitudes increase with negative values double optFWHM = avgFWHM; // Looking for the closest to maximum FWHM double optElp = minElp; // Want the minimum amount of elongation double optCls = maxCls; // 1 = star,0 = galaxy // Create a set of ranges double rangeMag = maxMag - minMag; double rangeFWHM = maxFWHM - minFWHM; double rangeElp = maxElp - minElp; double rangeCls = maxCls - minCls; // Create interrum variables for weights double normMag; double normFWHM; double normElp; double normCls; // Count keepers for statistics int SourceCount = 0; int EdgeCount = 0; int NeighborCount = 0; int edgekeepout; // Create a selection array to store normilized and summed difference values double[] NormArr = new double[starCount]; // Convert all points to normalized differences, checking for zero ranges (e.g.single or identical data points) for (int i = 0; i < starCount; i++) { if (rangeMag != 0) { normMag = 1 - Math.Abs(optMag - MagArr[i]) / rangeMag; } else { normMag = 0; } if (rangeFWHM != 0) { normFWHM = 1 - Math.Abs(optFWHM - FWHMArr[i]) / rangeFWHM; } else { normFWHM = 0; } if (rangeElp != 0) { normElp = 1 - Math.Abs(optElp - ElpArr[i]) / rangeElp; } else { normElp = 0; } if (rangeCls != 0) { normCls = 1 - Math.Abs(optCls - ClsArr[i]) / rangeCls; } else { normCls = 0; } // Sum the normalized points, weight and store value NormArr[i] = (normMag * MagWeight) + (normFWHM * FWHMWeight) + (normElp * ElpWeight) + (normCls * ClsWeight); SourceCount += 1; // Remove neighbors and edge liers edgekeepout = openSession.GuideStarEdgeMargin; if (IsOnEdge((int)XPosArr[i], (int)YPosArr[i], Xsize, Ysize, edgekeepout)) { NormArr[i] = -1; } else { for (int j = i + 1; j < starCount - 1; j++) { if (IsNeighbor((int)XPosArr[i], (int)YPosArr[i], (int)XPosArr[j], (int)YPosArr[j], TrackBoxSize)) { NormArr[i] = -2; } } } } // Now find the best remaining entry int bestOne = 0; for (int i = 0; i < starCount; i++) { if (NormArr[i] > NormArr[bestOne]) { bestOne = i; } } guider.GuideStarX = XPosArr[bestOne] * asti.BinX; guider.GuideStarY = YPosArr[bestOne] * asti.BinY; asti.SubframeLeft = (int)(XPosArr[bestOne] - (TrackBoxSize / 2)) * asti.BinX; asti.SubframeRight = (int)(XPosArr[bestOne] + (TrackBoxSize / 2)) * asti.BinX; asti.SubframeTop = (int)(YPosArr[bestOne] - (TrackBoxSize / 2)) * asti.BinY; asti.SubframeBottom = (int)(YPosArr[bestOne] + (TrackBoxSize / 2)) * asti.BinY; if (NormArr[bestOne] != -1) { tPlan.GuideStarX = guider.GuideStarX / asti.BinX; tPlan.GuideStarY = guider.GuideStarY / asti.BinY; lg.LogIt("Guide star coordinates set"); tsex.Close(); return(true); } else { // run statistics -- only if (total failure for (int i = 0; i < SourceCount; i++) { if (NormArr[i] == -1) { EdgeCount += 1; } if (NormArr[i] == -2) { NeighborCount += 1; } } lg.LogIt("No Guide star found out of " + SourceCount.ToString() + " stars, " + NeighborCount.ToString() + " had neighbors and " + EdgeCount.ToString() + " were on the edge."); lg.LogIt("No Guide star coordinates set"); tsex.Close(); return(false); } }
//Execute TSX_AutoGuide class // Image guider camera // Calibrate autoguide // Autoguide // Autoguide Profiler //MaxPixel-based method for getting the ADU of a guide star public static double GuideStarMaxPixel(double exposure) { //Take a subframe image on the guider, assuming it has been already set LogEvent lg = new LogEvent(); SessionControl openSession = new SessionControl(); TargetPlan tPlan = new TargetPlan(openSession.CurrentTargetName); lg.LogIt("Creating Guider Subframe Image"); AstroImage asti = new AstroImage { Camera = AstroImage.CameraType.Guider, Frame = AstroImage.ImageType.Light, BinX = tPlan.GuiderBinning, BinY = tPlan.GuiderBinning, SubFrame = 1, Delay = 0, Exposure = exposure }; //Set image reduction if (tPlan.GuiderAutoDarkEnabled) { asti.ImageReduction = AstroImage.ReductionType.AutoDark; } else { asti.ImageReduction = AstroImage.ReductionType.None; } //Create camera object and turn turn off autosave, if on TSXLink.Camera gCam = new TSXLink.Camera(asti) { AutoSaveOn = 0 }; //Center up AO, just in case and if enabled if (tPlan.AOEnabled) { gCam.CenterAO(); } //Compute the subframe from the trackbox size int sizeX = gCam.TrackBoxX; int sizeY = gCam.TrackBoxY; gCam.SubframeTop = (int)(tPlan.GuideStarY * tPlan.GuiderBinning) - (sizeY / 2); gCam.SubframeBottom = (int)(tPlan.GuideStarY * tPlan.GuiderBinning) + (sizeY / 2); gCam.SubframeLeft = (int)(tPlan.GuideStarX * tPlan.GuiderBinning) - (sizeX / 2); gCam.SubframeRight = (int)(tPlan.GuideStarX * tPlan.GuiderBinning) + (sizeX / 2); int tstat = gCam.GetImage(); if (tstat != 0) { lg.LogIt("Autoguider Image Error: " + tstat.ToString()); return(0); } lg.LogIt("Guider Subframe image successful"); double maxPixel = gCam.MaximumPixel; return(maxPixel); }