TwiceAsNice  2019-02-18
Public Member Functions | Public Attributes | List of all members
AG_Utils.MonThread Class Reference
Inheritance diagram for AG_Utils.MonThread:
Inheritance graph
Collaboration diagram for AG_Utils.MonThread:
Collaboration graph

Public Member Functions

def __init__ (self)
 
def run (self)
 not need to overload this More...
 
def findStar (self, img, alg)
 
def startGuiding (self)
 
def stopGuiding (self)
 
def changeCadence (self)
 
def FakeImage (self)
 
def stopMonitoring (self)
 
def startMonitoring (self)
 
def __init__ (self)
 
def run (self)
 not need to overload this More...
 
def findStar (self, img, alg)
 
def startGuiding (self)
 
def stopGuiding (self)
 
def changeCadence (self)
 
def FakeImage (self)
 
def stopMonitoring (self)
 
def startMonitoring (self)
 
def __init__ (self)
 
def run (self)
 not need to overload this More...
 
def findStar (self, img, alg)
 
def startGuiding (self)
 
def stopGuiding (self)
 
def changeCadence (self)
 
def FakeImage (self)
 
def stopMonitoring (self)
 
def startMonitoring (self)
 

Public Attributes

 doMon
 
 doRun
 
 doAG
 
 cY
 
 oYf
 
 got1frame
 
 stIm
 
 fkX
 
 fkY
 
 fkA
 
 pcam
 
 startT
 
 cIm
 
 gIm
 AutoGuiding. More...
 
 mYg
 
 mXf
 
 mYf
 
 bY
 
 oXf
 

Detailed Description

Monitoring and guiding thread which does a lot of the real work.

    General Philosophy
    This routine retrieves an image from the Patrol Camera (PCam) and
    locates the star within a preset box. Note that the location of
    this preset box has to defined by the calling routine (specifically
    by a mouse click during startup of the autoguiding). The target location
    of the star for auto-guiding is its location in the initial frame,
    but the target can be altered manually by the calling routine. The
    location and hence offset of the star is determined in the subsequent
    frames and reported to the calling routine. This thread also produces
    numpy arrays of the full field and target star suitable for display by 
    the GUI (it is bad form/impossible for a thread to address the GUI).
    Note that for development (AG_Conf.DEV=True), this thread generates
    fake images.

    Important Variables

        self.doMon   - whether to monitor (and indeed for the thread to run)
        self.doAG    - whether to autoguide
        self.cX,cY   - current star location
        self.mXg,mYg - measured star center in guide box
        self.mXf,mYf - measured star center in full frame
        self.oXf,oYf - offset of measured position from ref in full frame

    Star Finding and Centering

    Based on user input, the thread receives initial values for self.cX, self.cY,
    the center of the guiding box. It then searches for and locates the star, using
    one of several algorithms (brightest pixel, center of light, cross-correlation,
    etc.). At each iteration, the difference between the previous (cX,cY) and the
    newly derived values determines the offset. To allow for minor errors, the box
    center is reset to the first derived position (to nearest pixel), but it does
    not move thereafter! In other words, self.cX, self.cY are the star location,
    and not the box center, although the box center is set to the nearest pixel
    to (cX,cY) at startup of auto-guiding.

    Fake Image Details
    At startup, the routine creates self.stIm, a postage-stamp sized generic star
    image that is (AG_Conf.fkBoxHalf * 2) pixels square. The generic star is a
    gaussian with amplitude AG_Conf.fkMax and standard deviation AG_Conf.fkWidSig.
    There will be AG_Conf.nFake such stars located at the positions and amplitudes
    fkX,fkY,fkA - these are also calculated at startup. At each realization, the
    fake image starts with random noise (properties are: AG_Conf.fkNctr,fkNsig).
    The routine adds in the nFake stars at the appropriate locations and amplitudes.
    Of course for autoguiding, the positions will be shifted as a set to simulate
    tracking issues. The individual star amplitudes can also vary.

    NOTE: The program currently only does integral pixel shifts! A proper, bilinear
          interpolation routine is high on the list of desirables...

    To end the thread, call self.stopMonitoring().

Constructor & Destructor Documentation

◆ __init__() [1/3]

def AG_Utils.MonThread.__init__ (   self)

◆ __init__() [2/3]

def AG_Utils.MonThread.__init__ (   self)

◆ __init__() [3/3]

def AG_Utils.MonThread.__init__ (   self)

Member Function Documentation

◆ changeCadence() [1/3]

def AG_Utils.MonThread.changeCadence (   self)

◆ changeCadence() [2/3]

def AG_Utils.MonThread.changeCadence (   self)

◆ changeCadence() [3/3]

def AG_Utils.MonThread.changeCadence (   self)

◆ FakeImage() [1/3]

def AG_Utils.MonThread.FakeImage (   self)
    Generate and return a fake image - a numpy array of the appropriate
    size and with a fake star at the specified location. Optionally, shift
    the star randomly in x and y.

◆ FakeImage() [2/3]

def AG_Utils.MonThread.FakeImage (   self)
    Generate and return a fake image - a numpy array of the appropriate
    size and with a fake star at the specified location. Optionally, shift
    the star randomly in x and y.

◆ FakeImage() [3/3]

def AG_Utils.MonThread.FakeImage (   self)
    Generate and return a fake image - a numpy array of the appropriate
    size and with a fake star at the specified location. Optionally, shift
    the star randomly in x and y.

◆ findStar() [1/3]

def AG_Utils.MonThread.findStar (   self,
  img,
  alg 
)
    Find and return the location of the guide star in the supplied img.
    There are multiple ways of finding the star location. The calling
    program selects the algorithm using the parameter alg:

       alg = 0  - Brightest pixel in guide box
          This is the simplest possible star-finding algorithm. The routine
          identifies the brightest pixel in the supplied img and returns its
          XY location

       alg = 1  - Center of light in guide box
          Somewhat more sophisticated. The routine identifies the brightest
          pixel and then calculates the center of light in the guide box
          (after subtracting the sky background to avoid center-bias).

       alg = 2  - Cross correlation with first image
          Even more fancy (and hopefully resilient to odd-shaped images).
          This one returns the maximum of the cross-correlation of the
          supplied image with the first frame, saved in AG_Conf.sTmpl
          This algorithm is based on the material at:
          docs.scipy.org/doc/scipy/reference/generated/scipy.signal.correlate2d.html

    There are 2 sky level algorithms:

AG_Conf.skySub = 0  - The sky value is the median of the full guide box. Note
                      that this can be problematic of the star is "large" compared
                      to the guide box size!

AG_Conf.skySub = 1  - The sky value is the average of the 1-pixel wide region at
                      the edge of the sky box. The routine calculates this by extracting
                      a subarray inG that is 2 pixels smaller in each dimension. The average
                      of the boundary values is then just the difference in sums divided
                      by the difference in number of elements (see below).

    NOTE THAT THESE ROUTINES CURRENTLY RETURN AN INTEGER PIXEL LOCATION !!!

◆ findStar() [2/3]

def AG_Utils.MonThread.findStar (   self,
  img,
  alg 
)
    Find and return the location of the guide star in the supplied img.
    There are multiple ways of finding the star location. The calling
    program selects the algorithm using the parameter alg:

       alg = 0  - Brightest pixel in guide box
          This is the simplest possible star-finding algorithm. The routine
          identifies the brightest pixel in the supplied img and returns its
          XY location

       alg = 1  - Center of light in guide box
          Somewhat more sophisticated. The routine identifies the brightest
          pixel and then calculates the center of light in the guide box
          (after subtracting the sky background to avoid center-bias).

       alg = 2  - Cross correlation with first image
          Even more fancy (and hopefully resilient to odd-shaped images).
          This one returns the maximum of the cross-correlation of the
          supplied image with the first frame, saved in AG_Conf.sTmpl
          This algorithm is based on the material at:
          docs.scipy.org/doc/scipy/reference/generated/scipy.signal.correlate2d.html

    There are 2 sky level algorithms:

AG_Conf.skySub = 0  - The sky value is the median of the full guide box. Note
                      that this can be problematic of the star is "large" compared
                      to the guide box size!

AG_Conf.skySub = 1  - The sky value is the average of the 1-pixel wide region at
                      the edge of the sky box. The routine calculates this by extracting
                      a subarray inG that is 2 pixels smaller in each dimension. The average
                      of the boundary values is then just the difference in sums divided
                      by the difference in number of elements (see below).

    NOTE THAT THESE ROUTINES CURRENTLY RETURN AN INTEGER PIXEL LOCATION !!!

◆ findStar() [3/3]

def AG_Utils.MonThread.findStar (   self,
  img,
  alg 
)
    Find and return the location of the guide star in the supplied img.
    There are multiple ways of finding the star location. The calling
    program selects the algorithm using the parameter alg:

       alg = 0  - Brightest pixel in guide box
          This is the simplest possible star-finding algorithm. The routine
          identifies the brightest pixel in the supplied img and returns its
          XY location

       alg = 1  - Center of light in guide box
          Somewhat more sophisticated. The routine identifies the brightest
          pixel and then calculates the center of light in the guide box
          (after subtracting the sky background to avoid center-bias).

       alg = 2  - Cross correlation with first image
          Even more fancy (and hopefully resilient to odd-shaped images).
          This one returns the maximum of the cross-correlation of the
          supplied image with the first frame, saved in AG_Conf.sTmpl
          This algorithm is based on the material at:
          docs.scipy.org/doc/scipy/reference/generated/scipy.signal.correlate2d.html

    There are 2 sky level algorithms:

AG_Conf.skySub = 0  - The sky value is the median of the full guide box. Note
                      that this can be problematic of the star is "large" compared
                      to the guide box size!

AG_Conf.skySub = 1  - The sky value is the average of the 1-pixel wide region at
                      the edge of the sky box. The routine calculates this by extracting
                      a subarray inG that is 2 pixels smaller in each dimension. The average
                      of the boundary values is then just the difference in sums divided
                      by the difference in number of elements (see below).

    NOTE THAT THESE ROUTINES CURRENTLY RETURN AN INTEGER PIXEL LOCATION !!!

◆ run() [1/3]

def AG_Utils.MonThread.run (   self)

◆ run() [2/3]

def AG_Utils.MonThread.run (   self)

◆ run() [3/3]

def AG_Utils.MonThread.run (   self)

◆ startGuiding() [1/3]

def AG_Utils.MonThread.startGuiding (   self)

◆ startGuiding() [2/3]

def AG_Utils.MonThread.startGuiding (   self)

◆ startGuiding() [3/3]

def AG_Utils.MonThread.startGuiding (   self)

◆ startMonitoring() [1/3]

def AG_Utils.MonThread.startMonitoring (   self)

◆ startMonitoring() [2/3]

def AG_Utils.MonThread.startMonitoring (   self)

◆ startMonitoring() [3/3]

def AG_Utils.MonThread.startMonitoring (   self)

◆ stopGuiding() [1/3]

def AG_Utils.MonThread.stopGuiding (   self)

◆ stopGuiding() [2/3]

def AG_Utils.MonThread.stopGuiding (   self)

◆ stopGuiding() [3/3]

def AG_Utils.MonThread.stopGuiding (   self)

◆ stopMonitoring() [1/3]

def AG_Utils.MonThread.stopMonitoring (   self)

◆ stopMonitoring() [2/3]

def AG_Utils.MonThread.stopMonitoring (   self)

◆ stopMonitoring() [3/3]

def AG_Utils.MonThread.stopMonitoring (   self)

Member Data Documentation

◆ bY

AG_Utils.MonThread.bY

◆ cIm

AG_Utils.MonThread.cIm

◆ cY

AG_Utils.MonThread.cY

◆ doAG

AG_Utils.MonThread.doAG

◆ doMon

AG_Utils.MonThread.doMon

◆ doRun

AG_Utils.MonThread.doRun

◆ fkA

AG_Utils.MonThread.fkA

◆ fkX

AG_Utils.MonThread.fkX

◆ fkY

AG_Utils.MonThread.fkY

◆ gIm

AG_Utils.MonThread.gIm

AutoGuiding.

The logic here is straightforward, but can be a bit confusing.

  1. When first invoked, the monitor thread sets the current star center (self.cX,self.cY) to (0,0). See the init code above.
  2. When the user presses the AutoGuide button, the main routine (remotely) sets (self.cX,self.cY) to the location clicked.
  3. If this is the first frame (self.got1frame is false), do this:

    a. Cut out a subarray (self.gIm) centered on this point (self.cX,self.cY) and Measure the location of the star in the subarray (self.mXg,self.mYg) and in the full array (self.mXf,self.mYf).

    b. Set star location (self.cX,self.cY) to Measured (self.mXf,self.mYf)

    c. Set guide box center (self.bX,self.bY) to Measured as well. This has the effect of centering the box on the Measured star center, not the clicked location, in the first frame.

  4. If it is not the first frame, do the following:

    a. Cut out a subarray (self.gIm) centered on the guide box (self.bX,self.bY) and determine the star location in the subarray (self.mXg,self.mYg) and full frame (self.mXf,self.mYf). See step 3a above.

    b. Set star location (self.cX,self.cY) to Measured (self.mXf,self.mYf)

    c. Calculate the offset in pixels (self.oXf,self.oYf) for full image. This will be the offset between (self.cX,self.cY) and the center of the guide box (self.bX,self.bY). Note that bX,bY is also the measured star location in the first frame.

◆ got1frame

AG_Utils.MonThread.got1frame

◆ mXf

AG_Utils.MonThread.mXf

◆ mYf

AG_Utils.MonThread.mYf

◆ mYg

AG_Utils.MonThread.mYg

◆ oXf

AG_Utils.MonThread.oXf

◆ oYf

AG_Utils.MonThread.oYf

◆ pcam

AG_Utils.MonThread.pcam

◆ startT

AG_Utils.MonThread.startT

◆ stIm

AG_Utils.MonThread.stIm

The documentation for this class was generated from the following file: