def get_genealogy(cls, infile='genealogy.html', refresh=False): ''' data[family][genus][language] ''' data = {} with open(cls.LANGUAGES) as fp: fieldnames = fp.readline().strip().split(',') csvreader = csv.DictReader(fp, fieldnames=fieldnames, delimiter=',') for row in csvreader: data.setdefault(row['family'], {'__name__': row['family']}) data[row['family']].setdefault(row['genus'], {'__name__': row['genus']}) data[row['family']][row['genus']][row['name']] = { '__name__': row['name'], '__code__': row['wals code'], '__lat__': row['latitude'], '__lng__': row['longitude'], '__area__': area.get_area( (row['longitude'], row['latitude'])) } return data
def main(): img = plt.imread(IMAGE_PATH) fig = plt.figure() plt.imshow(img) for cont in [Australia, EuropeAsia, Africa, NorthAmerica, SouthAmerica]: for poly in cont: subplot = fig.add_subplot(111) subplot.plot(map(X_SCALE, poly.longitudes()), map(Y_SCALE, poly.latitudes())) # for x, y in poly.data[0:]: # annotate(u"{},{}".format(x, y), x, y) g = Genealogy() for language in g.languages(): name = language.name.decode("utf-8") if language.area == "UNKNOWN": language.area = get_area((language.lng, language.lng)) print u"{}({}, {})".format(name, language.lng, language.lat) annotate( u"{}({:.3f}, {:.3f})".format(name, float(language.lng), float(language.lat)), language.lng, language.lat ) # fig.show()
def main(): img = plt.imread(IMAGE_PATH) fig = plt.figure() plt.imshow(img, ) for cont in [Australia, EuropeAsia, Africa, NorthAmerica, SouthAmerica]: for poly in cont: subplot = fig.add_subplot(111) subplot.plot(map(X_SCALE, poly.longitudes()), map(Y_SCALE, poly.latitudes())) #for x, y in poly.data[0:]: # annotate(u"{},{}".format(x, y), x, y) g = Genealogy() for language in g.languages(): name = language.name.decode('utf-8') if language.area == 'UNKNOWN': language.area = get_area((language.lng, language.lng)) print u"{}({}, {})".format(name, language.lng, language.lat) annotate( u"{}({:.3f}, {:.3f})".format(name, float(language.lng), float(language.lat)), language.lng, language.lat) # fig.show()
def __init__(self, data, genus=None, family=None): if isinstance(data, Language): self.name = data.name self.code = data.code self.lat = data.lat self.lng = data.lng self.area = data.area self.genus = data.genus self.family = data.family self.features = data.features else: self.name = data.pop('__name__') self.code = data.pop('__code__') self.lat = data.pop('__lat__', '') self.lng = data.pop('__lng__', '') self.area = data.pop('__area__', 'UNKNOWN') self.genus = genus self.family = family self.features = data.pop('__features__', {}) if self.area == 'UNKNOWN': self.area = get_area((self.lng, self.lat))
def __init__(self, data, genus=None, family=None): if isinstance(data, Language): self.name = data.name self.code = data.code self.lat = data.lat self.lng = data.lng self.area = data.area self.genus = data.genus self.family = data.family self.features = data.features else: self.name = data.pop("__name__") self.code = data.pop("__code__") self.lat = data.pop("__lat__", "") self.lng = data.pop("__lng__", "") self.area = data.pop("__area__", "UNKNOWN") self.genus = genus self.family = family self.features = data.pop("__features__", {}) if self.area == "UNKNOWN": self.area = get_area((self.lng, self.lat))
# -*- coding: utf-8 -*- #将函数作为模块使用 from area import get_area #from c.area import get_area #解决不同级的模块调用 print(get_area(3))