GetGuidestar (function)

by Jeff Medkeff

This function takes the position of the next target and adjusts it so as to center a guide star in the guiding camera.

The right ascension and declination of the target should already be defined when this function is called. Given the position of the target, the function will calculate the position of the center of your guider's field when the target is centered. A list of stars around this position and bright enough to be used by the guider is then generated by PinPoint.

Whatever star is closest to this position is chosen as the guide star. The right ascension and declination of your target are then modified so as to insure that the selected guide star is centered in your field. This will slightly decenter the target in your main field. How much it is decentered depends on where in the sky you are aiming and how faint a guide star you are willing to use. For example, near the galactic plane the target will barely be decentered, but near the galactic pole it will probably be decentered by much more on average. Similarly, if you insist on very bright guide stars (10th magnitude), you will be decentering severely; if you allow very faint guide stars (16.5 magnitude) and correspondingly longer guiding exposures, you will decenter the target much less.

The reliability of this function is nearly 100% when it is fed proper configuration information. During the very rare occasions when it cannot find a guide star, it logs a guide star not found message and exits gracefully.



Function GetGuideStar


    ' Only pick a guide star if we are going to guide the image
    ' You really should get rid of this test here and put it
    ' wherever GetGuideStar is called, so that the function is
    ' called only if necessary.

    If DoWeGuide = True And tgtDuration > NoGuide Then
    
      Dim cd
      Dim Dec
      Dim RA
      Dim dra
      Dim ddec
      Dim platestar 'As PlateStars
      Dim star 'As platestar
      Dim mag


      ' Super-elegant algorithm here, provided by John McClusky
      cd = Cos((tgtDec + guider_offset/2) / 57.29578)   
      dra = (Sin(Rotation) * guider_offset) / cd  'RA  offset in degrees, corrected for declination
      ddec = Cos(Rotation) * guider_offset        'Dec  offset in degrees

      RA = tgtRA + dra / 15             ' RA of ideal guidestar, decimal hours
      Dec = tgtDec - ddec               ' dec of ideal guidestar, decimal degrees


      ' get list of catalog stars & sort on desired guide star location

      ' This is an image from the guider that we attach to PinPoint solely
      ' for the purpose of making PinPoint work. It must have an image
      ' attached to find catalog stars, for some reason.

      plate.AttachFITS "c:\asteroids\guide.fts"

      ' here we fake out PinPoint and tell it this little image is
      ' centered at the coordinates of our 'ideal' guide star

      plate.Declination = Dec
      plate.RightAscension = RA

      ' here we tell PinPoint what our guider's scale is. For many cameras,
      ' it will be the same as the imaging camera, so using PointSolveScale
      ' works fine. If it is different, define a set of appropriate variables
      ' or hard-code this here. Note that the multipliers are narrowing the area
      ' that we search for stars in - adjust to your satisfaction.

      plate.ArcsecPerPixelHoriz = PointSolveScale * 0.8
      plate.ArcsecPerPixelVert = PointSolveScale * 0.8

      ' we set this to zero so that we don't go slewing all over the place
      ' to grab our guide star. The area actually searched will be defined
      ' by the number of pixels on the guider times the platescale (which
      ' is manipulated by a factor, above, to make a bigger or smaller search
      ' area

      plate.CatalogExpansion = 0

      Logtext "Looking for guide star for " & tgtName

      On Error Resume Next
      If Not plate.FindCatalogStars Then
        Log "No candidate guide stars were found in catalog."
        plate.DetachFITS
        GetGuideStar = False
        Exit Function
      Else
        Set platestar = plate.CatalogStars          ' Pass back catalog stars

        ' sort them by distance from 'ideal' position
        platestar.Sort ppSortByDistance, ppSortAscending, RA, Dec

        For Each star In platestar

          ' Figure out magnitude of this star.
          ' Note that redmag will be modified by this test. If the magnitude
          ' is available in some other color band, this magnitude is used
          ' and corrected to red by a "ball park" factor provided by Brian
          ' Skiff. These alterations are in order of desirability; if a red
          ' magnitude is available, it is used. Visual correction is more reliable
          ' than IR correction. Etc.

          redmag = 99
          redmag = star.UltravioletMagnitude + 1.5
          redmag = star.BlueMagnitude + 0.8
          redmag = star.InfraredMagnitude - 0.4
          redmag = star.VisualMagnitude + 0.5
          redmag = star.RedMagnitude
          
            ' Here we find out if this particular star is bright enough.
            ' If so, we use it, and exit the loop. If not, we get the next-
            ' nearest star to our 'ideal' position and check that one.

            If redmag < GuiderMagLimit Then
                  ' back-calculate position of target location
                  tgtRA = star.RightAscension - dra / 15
                  If tgtRA > 24 Then
                    tgtRA = tgtRA - 24
                  End If
                  If tgtRA < 0 Then
                    tgtRA = tgtRA + 24
                  End If

                  tgtDec = star.Declination + ddec

                  Log "Desired Guide star is " & star.Identification & " at " & Round(mag, 1) & " magnitude."
                  Exit For
            End If 'mag < GuiderMagLimit Then

        Next
        plate.DetachFITS
      End If 'plate.FindCatalogStars
      On Error Goto 0
    End If 'DoWeGuide = 1 And tgtDuration > NoGuide

  GetGuideStar = True

End Function