def getOffset(self, position):

        ret = {"X": 0.0, "Y": 0.0, "N": 0.0, "E": 0.0, "Status": self.state()}

        try:
            frame = self._takeImage()
            fname = "/tmp/autoguider.fits"
            if os.path.exists(fname):
                os.remove(fname)
            frame.save(fname)
            img = fits.getdata(fname)
            # Extract some backgroud
            img -= np.mean(img) * 0.9
            img[img < 0] = 0.0

            pY, pX = centroid(img)
            ret["X"] = pX - position["XWIN_IMAGE"]
            ret["Y"] = pY - position["YWIN_IMAGE"]
            centerPos = frame.worldAt([position["XWIN_IMAGE"], position["YWIN_IMAGE"]])
            currPos = frame.worldAt([pX, pY])
            # offset = centerPos.angsep(currPos)
            ret["E"] = Coord.fromAS((centerPos.ra.AS - currPos.ra.AS) * np.cos(currPos.dec.R))
            ret["N"] = Coord.fromAS(centerPos.dec.AS - currPos.dec.AS)
        except:
            if self.abort.isSet():
                ret["Status"] = GuiderStatus.ABORTED
                return ret
            else:
                raise

        self.plot(frame, position, ret)

        return ret
Beispiel #2
0
    def moveSouth(self, offset, rate=SlewRate.MAX):
        self._slewing = True

        pos = self.getPositionRaDec()
        pos = Position.fromRaDec(pos.ra, pos.dec + Coord.fromAS(-offset))
        self.slewBegin(pos)

        self._dec += Coord.fromAS(-offset)
        self._setAltAzFromRaDec()

        self._slewing = False
        self.slewComplete(self.getPositionRaDec(), TelescopeStatus.OK)
Beispiel #3
0
    def moveSouth(self, offset, rate=SlewRate.MAX):
        self._slewing = True

        pos = self.getPositionRaDec()
        pos = Position.fromRaDec(pos.ra, pos.dec + Coord.fromAS(-offset))
        self.slewBegin(pos)

        self._dec += Coord.fromAS(-offset)
        self._setAltAzFromRaDec()

        self._slewing = False
        self.slewComplete(self.getPositionRaDec(), TelescopeStatus.OK)
Beispiel #4
0
    def _waitSlew (self, start_time, target, local=False):

        self.slewBegin(target)

        while True:

            # check slew abort event
            if self._abort.isSet ():
                self._slewing = False
                return TelescopeStatus.ABORTED

            # check timeout
            if time.time () >= (start_time + self["max_slew_time"]):
                self.abortSlew ()
                self._slewing = False
                raise MeadeException("Slew aborted. Max slew time reached.")

            if local:
                position = self.getPositionAltAz()
            else:
                position = self.getPositionRaDec()

            if target.within (position, eps=Coord.fromAS(60)):
                time.sleep (self["stabilization_time"])
                self._slewing = False
                return TelescopeStatus.OK

            time.sleep (self["slew_idle_time"])

        return TelescoopeStatus.ERROR
Beispiel #5
0
    def _waitSlew(self, start_time, target, local=False):

        self.slewBegin(target)

        while True:

            # check slew abort event
            if self._abort.isSet():
                self._slewing = False
                return TelescopeStatus.ABORTED

            # check timeout
            if time.time() >= (start_time + self["max_slew_time"]):
                self.abortSlew()
                self._slewing = False
                raise MeadeException("Slew aborted. Max slew time reached.")

            if local:
                position = self.getPositionAltAz()
            else:
                position = self.getPositionRaDec()

            if target.within(position, eps=Coord.fromAS(60)):
                time.sleep(self["stabilization_time"])
                self._slewing = False
                return TelescopeStatus.OK

            time.sleep(self["slew_idle_time"])

        return TelescoopeStatus.ERROR
Beispiel #6
0
            def _validateOffset(value):
                try:
                    offset = Coord.fromAS(int(value))
                except ValueError:
                    offset = Coord.fromDMS(value)

                return offset
Beispiel #7
0
    def within(self, other, eps=Coord.fromAS(60)):
        """
        Returns wether L{other} is up to L{eps} units from this
        points. (using great circle distance).

        @param other: Same as in angsep.
        @type  other: L{Position}.

        @param eps: Limit distance.
        @type  eps: L{Coord}.

        @returns: Wether L{other} is within {eps} units from this point.
        @rtype: bool
        """
        return (self.angsep(other) <= eps)
Beispiel #8
0
    def within(self, other, eps=Coord.fromAS(60)):
        """
        Returns wether L{other} is up to L{eps} units from this
        points. (using great circle distance).

        @param other: Same as in angsep.
        @type  other: L{Position}.

        @param eps: Limit distance.
        @type  eps: L{Coord}.

        @returns: Wether L{other} is within {eps} units from this point.
        @rtype: bool
        """
        return (self.angsep(other) <= eps)
Beispiel #9
0
    def process(check):

        import yaml
        from chimera.util.position import Position
        from chimera.util.coord import Coord
        from chimera.controllers.scheduler.model import (Session, Program,
                                                         AutoFocus, AutoFlat,
                                                         PointVerify, Point,
                                                         Expose)

        actionDict = {
            'autofocus': AutoFocus,
            'autoflat': AutoFlat,
            'pointverify': PointVerify,
            'point': Point,
            'expose': Expose,
        }

        manager = BaseResponse.manager
        # sched = ConfigureScheduler.scheduler

        # delete all programs
        session = Session()
        programs = session.query(Program).all()
        for program in programs:
            session.delete(program)
        session.commit()

        def generateDatabase(options):

            with open(os.path.join(os.path.expanduser('~/'), options.filename),
                      'r') as stream:
                try:
                    prgconfig = yaml.load(stream)
                except yaml.YAMLError as exc:

                    manager.broadCast(exc)
                    raise
                except Exception, e:
                    manager.broadCast(
                        'Exception trying to start scheduler: %s' % repr(e))
                    raise

            def _validateOffset(value):
                try:
                    offset = Coord.fromAS(int(value))
                except ValueError:
                    offset = Coord.fromDMS(value)

                return offset

            session = Session()

            programs = []

            for prg in prgconfig['programs']:

                # process program

                program = Program()
                for key in prg.keys():
                    if hasattr(program, key) and key != 'actions':
                        try:
                            setattr(program, key, prg[key])
                        except:
                            manager.broadCast(
                                'Could not set attribute %s = %s on Program' %
                                (key, prg[key]))

                # self.out("# program: %s" % program.name)

                # process actions
                for actconfig in prg['actions']:
                    act = actionDict[actconfig['action']]()
                    # self.out('Action: %s' % actconfig['action'])

                    if actconfig['action'] == 'point':
                        if 'ra' in actconfig.keys(
                        ) and 'dec' in actconfig.keys():
                            epoch = 'J2000' if 'epoch' not in actconfig.keys(
                            ) else actconfig['epoch']
                            position = Position.fromRaDec(
                                actconfig['ra'], actconfig['dec'], epoch)
                            # self.out('Coords: %s' % position)
                            act.targetRaDec = position
                            # act = Point(targetRaDec=position)
                        elif 'alt' in actconfig.keys(
                        ) and 'az' in actconfig.keys():
                            position = Position.fromAltAz(
                                actconfig['alt'], actconfig['az'])
                            # self.out('Coords: %s' % position)
                            act.targetAltAz = position
                        elif 'name' in actconfig:
                            # self.out('Target name: %s' % actconfig['name'])
                            act.targetName = actconfig['name']
                        elif 'offset' not in actconfig:
                            manager.broadCast(
                                'Empty Point action. No target to point to or offset to perform!'
                            )
                            continue

                        if 'offset' in actconfig:
                            if 'north' in actconfig['offset']:
                                offset = _validateOffset(
                                    actconfig['offset']['north'])
                                act.offsetNS = offset
                            elif 'south' in actconfig['offset']:
                                offset = _validateOffset(
                                    actconfig['offset']['south'])
                                act.offsetNS = Coord.fromAS(-offset.AS)

                            if 'west' in actconfig['offset']:
                                offset = _validateOffset(
                                    actconfig['offset']['west'])
                                act.offsetEW = offset
                            elif 'east' in actconfig['offset']:
                                offset = _validateOffset(
                                    actconfig['offset']['east'])
                                act.offsetEW = Coord.fromAS(-offset.AS)

                    else:
                        for key in actconfig.keys():
                            if hasattr(act, key) and key != 'action':
                                # self.out('\t%s: %s' % (key,actconfig[key]))
                                try:
                                    setattr(act, key, actconfig[key])
                                except:
                                    manager.broadCast(
                                        'Could not set attribute %s = %s on action %s'
                                        % (key, actconfig[key],
                                           actconfig['action']))
                    program.actions.append(act)

                # self.out("")
                programs.append(program)

            # self.out("List contain %i programs" % len(programs))
            session.add_all(programs)
            session.commit()

            return 0