Esempio n. 1
0
    def pointVerify(self):
        """
        Checks telescope pointing.
        If abs ( telescope coordinates - image coordinates ) > tolerance
           move the scope
           take a new image
           test again
           do this while ntrials < max_tries

        Returns True if centering was succesful
                False if not
        """

        # take an image and read its coordinates off the header

        try:
            image_path, image = self._takeImage()
            self.log.debug("Taking image: image name %s" % image_path)
        except:
            self.log.error("Can't take image")
            raise

        tel = self.getTel()
        # analyze the previous image using
        # AstrometryNet defined in util
        try:
            wcs_name = AstrometryNet.solveField(image_path, findstarmethod="sex")
        except NoSolutionAstrometryNetException, e:
            raise e
Esempio n. 2
0
    def pointVerify (self):
        """ Checks telescope pointing

        Checks the pointing.
        If abs ( telescope coordinates - image coordinates ) > tolerance
           move the scope
           take a new image
           test again
           do this while ntrials < max_trials

        Returns True if centering was succesful
                False if not
        """


        # take an image and read its coordinates off the header
        image = None

        try:
            image = self._takeImage()
            print "image name %s", image.filename()
        except:
            self.log.error( "Can't take image" )
            raise

        ra_img_center = image["CRVAL1"]    # expects to see this in image
        dec_img_center= image["CRVAL2"]
        currentImageCenter = Position.fromRaDec(Coord.fromD(ra_img_center), 
                                                Coord.fromD(dec_img_center))

        tel = self.getTel()
        # analyze the previous image using
        # AstrometryNet defined in util
        try:
            wcs_name = AstrometryNet.solveField(image.filename(),findstarmethod="sex") 
        except NoSolutionAstrometryNetException, e: 
            raise e
Esempio n. 3
0
    def pointVerify(self):
        """ Checks telescope pointing

        Checks the pointing.
        If abs ( telescope coordinates - image coordinates ) > tolerance
           move the scope
           take a new image
           test again
           do this while ntrials < max_trials

        Returns True if centering was succesful
                False if not
        """

        # take an image and read its coordinates off the header
        image = None

        try:
            image = self._takeImage()
            print "image name %s", image.filename()
        except:
            self.log.error("Can't take image")
            raise

        ra_img_center = image["CRVAL1"]  # expects to see this in image
        dec_img_center = image["CRVAL2"]
        currentImageCenter = Position.fromRaDec(Coord.fromD(ra_img_center),
                                                Coord.fromD(dec_img_center))

        tel = self.getTel()
        # analyze the previous image using
        # AstrometryNet defined in util
        try:
            wcs_name = AstrometryNet.solveField(image.filename(),
                                                findstarmethod="sex")
        except NoSolutionAstrometryNetException, e:
            raise e
Esempio n. 4
0
    def pointVerify(self):
        """ Checks telescope pointing

        Checks the pointing.
        If telescope coordinates - image coordinates > tolerance
           move the scope
           take a new image
           test again
           do this while ntrials < max_trials

        Returns True if centering was succesful
                False if not
        """

        # take an image and read its coordinates off the header
        try:
            image_name = self._takeImage()
            # for testing purposes uncomment line below and specify some image
        except:
            self.log.error("Can't take image")
            raise

        image = Image.fromFile(image_name)  # Image defined in util
        ra_img_center = image["CRVAL1"]  # expects to see this in image
        dec_img_center = image["CRVAL2"]
        currentImageCenter = Position.fromRaDec(Coord.fromD(ra_img_center),
                                                Coord.fromD(dec_img_center))

        tel = self.getTel()

        # analyze the previous image using
        # AstrometryNet defined in util
        try:
            wcs_name = AstrometryNet.solveField(image.filename,
                                                findstarmethod="sex")
        except (NoSolutionAstronomyNetException):
            # why can't I select this exception?
            #
            # there was no solution to this field.
            # send the telescope back to checkPointing
            # if that fails, clouds or telescope problem
            # an exception will be raised there
            self.log.error("No WCS solution")
            if not self.checkedpointing:
                if checkPointing() == True:
                    self.checkedpointing = True
                    tel.slewToRaDec(currentImageCenter)
                    try:
                        pointVerify()
                        return True
                    except CanSetScopeButNotThisField:
                        pass  # let the caller decide whether we go to next
                        # field or stay on this with no verification
            else:
                self.checkedpointing = False
                raise CanSetScopeButNotThisField(
                    "Able to set scope, but unable to verify this field %s" %
                    (currentImageCenter))

        wcs = Image.fromFile(wcs_name)
        ra_wcs_center = wcs["CRVAL1"] + (wcs["NAXIS1"] / 2.0 -
                                         wcs["CRPIX1"]) * wcs["CD1_1"]
        dec_wcs_center = wcs["CRVAL2"] + (wcs["NAXIS2"] / 2.0 -
                                          wcs["CRPIX2"]) * wcs["CD2_2"]
        currentWCS = Position.fromRaDec(Coord.fromD(ra_wcs_center),
                                        Coord.fromD(dec_wcs_center))

        # save the position of first trial:
        if (self.ntrials == 0):
            initialPosition = Position.fromRaDec(Coord.fromD(ra_img_center),
                                                 Coord.fromD(dec_img_center))
            initialWCS = Position.fromRaDec(currentWCS.ra, currentWCS.dec)

        # write down the two positions for later use in mount models
        if (self.ntrials == 0):
            logstr = "Pointing Info for Mount Model: %s %s %s" % (
                image["DATE-OBS"], initialPosition, currentWCS)
            self.log.info(logstr)

        delta_ra = ra_img_center - ra_wcs_center
        delta_dec = dec_img_center - dec_wcs_center

        self.log.debug("%s %s" % (delta_ra, delta_dec))
        self.log.debug("%s %s" % (ra_img_center, ra_wcs_center))
        self.log.debug("%s %s" % (dec_img_center, dec_wcs_center))

        # *** need to do real logging here
        logstr = "%s %f %f %f %f %f %f" % (image["DATE-OBS"], ra_img_center,
                                           dec_img_center, ra_wcs_center,
                                           dec_wcs_center, delta_ra, delta_dec)
        self.log.debug(logstr)

        if (delta_ra > self["tolra"]) or (delta_dec > self["toldec"]):
            print "Telescope not there yet."
            print "Trying again"
            self.ntrials += 1
            if (self.ntrials > self["max_trials"]):
                self.ntrials = 0
                raise CantPointScopeException(
                    "Scope does not point with a precision of %f (RA) or %f (DEC) after %d trials\n"
                    % self["tolra"] % self["toldec"] % self["max_trials"])
            tel.moveOffset(delta_ra, delta_dec)
            self.pointVerify()
        else:
            # if we got here, we were succesfull reset trials counter
            self.ntrials = 0
            # and save final position
            # write down the two positions for later use in mount models
            logstr = "Pointing: final solution %s %s %s" % (
                image["DATE-OBS"], currentImageCenter, currentWCS)
            self.log.info(logstr)

        return (True)