- Notifications
You must be signed in to change notification settings - Fork 406
/
Copy pathcheck_missing_locations.py
executable file
·48 lines (39 loc) · 2.36 KB
/
check_missing_locations.py
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
importargparse
importpandasaspd
if__name__=='__main__':
parser=argparse.ArgumentParser(
description="Check for missing colors & locations",
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument('--metadata', type=str, nargs='+', required=True, help="input region adjusted metadata")
parser.add_argument('--colors', type=str, nargs='+', required=True, help="input region specific color file")
parser.add_argument('--latlong', type=str, required=True, help="input lat-long file")
args=parser.parse_args()
things_to_exclude_orig= ['Africa', 'Asia', 'South America', 'Europe',
'North America', 'Oceania', 'Grand princess cruise ship',
'diamond princess']
things_to_exclude= [x.lower() forxinthings_to_exclude_orig]
all_metadatas= [pd.read_csv(met, delimiter='\t') formetinargs.metadata]
metadata=pd.concat(all_metadatas, sort=False)
all_colors= [pd.read_csv(col, delimiter='\t', header=None) forcolinargs.colors]
colors=pd.concat(all_colors, sort=False)
latlong=pd.read_csv(args.latlong, delimiter='\t', header=None)
forgeo_valuein ['location', 'division', 'country']:
locs_w_color_orig=colors.loc[colors[0]==geo_value,1].values
locs_w_color= [x.lower() forxinlocs_w_color_orig]
locs_w_latlong_orig=latlong.loc[latlong[0]==geo_value,1].values
locs_w_latlong= [x.lower() forxinlocs_w_latlong_orig]
locs_in_meta_orig= [xforxinmetadata[geo_value].unique() ifnotpd.isna(x)]
locs_in_meta= [x.lower() forxinlocs_in_meta_orig]
missing_color_locs= [locforlocinlocs_in_metaiflocnotinlocs_w_colorandlocnotinthings_to_exclude]
ifmissing_color_locs:
print("The following {} are missing colors:".format(geo_value))
print(missing_color_locs)
print("\n")
ifgeo_value!='country':
missing_latlong_locs= [locforlocinlocs_in_metaiflocnotinlocs_w_latlongandlocnotinthings_to_exclude]
ifmissing_latlong_locs:
print("The following {} are missing lat-long values:".format(geo_value))
print(missing_latlong_locs)
print("\n")
print("Please remember this does *not* check lat-longs for countries!!")