signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def parse_latitude(latitude, hemisphere):
latitude = int(latitude[:<NUM_LIT:2>]) + float(latitude[<NUM_LIT:2>:]) / <NUM_LIT><EOL>if hemisphere == '<STR_LIT:S>':<EOL><INDENT>latitude = -latitude<EOL><DEDENT>elif not hemisphere == '<STR_LIT:N>':<EOL><INDENT>raise ValueError('<STR_LIT>' % hemisphere)<EOL><DEDENT>return latitude<EOL>
Parse a NMEA-formatted latitude pair. Args: latitude (str): Latitude in DDMM.MMMM hemisphere (str): North or South Returns: float: Decimal representation of latitude
f12196:m3
def parse_longitude(longitude, hemisphere):
longitude = int(longitude[:<NUM_LIT:3>]) + float(longitude[<NUM_LIT:3>:]) / <NUM_LIT><EOL>if hemisphere == '<STR_LIT>':<EOL><INDENT>longitude = -longitude<EOL><DEDENT>elif not hemisphere == '<STR_LIT:E>':<EOL><INDENT>raise ValueError('<STR_LIT>' % hemisphere)<EOL><DEDENT>return longitude<EOL>
Parse a NMEA-formatted longitude pair. Args: longitude (str): Longitude in DDDMM.MMMM hemisphere (str): East or West Returns: float: Decimal representation of longitude
f12196:m4
def __init__(self, latitude, longitude, time, status, mode=None):
super(LoranPosition, self).__init__(latitude, longitude)<EOL>self.time = time<EOL>self.status = status<EOL>self.mode = mode<EOL>
Initialise a new ``LoranPosition`` object. Args: latitude (float): Fix's latitude longitude (float): Fix's longitude time (datetime.time): Time the fix was taken status (bool): Whether the data is active mode (str): Type of reading
f12196:c0:m0
def __str__(self, talker='<STR_LIT>'):
if not len(talker) == <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>' % talker)<EOL><DEDENT>data = ['<STR_LIT>' % talker]<EOL>data.extend(nmea_latitude(self.latitude))<EOL>data.extend(nmea_longitude(self.longitude))<EOL>data.append('<STR_LIT>' % (self.time.strftime('<STR_LIT>'),<EOL>self.time.microsecond / <NUM_L...
Pretty printed position string. Args: talker (str): Talker ID Returns: str: Human readable string representation of ``Position`` object
f12196:c0:m1
def mode_string(self):
return MODE_INDICATOR.get(self.mode, '<STR_LIT>')<EOL>
Return a string version of the reading mode information. Returns: str: Quality information as string
f12196:c0:m2
@staticmethod<EOL><INDENT>def parse_elements(elements):<DEDENT>
if not len(elements) in (<NUM_LIT:6>, <NUM_LIT:7>):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>latitude = parse_latitude(elements[<NUM_LIT:0>], elements[<NUM_LIT:1>])<EOL>longitude = parse_longitude(elements[<NUM_LIT:2>], elements[<NUM_LIT:3>])<EOL>hour, minute, second = [int(elements[<NUM_LIT:4>][i:i + <NUM...
Parse position data elements. Args: elements (list): Data values for fix Returns: Fix: Fix object representing data
f12196:c0:m3
def __init__(self, time, status, latitude, longitude, speed, track, date,<EOL>variation, mode=None):
super(Position, self).__init__(latitude, longitude)<EOL>self.time = time<EOL>self.status = status<EOL>self.speed = speed<EOL>self.track = track<EOL>self.date = date<EOL>self.variation = variation<EOL>self.mode = mode<EOL>
Initialise a new ``Position`` object. Args: time (datetime.time): Time the fix was taken status (bool): Whether the data is active latitude (float): Fix's latitude longitude (float): Fix's longitude speed (float): Ground speed track (float...
f12196:c1:m0
def __str__(self):
data = ['<STR_LIT>']<EOL>data.append(self.time.strftime('<STR_LIT>'))<EOL>data.append('<STR_LIT:A>' if self.status else '<STR_LIT>')<EOL>data.extend(nmea_latitude(self.latitude))<EOL>data.extend(nmea_longitude(self.longitude))<EOL>data.append('<STR_LIT>' % self.speed)<EOL>data.append('<STR_LIT>' % self.track)<EOL>data....
Pretty printed position string. Returns: str: Human readable string representation of ``Position`` object
f12196:c1:m1
def mode_string(self):
return MODE_INDICATOR.get(self.mode, '<STR_LIT>')<EOL>
Return a string version of the reading mode information. Returns: str: Quality information as string
f12196:c1:m2
@staticmethod<EOL><INDENT>def parse_elements(elements):<DEDENT>
if not len(elements) in (<NUM_LIT:11>, <NUM_LIT:12>):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>time = datetime.time(*[int(elements[<NUM_LIT:0>][i:i + <NUM_LIT:2>])<EOL>for i in range(<NUM_LIT:0>, <NUM_LIT:6>, <NUM_LIT:2>)])<EOL>active = True if elements[<NUM_LIT:1>] == '<STR_LIT:A>' else False<EOL>latitude...
Parse position data elements. Args: elements (list): Data values for position Returns: Position: Position object representing data
f12196:c1:m3
def __init__(self, time, latitude, longitude, quality, satellites,<EOL>dilution, altitude, geoid_delta, dgps_delta=None,<EOL>dgps_station=None, mode=None):
super(Fix, self).__init__(latitude, longitude)<EOL>self.time = time<EOL>self.quality = quality<EOL>self.satellites = satellites<EOL>self.dilution = dilution<EOL>self.altitude = altitude<EOL>self.geoid_delta = geoid_delta<EOL>self.dgps_delta = dgps_delta<EOL>self.dgps_station = dgps_station<EOL>self.mode = mode<EOL>
Initialise a new ``Fix`` object. Args: time (datetime.time): Time the fix was taken latitude (float): Fix's latitude longitude (float): Fix's longitude quality (int): Mode under which the fix was taken satellites (int): Number of tracked satellites ...
f12196:c2:m0
def __str__(self):
data = ['<STR_LIT>']<EOL>data.append(self.time.strftime('<STR_LIT>'))<EOL>data.extend(nmea_latitude(self.latitude))<EOL>data.extend(nmea_longitude(self.longitude))<EOL>data.append(str(self.quality))<EOL>data.append('<STR_LIT>' % self.satellites)<EOL>data.append('<STR_LIT>' % self.dilution)<EOL>data.append('<STR_LIT>' %...
Pretty printed location string. Returns: str: Human readable string representation of ``Fix`` object
f12196:c2:m1
def quality_string(self):
return self.fix_quality[self.quality]<EOL>
Return a string version of the quality information. Returns:: str: Quality information as string
f12196:c2:m2
@staticmethod<EOL><INDENT>def parse_elements(elements):<DEDENT>
if not len(elements) in (<NUM_LIT>, <NUM_LIT:15>):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>time = datetime.time(*[int(elements[<NUM_LIT:0>][i:i + <NUM_LIT:2>])<EOL>for i in range(<NUM_LIT:0>, <NUM_LIT:6>, <NUM_LIT:2>)])<EOL>latitude = parse_latitude(elements[<NUM_LIT:1>], elements[<NUM_LIT:2>])<EOL>longit...
Parse essential fix's data elements. Args: elements (list): Data values for fix Returns: Fix: Fix object representing data
f12196:c2:m3
def __init__(self, latitude, longitude, name):
super(Waypoint, self).__init__(latitude, longitude)<EOL>self.name = name.upper()<EOL>
Initialise a new ``Waypoint`` object. Args: latitude (float): Waypoint's latitude longitude (float): Waypoint's longitude name (str): Comment for waypoint
f12196:c3:m0
def __str__(self):
data = ['<STR_LIT>']<EOL>data.extend(nmea_latitude(self.latitude))<EOL>data.extend(nmea_longitude(self.longitude))<EOL>data.append(self.name)<EOL>data = '<STR_LIT:U+002C>'.join(data)<EOL>text = '<STR_LIT>' % (data, calc_checksum(data))<EOL>if len(text) > <NUM_LIT>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT...
Pretty printed location string. Returns: str: Human readable string representation of ``Waypoint`` object
f12196:c3:m1
@staticmethod<EOL><INDENT>def parse_elements(elements):<DEDENT>
if not len(elements) == <NUM_LIT:5>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>latitude = parse_latitude(elements[<NUM_LIT:0>], elements[<NUM_LIT:1>])<EOL>longitude = parse_longitude(elements[<NUM_LIT:2>], elements[<NUM_LIT:3>])<EOL>name = elements[<NUM_LIT:4>]<EOL>return Waypoint(latitude, longitude, name)...
Parse waypoint data elements. Args: elements (list): Data values for fix Returns: nmea.Waypoint: Object representing data
f12196:c3:m2
def __init__(self, gpsdata_file=None):
super(Locations, self).__init__()<EOL>self._gpsdata_file = gpsdata_file<EOL>if gpsdata_file:<EOL><INDENT>self.import_locations(gpsdata_file)<EOL><DEDENT>
Initialise a new ``Locations`` object.
f12196:c4:m0
def import_locations(self, gpsdata_file, checksum=True):
self._gpsdata_file = gpsdata_file<EOL>data = utils.prepare_read(gpsdata_file)<EOL>parsers = {<EOL>'<STR_LIT>': Fix,<EOL>'<STR_LIT>': Position,<EOL>'<STR_LIT>': Waypoint,<EOL>'<STR_LIT>': LoranPosition,<EOL>'<STR_LIT>': LoranPosition,<EOL>}<EOL>if not checksum:<EOL><INDENT>logging.warning('<STR_LIT>'<EOL>'<STR_LIT>'<EOL...
r"""Import GPS NMEA-formatted data files. ``import_locations()`` returns a list of `Fix` objects representing the fix sentences found in the GPS data. It expects data files in NMEA 0183 format, as specified in `the official documentation`_, which is ASCII text such as:: $G...
f12196:c4:m1
def __init__(self, ident, latitude, longitude, mcc, mnc, lac, cellid,<EOL>crange, samples, created, updated):
super(Cell, self).__init__(latitude, longitude)<EOL>self.ident = ident<EOL>self.mcc = mcc<EOL>self.mnc = mnc<EOL>self.lac = lac<EOL>self.cellid = cellid<EOL>self.crange = crange<EOL>self.samples = samples<EOL>self.created = created<EOL>self.updated = updated<EOL>
Initialise a new ``Cell`` object. Args: ident (int): OpenCellID database identifier latitude (float): Cell's latitude longitude (float): Cell's longitude mcc (int): Cell's country code mnc (int): Cell's network code lac (int): Cell's local...
f12198:c0:m0
def __str__(self):
return '<STR_LIT>'% (self.ident, self.latitude, self.longitude, self.mcc, self.mnc,<EOL>self.lac, self.cellid, self.crange, self.samples,<EOL>self.created.strftime('<STR_LIT>'),<EOL>self.updated.strftime('<STR_LIT>'))<EOL>
OpenCellID.org-style location string. See also: point.Point Returns: str: OpenCellID.org-style string representation of ``Cell`` object
f12198:c0:m1
def __init__(self, cells_file=None):
super(Cells, self).__init__()<EOL>self._cells_file = cells_file<EOL>if cells_file:<EOL><INDENT>self.import_locations(cells_file)<EOL><DEDENT>
Initialise a new ``Cells`` object.
f12198:c1:m0
def __str__(self):
return '<STR_LIT:\n>'.join(map(str, sorted(self.values(),<EOL>key=attrgetter('<STR_LIT>'))))<EOL>
``Cells`` objects rendered as export from OpenCellID.org. Returns: str: OpenCellID.org formatted output
f12198:c1:m1
def import_locations(self, cells_file):
self._cells_file = cells_file<EOL>field_names = ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>parse_date = lambda s: datetime.datetime.strptime(s,<EOL>'<STR_LIT>')<EOL>field_parsers = (int, float, float, int, int, ...
Parse OpenCellID.org data files. ``import_locations()`` returns a dictionary with keys containing the OpenCellID.org_ database identifier, and values consisting of a ``Cell`` objects. It expects cell files in the following format:: 22747,52.0438995361328,-0.2246370017529,2...
f12198:c1:m2
def __init__(self, latitude, longitude, antenna=None, direction=None,<EOL>frequency=None, height=None, locator=None, mode=None,<EOL>operator=None, power=None, qth=None):
if latitude is not None:<EOL><INDENT>super(Baken, self).__init__(latitude, longitude)<EOL><DEDENT>elif locator is not None:<EOL><INDENT>latitude, longitude = utils.from_grid_locator(locator)<EOL>super(Baken, self).__init__(latitude, longitude)<EOL><DEDENT>else:<EOL><INDENT>raise LookupError('<STR_LIT>'<EOL>'<STR_LIT>')...
Initialise a new ``Baken`` object. Args: latitude (float): Location's latitude longitude (float): Location's longitude antenna (str): Location's antenna type direction (tuple of int): Antenna's direction frequency (float): Transmitter's frequency ...
f12199:c0:m0
@locator.setter<EOL><INDENT>def locator(self, value):<DEDENT>
self._locator = value<EOL>self._latitude, self._longitude = utils.from_grid_locator(value)<EOL>
Update the locator, and trigger a latitude and longitude update. Args: value (str): New Maidenhead locator string
f12199:c0:m2
def __str__(self):
text = super(Baken, self).__format__('<STR_LIT>')<EOL>if self._locator:<EOL><INDENT>text = '<STR_LIT>' % (self._locator, text)<EOL><DEDENT>return text<EOL>
Pretty printed location string. Args: mode (str): Coordinate formatting system to use Returns: str: Human readable string representation of ``Baken`` object
f12199:c0:m3
def __init__(self, baken_file=None):
super(Bakens, self).__init__()<EOL>if baken_file:<EOL><INDENT>self.import_locations(baken_file)<EOL><DEDENT>
Initialise a new `Bakens` object.
f12199:c1:m0
def import_locations(self, baken_file):
self._baken_file = baken_file<EOL>data = ConfigParser()<EOL>if hasattr(baken_file, '<STR_LIT>'):<EOL><INDENT>data.readfp(baken_file)<EOL><DEDENT>elif isinstance(baken_file, list):<EOL><INDENT>data.read(baken_file)<EOL><DEDENT>elif isinstance(baken_file, basestring):<EOL><INDENT>data.readfp(open(baken_file))<EOL><DEDENT...
Import baken data files. ``import_locations()`` returns a dictionary with keys containing the section title, and values consisting of a collection :class:`Baken` objects. It expects data files in the format used by the baken_ amateur radio package, which is Windows INI style fi...
f12199:c1:m1
def __init__(self, location, country, zone, comments=None):
latitude, longitude = utils.from_iso6709(location + '<STR_LIT:/>')[:<NUM_LIT:2>]<EOL>super(Zone, self).__init__(latitude, longitude)<EOL>self.country = country<EOL>self.zone = zone<EOL>self.comments = comments<EOL>
Initialise a new ``Zone`` object. Args: location (str): Primary location in ISO 6709 format country (str): Location's ISO 3166 country code zone (str): Location's zone name as used in zoneinfo database comments (list): Location's alternate names
f12200:c0:m0
def __repr__(self):
location = utils.to_iso6709(self.latitude, self.longitude,<EOL>format='<STR_LIT>')[:-<NUM_LIT:1>]<EOL>return utils.repr_assist(self, {'<STR_LIT:location>': location})<EOL>
Self-documenting string representation. Returns: str: String to recreate ``Zone`` object
f12200:c0:m1
def __str__(self):
text = ['<STR_LIT>' % (self.zone, self.country,<EOL>super(Zone, self).__format__('<STR_LIT>')), ]<EOL>if self.comments:<EOL><INDENT>text.append('<STR_LIT>' + '<STR_LIT:U+002CU+0020>'.join(self.comments))<EOL><DEDENT>text.append('<STR_LIT:)>')<EOL>return '<STR_LIT>'.join(text)<EOL>
Pretty printed location string. Args: mode (str): Coordinate formatting system to use Returns: str: Human readable string representation of ``Zone`` object
f12200:c0:m2
def __init__(self, zone_file=None):
super(Zones, self).__init__()<EOL>self._zone_file = zone_file<EOL>if zone_file:<EOL><INDENT>self.import_locations(zone_file)<EOL><DEDENT>
Initialise a new Zones object.
f12200:c1:m0
def import_locations(self, zone_file):
self._zone_file = zone_file<EOL>field_names = ('<STR_LIT>', '<STR_LIT:location>', '<STR_LIT>', '<STR_LIT>')<EOL>data = utils.prepare_csv_read(zone_file, field_names, delimiter=r"<STR_LIT:U+0020>")<EOL>for row in (x for x in data if not x['<STR_LIT>'].startswith('<STR_LIT:#>')):<EOL><INDENT>if row['<STR_LIT>']:<EOL><IND...
Parse zoneinfo zone description data files. ``import_locations()`` returns a list of :class:`Zone` objects. It expects data files in one of the following formats:: AN +1211-06900 America/Curacao AO -0848+01314 Africa/Luanda AQ -7750+16636 Antarctica/McMurdo McMurdo...
f12200:c1:m1
def dump_zone_file(self):
data = []<EOL>for zone in sorted(self, key=attrgetter('<STR_LIT>')):<EOL><INDENT>text = ['<STR_LIT>'<EOL>% (zone.country,<EOL>utils.to_iso6709(zone.latitude, zone.longitude,<EOL>format='<STR_LIT>')[:-<NUM_LIT:1>],<EOL>zone.zone), ]<EOL>if zone.comments:<EOL><INDENT>text.append('<STR_LIT>' % '<STR_LIT:U+002CU+0020>'.joi...
Generate a zoneinfo compatible zone description table. Returns: list: zoneinfo descriptions
f12200:c1:m2
def __init__(self, geonameid, name, asciiname, alt_names, latitude,<EOL>longitude, feature_class, feature_code, country, alt_country,<EOL>admin1, admin2, admin3, admin4, population, altitude, gtopo30,<EOL>tzname, modified_date, timezone=None):
super(Location, self).__init__(latitude, longitude, altitude, name)<EOL>self.geonameid = geonameid<EOL>self.name = name<EOL>self.asciiname = asciiname<EOL>self.alt_names = alt_names<EOL>self.latitude = latitude<EOL>self.longitude = longitude<EOL>self.feature_class = feature_class<EOL>self.feature_code = feature_code<EO...
Initialise a new ``Location`` object. Args: geonameid (int): ID of record in geonames database name (unicode): Name of geographical location asciiname (str): Name of geographical location in ASCII encoding alt_names (list of unicode): Alternate names for the loca...
f12201:c0:m0
def __str__(self):
return self.__format__()<EOL>
Pretty printed location string. See also: trigpoints.point.Point Returns: str: Human readable string representation of ``Location`` object
f12201:c0:m1
def __format__(self, format_spec='<STR_LIT>'):
text = super(Location.__base__, self).__format__(format_spec)<EOL>if self.alt_names:<EOL><INDENT>return '<STR_LIT>' % (self.name, '<STR_LIT:U+002CU+0020>'.join(self.alt_names),<EOL>text)<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>' % (self.name, text)<EOL><DEDENT>
Extended pretty printing for location strings. Args: format_spec (str): Coordinate formatting system to use Returns: str: Human readable string representation of ``Point`` object Raises: ValueError: Unknown value for ``format_spec``
f12201:c0:m2
def __init__(self, data=None, tzfile=None):
super(Locations, self).__init__()<EOL>if tzfile:<EOL><INDENT>self.import_timezones_file(tzfile)<EOL><DEDENT>else:<EOL><INDENT>self.timezones = {}<EOL><DEDENT>self._data = data<EOL>self._tzfile = tzfile<EOL>if data:<EOL><INDENT>self.import_locations(data)<EOL><DEDENT>
Initialise a new ``Locations`` object.
f12201:c1:m0
def import_locations(self, data):
self._data = data<EOL>field_names = ('<STR_LIT>', '<STR_LIT:name>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>comma_split...
Parse geonames.org country database exports. ``import_locations()`` returns a list of :class:`trigpoints.Trigpoint` objects generated from the data exported by geonames.org_. It expects data files in the following tab separated format:: 2633441 Afon Wyre Afon Wyre River Wayrai,Riv...
f12201:c1:m1
def import_timezones_file(self, data):
self._tzfile = data<EOL>field_names = ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>time_parse = lambda n: int(float(n) * <NUM_LIT>)<EOL>data = utils.prepare_csv_read(data, field_names, delimiter=r"<STR_LIT:U+0020>")<EOL>self.timezones = {}<EOL>for row in data:<EOL><INDENT>if row['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>...
Parse geonames.org_ timezone exports. ``import_timezones_file()`` returns a dictionary with keys containing the timezone identifier, and values consisting of a UTC offset and UTC offset during daylight savings time in minutes. It expects data files in the following format:: ...
f12201:c1:m2
def __init__(self, identifier, name, ptype, region, country, location,<EOL>population, size, latitude, longitude, altitude, date,<EOL>entered):
super(City, self).__init__(latitude, longitude, altitude, name)<EOL>self.identifier = identifier<EOL>self.ptype = ptype<EOL>self.region = region<EOL>self.country = country<EOL>self.location = location<EOL>self.population = population<EOL>self.size = size<EOL>self.date = date<EOL>self.entered = entered<EOL>
Initialise a new ``City`` object. Args: identifier (int): Numeric identifier for object name (str): Place name ptype (str): Type of place region (str): Region place can be found country (str): Country name place can be found location (str)...
f12203:c0:m0
def __str__(self):
values = map(utils.value_or_empty,<EOL>(self.identifier, self.ptype,<EOL>self.population, self.size,<EOL>self.name, self.country,<EOL>self.region, self.location,<EOL>self.latitude, self.longitude,<EOL>self.altitude,<EOL>time.strftime('<STR_LIT>', self.date) if self.date else '<STR_LIT>',<EOL>self.entered))<EOL>return T...
Pretty printed location string. Returns: str: Human readable string representation of ``City`` object
f12203:c0:m1
def __init__(self, data=None):
super(Cities, self).__init__()<EOL>self._data = data<EOL>if data:<EOL><INDENT>self.import_locations(data)<EOL><DEDENT>
Initialise a new ``Cities`` object.
f12203:c1:m0
def import_locations(self, data):
self._data = data<EOL>if hasattr(data, '<STR_LIT>'):<EOL><INDENT>data = data.read().split('<STR_LIT>')<EOL><DEDENT>elif isinstance(data, list):<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(data, basestring):<EOL><INDENT>data = open(data).read().split('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>...
Parse `GNU miscfiles`_ cities data files. ``import_locations()`` returns a list containing :class:`City` objects. It expects data files in the same format that `GNU miscfiles`_ provides, that is:: ID : 1 Type : City Population : 210700 ...
f12203:c1:m1
def _parse_flags(element):
visible = True if element.get('<STR_LIT>') else False<EOL>user = element.get('<STR_LIT:user>')<EOL>timestamp = element.get('<STR_LIT>')<EOL>if timestamp:<EOL><INDENT>timestamp = utils.Timestamp.parse_isoformat(timestamp)<EOL><DEDENT>tags = {}<EOL>try:<EOL><INDENT>for tag in element['<STR_LIT>']:<EOL><INDENT>key = tag.g...
Parse OSM XML element for generic data. Args: element (etree.Element): Element to parse Returns: tuple: Generic OSM data for object instantiation
f12204:m0
def _get_flags(osm_obj):
flags = []<EOL>if osm_obj.visible:<EOL><INDENT>flags.append('<STR_LIT>')<EOL><DEDENT>if osm_obj.user:<EOL><INDENT>flags.append('<STR_LIT>' % osm_obj.user)<EOL><DEDENT>if osm_obj.timestamp:<EOL><INDENT>flags.append('<STR_LIT>' % osm_obj.timestamp.isoformat())<EOL><DEDENT>if osm_obj.tags:<EOL><INDENT>flags.append('<STR_L...
Create element independent flags output. Args: osm_obj (Node): Object with OSM-style metadata Returns: list: Human readable flags output
f12204:m1
def get_area_url(location, distance):
locations = [location.destination(i, distance) for i in range(<NUM_LIT:0>, <NUM_LIT>, <NUM_LIT>)]<EOL>latitudes = list(map(attrgetter('<STR_LIT>'), locations))<EOL>longitudes = list(map(attrgetter('<STR_LIT>'), locations))<EOL>bounds = (min(longitudes), min(latitudes), max(longitudes), max(latitudes))<EOL>return ('<STR...
Generate URL for downloading OSM data within a region. This function defines a boundary box where the edges touch a circle of ``distance`` kilometres in radius. It is important to note that the box is neither a square, nor bounded within the circle. The bounding box is strictly a trapezoid whose nort...
f12204:m2
def __init__(self, ident, latitude, longitude, visible=False, user=None,<EOL>timestamp=None, tags=None):
super(Node, self).__init__(latitude, longitude)<EOL>self.ident = ident<EOL>self.visible = visible<EOL>self.user = user<EOL>self.timestamp = timestamp<EOL>self.tags = tags<EOL>
Initialise a new ``Node`` object. Args: ident (int): Unique identifier for the node latitude (float): Nodes's latitude longitude (float): Node's longitude visible (bool): Whether the node is visible user (str): User who logged the node tim...
f12204:c0:m0
def __str__(self):
text = ['<STR_LIT>' % (self.ident,<EOL>super(Node, self).__format__('<STR_LIT>')), ]<EOL>flags = _get_flags(self)<EOL>if flags:<EOL><INDENT>text.append('<STR_LIT>' % '<STR_LIT:U+002CU+0020>'.join(flags))<EOL><DEDENT>return '<STR_LIT:U+0020>'.join(text)<EOL>
Pretty printed location string. Returns: str: Human readable string representation of ``Node`` object
f12204:c0:m1
def toosm(self):
node = create_elem('<STR_LIT>', {'<STR_LIT:id>': str(self.ident),<EOL>'<STR_LIT>': str(self.latitude),<EOL>'<STR_LIT>': str(self.longitude)})<EOL>node.set('<STR_LIT>', '<STR_LIT:true>' if self.visible else '<STR_LIT:false>')<EOL>if self.user:<EOL><INDENT>node.set('<STR_LIT:user>', self.user)<EOL><DEDENT>if self.timesta...
Generate a OSM node element subtree. Returns: etree.Element: OSM node element
f12204:c0:m2
def get_area_url(self, distance):
return get_area_url(self, distance)<EOL>
Generate URL for downloading OSM data within a region. Args: distance (int): Boundary distance in kilometres Returns: str: URL that can be used to fetch the OSM data within ``distance`` of ``location``
f12204:c0:m3
def fetch_area_osm(self, distance):
return Osm(urlopen(get_area_url(self, distance)))<EOL>
Fetch, and import, an OSM region. Args: distance (int): Boundary distance in kilometres Returns: Osm: All the data OSM has on a region imported for use
f12204:c0:m4
@staticmethod<EOL><INDENT>def parse_elem(element):<DEDENT>
ident = int(element.get('<STR_LIT:id>'))<EOL>latitude = element.get('<STR_LIT>')<EOL>longitude = element.get('<STR_LIT>')<EOL>flags = _parse_flags(element)<EOL>return Node(ident, latitude, longitude, *flags)<EOL>
Parse a OSM node XML element. Args: element (etree.Element): XML Element to parse Returns: Node: Object representing parsed element
f12204:c0:m5
def __init__(self, ident, nodes, visible=False, user=None, timestamp=None,<EOL>tags=None):
super(Way, self).__init__()<EOL>self.extend(nodes)<EOL>self.ident = ident<EOL>self.visible = visible<EOL>self.user = user<EOL>self.timestamp = timestamp<EOL>self.tags = tags<EOL>
Initialise a new ``Way`` object. Args: ident (int): Unique identifier for the way nodes (list of str): Identifiers of the nodes that form this way visible (bool): Whether the way is visible user (str): User who logged the way timestamp (str): The date...
f12204:c1:m0
def __repr__(self):
return utils.repr_assist(self, {'<STR_LIT>': self[:]})<EOL>
Self-documenting string representation. Returns:: str: String to recreate ``Way`` object
f12204:c1:m1
def __str__(self, nodes=False):
text = ['<STR_LIT>' % (self.ident), ]<EOL>if not nodes:<EOL><INDENT>text.append('<STR_LIT>' % str(self[:])[<NUM_LIT:1>:-<NUM_LIT:1>])<EOL><DEDENT>flags = _get_flags(self)<EOL>if flags:<EOL><INDENT>text.append('<STR_LIT>' % '<STR_LIT:U+002CU+0020>'.join(flags))<EOL><DEDENT>if nodes:<EOL><INDENT>text.append('<STR_LIT:\n>...
Pretty printed location string. Args: nodes (list): Nodes to be used in expanding references Returns: str: Human readable string representation of ``Way`` object
f12204:c1:m2
def toosm(self):
way = create_elem('<STR_LIT>', {'<STR_LIT:id>': str(self.ident)})<EOL>way.set('<STR_LIT>', '<STR_LIT:true>' if self.visible else '<STR_LIT:false>')<EOL>if self.user:<EOL><INDENT>way.set('<STR_LIT:user>', self.user)<EOL><DEDENT>if self.timestamp:<EOL><INDENT>way.set('<STR_LIT>', self.timestamp.isoformat())<EOL><DEDENT>i...
Generate a OSM way element subtree. Returns: etree.Element: OSM way element
f12204:c1:m3
@staticmethod<EOL><INDENT>def parse_elem(element):<DEDENT>
ident = int(element.get('<STR_LIT:id>'))<EOL>flags = _parse_flags(element)<EOL>nodes = [node.get('<STR_LIT>') for node in element.findall('<STR_LIT>')]<EOL>return Way(ident, nodes, *flags)<EOL>
Parse a OSM way XML element. Args: element (etree.Element): XML Element to parse Returns: Way: `Way` object representing parsed element
f12204:c1:m4
def __init__(self, osm_file=None):
super(Osm, self).__init__()<EOL>self._osm_file = osm_file<EOL>if osm_file:<EOL><INDENT>self.import_locations(osm_file)<EOL><DEDENT>self.generator = ua_string<EOL>self.version = '<STR_LIT>'<EOL>
Initialise a new ``Osm`` object.
f12204:c2:m0
def import_locations(self, osm_file):
self._osm_file = osm_file<EOL>data = utils.prepare_xml_read(osm_file, objectify=True)<EOL>if not data.tag == '<STR_LIT>':<EOL><INDENT>raise ValueError("<STR_LIT>" % data.tag)<EOL><DEDENT>self.version = data.get('<STR_LIT:version>')<EOL>if not self.version:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>elif not ...
Import OSM data files. ``import_locations()`` returns a list of ``Node`` and ``Way`` objects. It expects data files conforming to the `OpenStreetMap 0.5 DTD`_, which is XML such as:: <?xml version="1.0" encoding="UTF-8"?> <osm version="0.5" generator="upoints/0.9.0"> ...
f12204:c2:m1
def export_osm_file(self):
osm = create_elem('<STR_LIT>', {'<STR_LIT>': self.generator,<EOL>'<STR_LIT:version>': self.version})<EOL>osm.extend(obj.toosm() for obj in self)<EOL>return etree.ElementTree(osm)<EOL>
Generate OpenStreetMap element tree from ``Osm``.
f12204:c2:m2
def value_or_empty(value):
return value if value else '<STR_LIT>'<EOL>
Return an empty string for display when value is ``None``. Args: value (str): Value to prepare for display Returns: str: String representation of ``value``
f12205:m0
def repr_assist(obj, remap=None):
if not remap:<EOL><INDENT>remap = {}<EOL><DEDENT>data = []<EOL>for arg in inspect.getargspec(getattr(obj.__class__, '<STR_LIT>'))[<NUM_LIT:0>]:<EOL><INDENT>if arg == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>elif arg in remap:<EOL><INDENT>value = remap[arg]<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>value = get...
Helper function to simplify ``__repr__`` methods. Args: obj: Object to pull argument values for remap (dict): Argument pairs to remap before output Returns: str: Self-documenting representation of ``value``
f12205:m1
def prepare_read(data, method='<STR_LIT>', mode='<STR_LIT:r>'):
if hasattr(data, '<STR_LIT>'):<EOL><INDENT>data = getattr(data, method)()<EOL><DEDENT>elif isinstance(data, list):<EOL><INDENT>if method == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>'.join(data)<EOL><DEDENT><DEDENT>elif isinstance(data, basestring):<EOL><INDENT>data = getattr(open(data, mode), method)()<EOL><DEDENT>els...
Prepare various input types for parsing. Args: data (iter): Data to read method (str): Method to process data with mode (str): Custom mode to process with, if data is a file Returns: list: List suitable for parsing Raises: TypeError: Invalid value for data
f12205:m2
def prepare_csv_read(data, field_names, *args, **kwargs):
if hasattr(data, '<STR_LIT>') or isinstance(data, list):<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(data, basestring):<EOL><INDENT>data = open(data)<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>' % type(data))<EOL><DEDENT>return csv.DictReader(data, field_names, *args, **kwargs)<EOL>
Prepare various input types for CSV parsing. Args: data (iter): Data to read field_names (tuple of str): Ordered names to assign to fields Returns: csv.DictReader: CSV reader suitable for parsing Raises: TypeError: Invalid value for data
f12205:m3
def prepare_xml_read(data, objectify=False):
mod = _objectify if objectify else etree<EOL>if hasattr(data, '<STR_LIT>'):<EOL><INDENT>data = mod.parse(data).getroot()<EOL><DEDENT>elif isinstance(data, list):<EOL><INDENT>data = mod.fromstring('<STR_LIT>'.join(data))<EOL><DEDENT>elif isinstance(data, basestring):<EOL><INDENT>data = mod.parse(open(data)).getroot()<EO...
Prepare various input types for XML parsing. Args: data (iter): Data to read objectify (bool): Parse using lxml's objectify data binding Returns: etree.ElementTree: Tree suitable for parsing Raises: TypeError: Invalid value for data
f12205:m4
def element_creator(namespace=None):
ELEMENT_MAKER = _objectify.ElementMaker(namespace=namespace,<EOL>annotate=False)<EOL>def create_elem(tag, attr=None, text=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not attr:<EOL><INDENT>attr = {}<EOL><DEDENT>if text:<EOL><INDENT>element = getattr(ELEMENT_MAKER, tag)(text, **attr)<EOL><DEDENT>else:<EOL><INDENT>element =...
Create a simple namespace-aware objectify element creator. Args: namespace (str): Namespace to work in Returns: function: Namespace-aware element creator
f12205:m5
def to_dms(angle, style='<STR_LIT>'):
sign = <NUM_LIT:1> if angle >= <NUM_LIT:0> else -<NUM_LIT:1><EOL>angle = abs(angle) * <NUM_LIT><EOL>minutes, seconds = divmod(angle, <NUM_LIT>)<EOL>degrees, minutes = divmod(minutes, <NUM_LIT>)<EOL>if style == '<STR_LIT>':<EOL><INDENT>return tuple(sign * abs(i) for i in (int(degrees), int(minutes),<EOL>seconds))<EOL><D...
Convert decimal angle to degrees, minutes and possibly seconds. Args: angle (float): Angle to convert style (str): Return fractional or whole minutes values Returns: tuple of int: Angle converted to degrees, minutes and possibly seconds Raises: ValueError: Unknown value fo...
f12205:m6
def to_dd(degrees, minutes, seconds=<NUM_LIT:0>):
sign = -<NUM_LIT:1> if any(i < <NUM_LIT:0> for i in (degrees, minutes, seconds)) else <NUM_LIT:1><EOL>return sign * (abs(degrees) + abs(minutes) / <NUM_LIT> + abs(seconds) / <NUM_LIT>)<EOL>
Convert degrees, minutes and optionally seconds to decimal angle. Args: degrees (float): Number of degrees minutes (float): Number of minutes seconds (float): Number of seconds Returns: float: Angle converted to decimal degrees
f12205:m7
def __chunk(segment, abbr=False):
names = ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>if not abbr:<EOL><INDENT>sjoin = '<STR_LIT:->'<EOL><DEDENT>else:<EOL><INDENT>names = [s[<NUM_LIT:0>].upper() for s in names]<EOL>sjoin = '<STR_LIT>'<EOL><DEDENT>if segment % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>return (names[segment].capit...
Generate a ``tuple`` of compass direction names. Args: segment (list): Compass segment to generate names for abbr (bool): Names should use single letter abbreviations Returns: bool: Direction names for compass segment
f12205:m8
def angle_to_name(angle, segments=<NUM_LIT:8>, abbr=False):
if segments == <NUM_LIT:4>:<EOL><INDENT>string = COMPASS_NAMES[int((angle + <NUM_LIT>) / <NUM_LIT>) % <NUM_LIT:4> * <NUM_LIT:2>]<EOL><DEDENT>elif segments == <NUM_LIT:8>:<EOL><INDENT>string = COMPASS_NAMES[int((angle + <NUM_LIT>) / <NUM_LIT>) % <NUM_LIT:8> * <NUM_LIT:2>]<EOL><DEDENT>elif segments == <NUM_LIT:16>:<EOL><...
Convert angle in to direction name. Args: angle (float): Angle in degrees to convert to direction name segments (int): Number of segments to split compass in to abbr (bool): Whether to return abbreviated direction string Returns: str: Direction name for ``angle``
f12205:m9
def from_iso6709(coordinates):
matches = iso6709_matcher.match(coordinates)<EOL>if matches:<EOL><INDENT>latitude, longitude, altitude = matches.groups()<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>sign = <NUM_LIT:1> if latitude[<NUM_LIT:0>] == '<STR_LIT:+>' else -<NUM_LIT:1><EOL>latitude_head = len(latitude.split('<STR_LI...
Parse ISO 6709 coordinate strings. This function will parse ISO 6709-1983(E) "Standard representation of latitude, longitude and altitude for geographic point locations" elements. Unfortunately, the standard is rather convoluted and this implementation is incomplete, but it does support most of the com...
f12205:m10
def to_iso6709(latitude, longitude, altitude=None, format='<STR_LIT>', precision=<NUM_LIT:4>):
text = []<EOL>if format == '<STR_LIT:d>':<EOL><INDENT>text.append('<STR_LIT>' % (latitude, longitude))<EOL><DEDENT>elif format == '<STR_LIT>':<EOL><INDENT>text.append('<STR_LIT>' % (precision + <NUM_LIT:4>, precision, latitude,<EOL>precision + <NUM_LIT:5>, precision, longitude))<EOL><DEDENT>elif format in ('<STR_LIT>',...
Produce ISO 6709 coordinate strings. This function will produce ISO 6709-1983(E) "Standard representation of latitude, longitude and altitude for geographic point locations" elements. See also: from_iso6709 Args: latitude (float): Location's latitude longitude (float): Location...
f12205:m11
def angle_to_distance(angle, units='<STR_LIT>'):
distance = math.radians(angle) * BODY_RADIUS<EOL>if units in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return distance<EOL><DEDENT>elif units in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return distance / STATUTE_MILE<EOL><DEDENT>elif units in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return distance / NAUTICAL_...
Convert angle in to distance along a great circle. Args: angle (float): Angle in degrees to convert to distance units (str): Unit type to be used for distances Returns: float: Distance in ``units`` Raises: ValueError: Unknown value for ``units``
f12205:m12
def distance_to_angle(distance, units='<STR_LIT>'):
if units in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>pass<EOL><DEDENT>elif units in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>distance *= STATUTE_MILE<EOL><DEDENT>elif units in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>distance *= NAUTICAL_MILE<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % units)...
Convert a distance in to an angle along a great circle. Args: distance (float): Distance to convert to degrees units (str): Unit type to be used for distances Returns: float: Angle in degrees Raises: ValueError: Unknown value for ``units``
f12205:m13
def from_grid_locator(locator):
if not len(locator) in (<NUM_LIT:4>, <NUM_LIT:6>, <NUM_LIT:8>):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>% locator)<EOL><DEDENT>locator = list(locator)<EOL>locator[<NUM_LIT:0>] = ord(locator[<NUM_LIT:0>]) - <NUM_LIT><EOL>locator[<NUM_LIT:1>] = ord(locator[<NUM_LIT:1>]) - <NUM_LIT><EOL>locator[<NUM_LIT:2>] = int(loc...
Calculate geodesic latitude/longitude from Maidenhead locator. Args: locator (str): Maidenhead locator string Returns: tuple of float: Geodesic latitude and longitude values Raises: ValueError: Incorrect grid locator length ValueError: Invalid values in locator string
f12205:m14
def to_grid_locator(latitude, longitude, precision='<STR_LIT>'):
if precision not in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>raise ValueError('<STR_LIT>' % precision)<EOL><DEDENT>if not -<NUM_LIT> <= latitude <= <NUM_LIT>:<EOL><INDENT>raise ValueError('<STR_LIT>' % latitude)<EOL><DEDENT>if not -<NUM_LIT> <= longitude <= <NUM_LIT>:<EOL><INDENT>raise ValueError('<STR_LIT>...
Calculate Maidenhead locator from latitude and longitude. Args: latitude (float): Position's latitude longitude (float): Position's longitude precision (str): Precision with which generate locator string Returns: str: Maidenhead locator for latitude and longitude Raise: ...
f12205:m15
def parse_location(location):
def split_dms(text, hemisphere):<EOL><INDENT>"""<STR_LIT>"""<EOL>out = []<EOL>sect = []<EOL>for i in text:<EOL><INDENT>if i.isdigit():<EOL><INDENT>sect.append(i)<EOL><DEDENT>else:<EOL><INDENT>out.append(sect)<EOL>sect = []<EOL><DEDENT><DEDENT>d, m, s = [float('<STR_LIT>'.join(i)) for i in out]<EOL>if hemisphere in '<ST...
Parse latitude and longitude from string location. Args: location (str): String to parse Returns: tuple of float: Latitude and longitude of location
f12205:m16
def sun_rise_set(latitude, longitude, date, mode='<STR_LIT>', timezone=<NUM_LIT:0>,<EOL>zenith=None):
if not date:<EOL><INDENT>date = datetime.date.today()<EOL><DEDENT>zenith = ZENITH[zenith]<EOL>n = (date - datetime.date(date.year - <NUM_LIT:1>, <NUM_LIT:12>, <NUM_LIT>)).days<EOL>lng_hour = longitude / <NUM_LIT:15><EOL>if mode == '<STR_LIT>':<EOL><INDENT>t = n + ((<NUM_LIT:6> - lng_hour) / <NUM_LIT>)<EOL><DEDENT>elif ...
Calculate sunrise or sunset for a specific location. This function calculates the time sunrise or sunset, or optionally the beginning or end of a specified twilight period. Source:: Almanac for Computers, 1990 published by Nautical Almanac Office United States Naval Observatory ...
f12205:m17
def sun_events(latitude, longitude, date, timezone=<NUM_LIT:0>, zenith=None):
return (sun_rise_set(latitude, longitude, date, '<STR_LIT>', timezone, zenith),<EOL>sun_rise_set(latitude, longitude, date, '<STR_LIT>', timezone, zenith))<EOL>
Convenience function for calculating sunrise and sunset. Civil twilight starts/ends when the Sun's centre is 6 degrees below the horizon. Nautical twilight starts/ends when the Sun's centre is 12 degrees below the horizon. Astronomical twilight starts/ends when the Sun's centre is 18 degrees belo...
f12205:m18
def dump_xearth_markers(markers, name='<STR_LIT>'):
output = []<EOL>for identifier, point in markers.items():<EOL><INDENT>line = ['<STR_LIT>' % (point.latitude, point.longitude), ]<EOL>if hasattr(point, '<STR_LIT:name>') and point.name:<EOL><INDENT>if name == '<STR_LIT>':<EOL><INDENT>line.append('<STR_LIT>' % (identifier, point.name))<EOL><DEDENT>elif name == '<STR_LIT:...
Generate an Xearth compatible marker file. ``dump_xearth_markers()`` writes a simple Xearth_ marker file from a dictionary of :class:`trigpoints.Trigpoint` objects. It expects a dictionary in one of the following formats. For support of :class:`Trigpoint` that is:: {500936: Trigpoint(52.06603...
f12205:m19
def calc_radius(latitude, ellipsoid='<STR_LIT>'):
ellipsoids = {<EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>), <EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>),<EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>),<EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>), <EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>),<EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>),<EOL>'<STR_LIT>': (<NUM_LIT>, <NUM_LIT>),<EOL>'<STR_LIT>...
Calculate earth radius for a given latitude. This function is most useful when dealing with datasets that are very localised and require the accuracy of an ellipsoid model without the complexity of code necessary to actually use one. The results are meant to be used as a :data:`BODY_RADIUS` replacemen...
f12205:m20
def __init__(self, site=None):
super(FileFormatError, self).__init__()<EOL>self.site = site<EOL>
Initialise a new ``FileFormatError`` object. Args: site (str): Remote site name to display in error message
f12205:c0:m0
def __str__(self):
if self.site:<EOL><INDENT>return ("<STR_LIT>"<EOL>'<STR_LIT>' % (self.site,<EOL>__bug_report__))<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>
Pretty printed error string. Returns: str: Human readable error string
f12205:c0:m1
def __init__(self, tzstring):
super(TzOffset, self).__init__()<EOL>hours, minutes = map(int, tzstring.split('<STR_LIT::>'))<EOL>self.__offset = datetime.timedelta(hours=hours, minutes=minutes)<EOL>
Initialise a new ``TzOffset`` object. Args:: tzstring (str): `ISO 8601`_ style timezone definition .. _ISO 8601: http://www.cl.cam.ac.uk/~mgk25/iso-time.html
f12205:c1:m0
def __repr__(self):
return repr_assist(self, {'<STR_LIT>': self.as_timezone()})<EOL>
Self-documenting string representation. Returns: str: String to recreate ``TzOffset`` object
f12205:c1:m1
def dst(self, dt=None):
return datetime.timedelta(<NUM_LIT:0>)<EOL>
Daylight Savings Time offset. Note: This method is only for compatibility with the ``tzinfo`` interface, and does nothing Args: dt (any): For compatibility with parent classes
f12205:c1:m2
def as_timezone(self):
offset = self.utcoffset()<EOL>hours, minutes = divmod(offset.seconds / <NUM_LIT>, <NUM_LIT>)<EOL>if offset.days == -<NUM_LIT:1>:<EOL><INDENT>hours = -<NUM_LIT> + hours<EOL><DEDENT>return '<STR_LIT>' % (hours, minutes)<EOL>
Create a human-readable timezone string. Returns: str: Human-readable timezone definition
f12205:c1:m3
def utcoffset(self, dt=None):
return self.__offset<EOL>
Return the offset in minutes from UTC. Args: dt (any): For compatibility with parent classes
f12205:c1:m4
def isoformat(self):
text = [self.strftime('<STR_LIT>'), ]<EOL>if self.tzinfo:<EOL><INDENT>text.append(self.tzinfo.as_timezone())<EOL><DEDENT>else:<EOL><INDENT>text.append('<STR_LIT>')<EOL><DEDENT>return '<STR_LIT>'.join(text)<EOL>
Generate an ISO 8601 formatted time stamp. Returns: str: `ISO 8601`_ formatted time stamp .. _ISO 8601: http://www.cl.cam.ac.uk/~mgk25/iso-time.html
f12205:c2:m0
@staticmethod<EOL><INDENT>def parse_isoformat(timestamp):<DEDENT>
if len(timestamp) == <NUM_LIT:20>:<EOL><INDENT>zone = TzOffset('<STR_LIT>')<EOL>timestamp = timestamp[:-<NUM_LIT:1>]<EOL><DEDENT>elif len(timestamp) == <NUM_LIT>:<EOL><INDENT>zone = TzOffset('<STR_LIT>' % (timestamp[-<NUM_LIT:5>:-<NUM_LIT:2>], timestamp[-<NUM_LIT:2>:]))<EOL>timestamp = timestamp[:-<NUM_LIT:5>]<EOL><DED...
Parse an ISO 8601 formatted time stamp. Args: timestamp (str): Timestamp to parse Returns: Timestamp: Parsed timestamp
f12205:c2:m1
def __init__(self, alt_id, name, state, country, wmo, latitude, longitude,<EOL>ua_latitude, ua_longitude, altitude, ua_altitude, rbsn):
super(Station, self).__init__(latitude, longitude, altitude, name)<EOL>self.alt_id = alt_id<EOL>self.state = state<EOL>self.country = country<EOL>self.wmo = wmo<EOL>self.ua_latitude = ua_latitude<EOL>self.ua_longitude = ua_longitude<EOL>self.ua_altitude = ua_altitude<EOL>self.rbsn = rbsn<EOL>
Initialise a new ``Station`` object. Args: alt_id (str): Alternate location identifier name (str): Station's name state (str): State name, if station is in the US country (str): Country name wmo (int): WMO region code latitude (float): Sta...
f12206:c0:m0
def __str__(self):
return self.__format__()<EOL>
Pretty printed location string. See also: ``trigpoints.point.Point`` Returns: str: Human readable string representation of ``Station`` object
f12206:c0:m1
def __format__(self, format_spec='<STR_LIT>'):
text = super(Station.__base__, self).__format__(format_spec)<EOL>if self.alt_id:<EOL><INDENT>return '<STR_LIT>' % (self.name, self.alt_id, text)<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>' % (self.name, text)<EOL><DEDENT>
Extended pretty printing for location strings. Args: format_spec str: Coordinate formatting system to use Returns: Human readable string representation of ``Point`` object Raises: ValueError: Unknown value for ``format_spec``
f12206:c0:m2
def __init__(self, data=None, index='<STR_LIT>'):
super(Stations, self).__init__()<EOL>self._data = data<EOL>self._index = index<EOL>if data:<EOL><INDENT>self.import_locations(data, index)<EOL><DEDENT>
Initialise a new `Stations` object.
f12206:c1:m0
def import_locations(self, data, index='<STR_LIT>'):
self._data = data<EOL>data = utils.prepare_read(data)<EOL>for line in data:<EOL><INDENT>line = line.strip()<EOL>chunk = line.split('<STR_LIT:;>')<EOL>if not len(chunk) == <NUM_LIT>:<EOL><INDENT>if index == '<STR_LIT>':<EOL><INDENT>logging.debug('<STR_LIT>'<EOL>'<STR_LIT>' % line)<EOL>chunk.extend(['<STR_LIT>', '<STR_LI...
Parse NOAA weather station data files. ``import_locations()`` returns a dictionary with keys containing either the WMO or ICAO identifier, and values that are ``Station`` objects that describes the large variety of data exported by NOAA_. It expects data files in one of the following f...
f12206:c1:m1
@cli.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, help='<STR_LIT>')<EOL>@click.pass_obj<EOL>def bearing(globs, string):
globs.locations.bearing('<STR_LIT>', string)<EOL>
Calculate initial bearing between locations.
f12207:m1
@cli.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>',<EOL>type=click.Choice(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']),<EOL>default='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>@click.argument('<STR_LIT>', type=float)<EOL>@click.argument('<STR_LIT>', type=float)<EOL>@click.pass_obj<EOL>def destination(globs, locator, dist...
globs.locations.destination(distance, bearing, locator)<EOL>
Calculate destination from locations.
f12207:m2
@cli.command()<EOL>@click.option('<STR_LIT>', '<STR_LIT>',<EOL>type=click.Choice(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']),<EOL>help='<STR_LIT>')<EOL>@click.pass_obj<EOL>def display(globs, locator):
globs.locations.display(locator)<EOL>
Pretty print the locations.
f12207:m3