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,60 +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" , "ideal_vgi_infrastructure" ),
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- ("PoiDensity" , "poi" ),
101- ("TagsRatio" , "building_count" ),
102- ("TagsRatio" , "major_roads_length" ),
103- ("TagsRatio" , "jrc_health_count" ),
104- ("TagsRatio" , "jrc_education_count" ),
105- ("TagsRatio" , "jrc_road_length" ),
106- ("TagsRatio" , "jrc_airport_count" ),
107- ("TagsRatio" , "jrc_power_generation_plant_count" ),
108- ("TagsRatio" , "jrc_cultural_heritage_site_count" ),
109- ("TagsRatio" , "jrc_bridge_count" ),
110- ("TagsRatio" , "jrc_mass_gathering_sites_count" ),
111- ("Minimal" , "minimal" ),
112- )
113-
11462ATTRIBUTION_TEXTS = MappingProxyType (
11563 {
11664 "OSM" : "© OpenStreetMap contributors" ,
@@ -125,17 +73,16 @@ class RasterDataset:
12573)
12674
12775
128- def load_metadata (module_name : str ) -> Dict :
129- """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.
13078
131- 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.
13280
133- Args:
134- module_name: Either indicators or reports.
13581 Returns:
136- A Dict with the class names of the indicators/reports
137- 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.
13884 """
85+ # TODO: Is this check needed if Literal is used in func declaration?
13986 if module_name != "indicators" and module_name != "reports" :
14087 raise ValueError ("module name value can only be 'indicators' or 'reports'." )
14188
@@ -272,11 +219,15 @@ def get_attribution(data_keys: list) -> str:
272219 return "; " .join ([str (v ) for v in filtered .values ()])
273220
274221
222+ # TODO
275223def get_valid_layers (indcator_name : str ) -> tuple :
276224 """Get valid Indicator/Layer combination of an Indicator."""
277- 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+ )
278228
279229
230+ # TODO
280231def get_valid_indicators (layer_key : str ) -> tuple :
281232 """Get valid Indicator/Layer combination of a Layer."""
282- 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