def locator(self, value): """Update the locator, and trigger a latitude and longitude update. :param str value: New Maidenhead locator string """ self._locator = value self._latitude, self._longitude = utils.from_grid_locator(value)
def import_locations(self, locations): """Import locations from arguments. :type locations: ``list`` of 2 ``tuple`` of ``str`` :param locations: Identifiers and locations """ for identifier, location in locations: data = utils.parse_location(location) if data: latitude, longitude = data else: latitude, longitude = utils.from_grid_locator(location) self[identifier] = Point(latitude, longitude, self.units)
def _set_locator(self, value): """Update the locator, and trigger a latitude and longitude update >>> test = Baken(None, None, "2 x Turnstile", None, 50.000, 460.000, ... "IO93BF", "A1A", None, 25, None) >>> test.locator = "JN44FH" >>> test Baken(44.3125, 8.45833333333, '2 x Turnstile', None, 50.0, 460.0, 'JN44FH', 'A1A', None, 25, None) :type value : ``str`` :param value: New Maidenhead locator string """ self._locator = value self._latitude, self._longitude = utils.from_grid_locator(value)
def read_locations(filename): """Pull locations from a user's config file. :param str filename: Config file to parse :rtype: ``dict`` :return: List of locations from config file """ data = ConfigParser() data.read(filename) if not data.sections(): logging.debug("Config file %r is empty" % filename) return {} locations = {} for name in data.sections(): if data.has_option(name, "locator"): latitude, longitude = utils.from_grid_locator(data.get(name, "locator")) else: latitude = data.getfloat(name, "latitude") longitude = data.getfloat(name, "longitude") locations[name] = (latitude, longitude) return locations
def import_locations(self, locations, config_locations): """Import locations from arguments. :type locations: ``list`` of ``str`` :param locations: Location identifiers :param dict config_locations: Locations imported from user's config file """ for number, location in enumerate(locations): if config_locations and location in config_locations: latitude, longitude = config_locations[location] self.append(NumberedPoint(latitude, longitude, location, self.units)) else: try: data = utils.parse_location(location) if data: latitude, longitude = data else: latitude, longitude = utils.from_grid_locator(location) self.append(NumberedPoint(latitude, longitude, number + 1, self.units)) except ValueError: raise LocationsError(data=(number, location))
def __init__(self, latitude, longitude, antenna=None, direction=None, frequency=None, height=None, locator=None, mode=None, operator=None, power=None, qth=None): """Initialise a new ``Baken`` object. :param float latitude: Location's latitude :param float longitude: Location's longitude :param str antenna: Location's antenna type :type direction: ``tuple`` of ``int`` :param direction: Antenna's direction :param float frequency: Transmitter's frequency :param float height: Antenna's height :param str locator: Location's Maidenhead locator string :param str mode: Transmitter's mode :type operator: ``tuple`` of ``str`` :param operator: Transmitter's operator :param float power: Transmitter's power :param str qth: Location's qth :raise LookupError: No position data to use """ if not latitude is None: super(Baken, self).__init__(latitude, longitude) elif not locator is None: latitude, longitude = utils.from_grid_locator(locator) super(Baken, self).__init__(latitude, longitude) else: raise LookupError('Unable to instantiate baken object, no ' 'latitude or locator string') self.antenna = antenna self.direction = direction self.frequency = frequency self.height = height self._locator = locator self.mode = mode self.operator = operator self.power = power self.qth = qth
def __init__(self, latitude, longitude, antenna=None, direction=None, frequency=None, height=None, locator=None, mode=None, operator=None, power=None, qth=None): """Initialise a new ``Baken`` object >>> Baken(14.460, 20.680, None, None, None, 0.000, None, None, None, ... None, None) Baken(14.46, 20.68, None, None, None, 0.0, None, None, None, None, None) >>> Baken(None, None, "2 x Turnstile", None, 50.000, 460.000, "IO93BF", ... "A1A", None, 25, None) Baken(53.2291666667, -1.875, '2 x Turnstile', None, 50.0, 460.0, 'IO93BF', 'A1A', None, 25, None) >>> obj = Baken(None, None) Traceback (most recent call last): ... LookupError: Unable to instantiate baken object, no latitude or locator string :type latitude: ``float`` or coercible to ``float`` :param latitude: Location's latitude :type longitude: ``float`` or coercible to ``float`` :param longitude: Location's longitude :type antenna: ``str`` :param antenna: Location's antenna type :type direction: ``tuple`` of ``int`` :param direction: Antenna's direction :type frequency: ``float`` :param frequency: Transmitter's frequency :type height: ``float`` :param height: Antenna's height :type locator: ``str`` :param locator: Location's Maidenhead locator string :type mode: ``str`` :param mode: Transmitter's mode :type operator: ``tuple`` of ``str`` :param operator: Transmitter's operator :type power: ``float`` :param power: Transmitter's power :type qth: ``str`` :param qth: Location's qth :raise LookupError: No position data to use """ if not latitude is None: super(Baken, self).__init__(latitude, longitude) elif not locator is None: latitude, longitude = utils.from_grid_locator(locator) super(Baken, self).__init__(latitude, longitude) else: raise LookupError("Unable to instantiate baken object, no " "latitude or locator string") self.antenna = antenna self.direction = direction self.frequency = frequency self.height = height self._locator = locator self.mode = mode self.operator = operator self.power = power self.qth = qth
def test_from_grid_locator(locator, result): assert '%.3f, %.3f' % from_grid_locator(locator) == result
def test_from_grid_locator(): expect('%.3f, %.3f' % from_grid_locator('BL11bh16')) == '21.319, -157.904' expect('%.3f, %.3f' % from_grid_locator('IO92va')) == '52.021, -0.208' expect('%.3f, %.3f' % from_grid_locator('IO92')) == '52.021, -1.958'