-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_langfam_genus.py
More file actions
56 lines (41 loc) · 1.69 KB
/
add_langfam_genus.py
File metadata and controls
56 lines (41 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 8 12:50:00 2022
@author: TuoVaisanen-e01
"""
import pandas as pd
import geopandas as gpd
import argparse
# set up argument parser
ap = argparse.ArgumentParser()
# Get path to input file
ap.add_argument("-fam", "--family", required=True,
help="Path to input 250 m grid with calculated diversity based on language families. The filenames need to be '[YEAR]_langfam_diversity_euref250.pkl.")
# Get path to input file
ap.add_argument("-g", "--grid", required=True,
help="Path to folder containing grid geopackages per year. The filenames need to be 'HMA_langs_div_[YEAR].gpkg")
# Get path to output file
ap.add_argument("-o", "--output", required=True,
help="Path to output folder. For example: /path/to/folder/. The files are called 'HMA_langs_fam_div_[YEAR].gpkg'")
# parse arguments
args = vars(ap.parse_args())
# get paths
gridpath = args['grid']
fampath = args['family']
outpath = args['output']
# loop over years
for i in range (1987,2020):
# print messages
print('[INFO] - Processing year ' + str(i) + '...')
# read hma data in
hma = gpd.read_file(gridpath + 'HMA_langs_div_{}.gpkg'.format(str(i)))
# read national divs in
fam = pd.read_pickle(fampath + str(i) + '_langfam_diversity_euref250.pkl')
# join data
hma = pd.merge(hma, fam, on='euref_250', how='left')
# save to geopackge
print('[INFO] - Saving year ' + str(i) + '...')
hma.to_file(r'W:\maphel_langtime\geopackage\HMA_langs_famgen_div_{}.gpkg'.format(str(i)),
driver='GPKG')
# print final message
print('[INFO] - ... done!')