def _communicate_tracking_info(self):
        """ Runs as a daemon thread, communicating tracking info to remote socket.

            Uses observer and satellite objects set by trackobject().

            Will exit if altitude is less than zero (below the horizon).
        """
        if self._debugmode:
            print(('alive:', self._stay_alive))
        else:
            sock = trackersocket.trackersocket()
            sock.connect(self._IP, self._PORT)  # change to correct address

        # track satellite
        while self._stay_alive:
            if self._debugmode:
                #print type(self.observer_dict), self.observer_dict
                #print type(self.satellite_dict), self.satellite_dict
                print(('Tracking', self.satellite_dict['tle0'], 'from', self.observer_dict['elev']))
            else:
                p = orbital.pinpoint(self.observer_dict, self.satellite_dict)
                if p['ok']:
                    if p['alt'] < 0:
                        # break
                        self._stay_alive = False
                    else:
                        s = 'P ' + str((p['az'].conjugate())) + ' ' + str(p['alt'].conjugate())
                        #print s + str('\n')
                        sock.send(s + str('\n'))
                        time.sleep(self.SLEEP_TIME)
            # exiting
        if self._debugmode:
            print('Tracking thread exited.')
        else:
            sock.disconnect()
def pinpoint(observer_name, satellite_name):
    """ Returns azimuth and altitude of satellite from observer.

        Only names are provided as params,
        they are subsequently searched in their respectable lists.
    """
    o_result = dataio.get_observer(observer_name)
    if o_result['ok']:
        o = o_result['results'][0]
    else:
        return {'error': 'observer not found'}

    s_result = dataio.get_satellite(satellite_name)
    if o_result['ok']:
        s = s_result['results'][0]
    else:
        return {'error': 'satellite not found'}

    result = orbital.pinpoint(o, s)
    return result
    def _communicate_tracking_info(self):
        """ Runs as a daemon thread, communicating tracking info to remote socket.

            Uses observer and satellite objects set by trackobject().

            Will exit if altitude is less than zero (below the horizon).
        """
        if self._debugmode:
            print(('alive:', self._stay_alive))
        else:
            sock = trackersocket.trackersocket()
            sock.connect(self._IP, self._PORT)  # change to correct address

        # track satellite
        while self._stay_alive:
            if self._debugmode:
                #print type(self.observer_dict), self.observer_dict
                #print type(self.satellite_dict), self.satellite_dict
                print(('Tracking', self.satellite_dict['tle0'], 'from',
                       self.observer_dict['elev']))
            else:
                p = orbital.pinpoint(self.observer_dict, self.satellite_dict)
                if p['ok']:
                    if p['alt'] < 0:
                        # break
                        self._stay_alive = False
                    else:
                        s = 'P ' + str((p['az'].conjugate())) + ' ' + str(
                            p['alt'].conjugate())
                        #print s + str('\n')
                        sock.send(s + str('\n'))
                        time.sleep(self.SLEEP_TIME)
            # exiting
        if self._debugmode:
            print('Tracking thread exited.')
        else:
            sock.disconnect()