-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwho_do_what.py
65 lines (58 loc) · 2.35 KB
/
who_do_what.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Script to compare indices provided by xclim vs the ones of clix-meta.
The output is printed in stdout.
Needs icclim and xclim to be installed.
Run it with `python -m who_do_what`
"""
import xclim.indicators.seaIce
import xclim.indicators.atmos
import xclim.indicators.land
from icclim.clix_meta.clix_meta_indices import ClixMetaIndices
def get_xclim_index_name(module):
acc = []
for a in list(filter(lambda x: x[0] != "_", dir(module))):
acc.append(
(a,
module.__dict__[a]
.cf_attrs[0]
.get("standard_name", "no_standard_name")))
return acc
def main():
xclim_indices = []
xclim_indices += get_xclim_index_name(xclim.indicators.seaIce)
xclim_indices += get_xclim_index_name(xclim.indicators.atmos)
xclim_indices += get_xclim_index_name(xclim.indicators.land)
clix_meta = ClixMetaIndices.get_instance()
clix_indices = list(map(lambda x: (x, clix_meta.indices_record[x]["output"]["standard_name"]),
clix_meta.indices_record.keys()))
in_xclim_not_in_clix = []
in_clix_not_in_xclim = []
in_both = []
for xc in xclim_indices:
if xc[1] != "no_standard_name":
if xc[1].upper() not in list(
map(lambda clix: str(clix[1]).upper(), clix_indices)):
in_xclim_not_in_clix.append(xc)
else:
in_both.append((xc, "by standard_name"))
else:
if xc[0].upper() not in list(
map(lambda clix: str(clix[0]).upper(), clix_indices)):
in_xclim_not_in_clix.append(xc)
else:
in_both.append((xc, "by short name"))
for clix in clix_indices:
if clix[1] != "no_standard_name":
if str(clix[1]).upper() not in list(
map(lambda ind: str(ind[1]).upper(), xclim_indices)):
in_clix_not_in_xclim.append(clix)
else:
if str(clix[0]).upper() not in list(
map(lambda ind: str(ind[0]).upper(), xclim_indices)):
in_clix_not_in_xclim.append(clix)
# TODO: Improve output to create a csv or something similar
print(f"in_xclim_not_in_clix indices: {in_xclim_not_in_clix}")
print(f"in_clix_not_in_xclim indices: {in_clix_not_in_xclim}")
print(f"in_both indices: {in_both}")
if __name__ == '__main__':
main()