11"""Global Variables and Functions."""
2+ from __future__ import annotations
3+
24import glob
35import logging
46import os
57from dataclasses import dataclass
68from types import MappingProxyType
7- from typing import Dict , List , Optional
9+ from typing import Dict , List , Literal , Optional , Tuple
810
911import yaml
1012
@@ -57,63 +59,6 @@ class RasterDataset:
5759 ),
5860)
5961
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-
11762ATTRIBUTION_TEXTS = MappingProxyType (
11863 {
11964 "OSM" : "© OpenStreetMap contributors" ,
@@ -128,17 +73,16 @@ class RasterDataset:
12873)
12974
13075
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.
13378
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.
13580
136- Args:
137- module_name: Either indicators or reports.
13881 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.
14184 """
85+ # TODO: Is this check needed if Literal is used in func declaration?
14286 if module_name != "indicators" and module_name != "reports" :
14387 raise ValueError ("module name value can only be 'indicators' or 'reports'." )
14488
@@ -275,11 +219,15 @@ def get_attribution(data_keys: list) -> str:
275219 return "; " .join ([str (v ) for v in filtered .values ()])
276220
277221
222+ # TODO
278223def get_valid_layers (indcator_name : str ) -> tuple :
279224 """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+ )
281228
282229
230+ # TODO
283231def get_valid_indicators (layer_key : str ) -> tuple :
284232 """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