2020root = pathlib .Path (__file__ ).parent .absolute ()
2121figpath = root / "figures"
2222
23- UPDATE = True
23+ # whether to update the used dataset or use the precalculated data
24+ UPDATE = False
2425
2526
2627config = pm .get_config ()
2728
28- powerplants = pm .powerplants (update = UPDATE )
29+ powerplants = pm .powerplants (update = UPDATE , from_url = not UPDATE )
2930
3031
3132powerplants = powerplants .powerplant .convert_country_to_alpha2 ()
@@ -47,7 +48,7 @@ def parse(c):
4748 rename .get (c , c ), ** kwargs
4849 ).iloc [0 ]
4950 except Exception as e :
50- print (f"Country { c } failed with { e } " )
51+ print (f"Country { c } failed with { repr ( e ) } " )
5152 time .sleep (3 )
5253 return np .nan
5354
@@ -68,14 +69,17 @@ def parse(c):
6869
6970sources = [s if isinstance (s , str ) else list (s )[0 ] for s in config ["matching_sources" ]]
7071
71- input_dbs = {
72- s .title (): getattr (pm .data , s )()
73- .powerplant .convert_country_to_alpha2 ()
74- .query (query )
75- .powerplant .lookup ()
76- .fillna (0 )
77- for s in sources
78- }
72+ input_dbs = {}
73+ for s in sources :
74+ print (s .title ())
75+ input_dbs [s .title ()] = (
76+ getattr (pm .data , s )()
77+ .powerplant .convert_country_to_alpha2 ()
78+ .query (query )
79+ .powerplant .lookup ()
80+ .fillna (0 )
81+ )
82+
7983output_dbs = {
8084 s .title (): powerplants [
8185 powerplants .projectID .apply (lambda ds : s in ds )
@@ -103,7 +107,9 @@ def parse(c):
103107 diff [s .title () + " (%)" ] = ds .fillna (0 )
104108
105109diff = diff [out_compare .Statistics != 0 ]
106- diff = diff .loc [:, list (set (out_compare .index .unique (1 )) - {"Wind" , "Solar" }), :]
110+ diff = diff .loc [
111+ :, list (set (out_compare .index .unique (1 )) - {"Biogas" , "Wind" , "Solar" }), :
112+ ]
107113diff .index = diff .index .get_level_values (0 ) + " " + diff .index .get_level_values (1 )
108114
109115df = (diff [diff .Difference > 1 ]).sort_values ("Difference" , ascending = False )
@@ -125,6 +131,8 @@ def parse(c):
125131# country figures #
126132# ---------------------------------------------------------------------------- #
127133
134+ (figpath / "country-comparison" ).mkdir (parents = True , exist_ok = True )
135+
128136fig , ax = plt .subplots (figsize = (5 , 20 ))
129137diff [diff .abs () > 2 ].plot .barh (ax = ax , zorder = 3 )
130138ax .set_xlabel ("Capacity difference (stats - ppm) [GW]" )
0 commit comments