1
1
"""Global Variables and Functions."""
2
+ from __future__ import annotations
3
+
2
4
import glob
3
5
import logging
4
6
import os
5
7
from dataclasses import dataclass
6
8
from types import MappingProxyType
7
- from typing import Dict , List , Optional
9
+ from typing import Dict , List , Literal , Optional , Tuple
8
10
9
11
import yaml
10
12
@@ -57,63 +59,6 @@ class RasterDataset:
57
59
),
58
60
)
59
61
60
- # Possible indicator layer combinations
61
- INDICATOR_LAYER = (
62
- ("BuildingCompleteness" , "building_area" ),
63
- ("GhsPopComparisonBuildings" , "building_count" ),
64
- ("GhsPopComparisonRoads" , "jrc_road_length" ),
65
- ("GhsPopComparisonRoads" , "major_roads_length" ),
66
- ("MappingSaturation" , "building_count" ),
67
- ("MappingSaturation" , "major_roads_length" ),
68
- ("MappingSaturation" , "amenities" ),
69
- ("MappingSaturation" , "jrc_health_count" ),
70
- ("MappingSaturation" , "jrc_mass_gathering_sites_count" ),
71
- ("MappingSaturation" , "jrc_railway_length" ),
72
- ("MappingSaturation" , "jrc_road_length" ),
73
- ("MappingSaturation" , "jrc_education_count" ),
74
- ("MappingSaturation" , "mapaction_settlements_count" ),
75
- ("MappingSaturation" , "mapaction_major_roads_length" ),
76
- ("MappingSaturation" , "mapaction_rail_length" ),
77
- ("MappingSaturation" , "mapaction_lakes_area" ),
78
- ("MappingSaturation" , "mapaction_rivers_length" ),
79
- ("MappingSaturation" , "infrastructure_lines" ),
80
- ("MappingSaturation" , "poi" ),
81
- ("MappingSaturation" , "lulc" ),
82
- ("Currentness" , "major_roads_count" ),
83
- ("Currentness" , "building_count" ),
84
- ("Currentness" , "amenities" ),
85
- ("Currentness" , "jrc_health_count" ),
86
- ("Currentness" , "jrc_education_count" ),
87
- ("Currentness" , "jrc_road_count" ),
88
- ("Currentness" , "jrc_railway_count" ),
89
- ("Currentness" , "jrc_airport_count" ),
90
- ("Currentness" , "jrc_water_treatment_plant_count" ),
91
- ("Currentness" , "jrc_power_generation_plant_count" ),
92
- ("Currentness" , "jrc_cultural_heritage_site_count" ),
93
- ("Currentness" , "jrc_bridge_count" ),
94
- ("Currentness" , "jrc_mass_gathering_sites_count" ),
95
- ("Currentness" , "mapaction_settlements_count" ),
96
- ("Currentness" , "mapaction_major_roads_length" ),
97
- ("Currentness" , "mapaction_rail_length" ),
98
- ("Currentness" , "mapaction_lakes_count" ),
99
- ("Currentness" , "mapaction_rivers_length" ),
100
- ("Currentness" , "infrastructure_lines" ),
101
- ("Currentness" , "poi" ),
102
- ("Currentness" , "lulc" ),
103
- ("PoiDensity" , "poi" ),
104
- ("TagsRatio" , "building_count" ),
105
- ("TagsRatio" , "major_roads_length" ),
106
- ("TagsRatio" , "jrc_health_count" ),
107
- ("TagsRatio" , "jrc_education_count" ),
108
- ("TagsRatio" , "jrc_road_length" ),
109
- ("TagsRatio" , "jrc_airport_count" ),
110
- ("TagsRatio" , "jrc_power_generation_plant_count" ),
111
- ("TagsRatio" , "jrc_cultural_heritage_site_count" ),
112
- ("TagsRatio" , "jrc_bridge_count" ),
113
- ("TagsRatio" , "jrc_mass_gathering_sites_count" ),
114
- ("Minimal" , "minimal" ),
115
- )
116
-
117
62
ATTRIBUTION_TEXTS = MappingProxyType (
118
63
{
119
64
"OSM" : "© OpenStreetMap contributors" ,
@@ -128,17 +73,16 @@ class RasterDataset:
128
73
)
129
74
130
75
131
- def load_metadata (module_name : str ) -> Dict :
132
- """Read metadata of all indicators or reports from YAML files.
76
+ def load_metadata (module_name : Literal [ "indicators" , "reports" ] ) -> Dict :
77
+ """Load metadata of all indicators or reports from YAML files.
133
78
134
- Those text files are located in the directory of each indicator/ report.
79
+ The YAML files are located in the directory of each individual indicator or report.
135
80
136
- Args:
137
- module_name: Either indicators or reports.
138
81
Returns:
139
- A Dict with the class names of the indicators/reports
140
- as keys and metadata as values.
82
+ A dictionary with the indicator or report keys as directory keys and the content
83
+ of the YAML file ( metadata) as values.
141
84
"""
85
+ # TODO: Is this check needed if Literal is used in func declaration?
142
86
if module_name != "indicators" and module_name != "reports" :
143
87
raise ValueError ("module name value can only be 'indicators' or 'reports'." )
144
88
@@ -275,11 +219,15 @@ def get_attribution(data_keys: list) -> str:
275
219
return "; " .join ([str (v ) for v in filtered .values ()])
276
220
277
221
222
+ # TODO
278
223
def get_valid_layers (indcator_name : str ) -> tuple :
279
224
"""Get valid Indicator/Layer combination of an Indicator."""
280
- return tuple ([tup [1 ] for tup in INDICATOR_LAYER if tup [0 ] == indcator_name ])
225
+ return tuple (
226
+ [tup [1 ] for tup in INDICATOR_LAYER_THRESHOLDS if tup [0 ] == indcator_name ]
227
+ )
281
228
282
229
230
+ # TODO
283
231
def get_valid_indicators (layer_key : str ) -> tuple :
284
232
"""Get valid Indicator/Layer combination of a Layer."""
285
- return tuple ([tup [0 ] for tup in INDICATOR_LAYER if tup [1 ] == layer_key ])
233
+ return tuple ([tup [0 ] for tup in INDICATOR_LAYER_THRESHOLDS if tup [1 ] == layer_key ])
0 commit comments