4
4
import os
5
5
from dataclasses import dataclass
6
6
from types import MappingProxyType
7
- from typing import Dict , List , Optional
7
+ from typing import Dict , List , Optional , Tuple
8
8
9
9
import yaml
10
-
11
10
from ohsome_quality_analyst .base .layer import LayerDefinition
12
11
from ohsome_quality_analyst .config import get_config_value
13
12
from ohsome_quality_analyst .utils .exceptions import RasterDatasetUndefinedError
14
- from ohsome_quality_analyst .utils .helper import flatten_sequence , get_module_dir
13
+ from ohsome_quality_analyst .utils .helper import (flatten_sequence ,
14
+ get_module_dir )
15
15
16
16
17
17
@dataclass (frozen = True )
@@ -30,6 +30,22 @@ class RasterDataset:
30
30
nodata : Optional [int ]
31
31
32
32
33
+ @dataclass (frozen = True )
34
+ class IndicatorLayerThreshold :
35
+ """Valid Indicator/Layer combinations with optional threshold values.
36
+
37
+ Args:
38
+ indicator (str): Indicator name
39
+ layer (str): Layer name
40
+ thresholds (tuple): A tuple with thresholds values.
41
+ First element of the tuple is the threshold between result class 1 and 2.
42
+ """
43
+
44
+ indicator : str
45
+ layer : str
46
+ threshold : Tuple [float , float , float , float ] = None
47
+
48
+
33
49
RASTER_DATASETS = (
34
50
RasterDataset (
35
51
"GHS_BUILT_R2018A" ,
@@ -58,57 +74,57 @@ class RasterDataset:
58
74
)
59
75
60
76
# 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" ),
77
+ INDICATOR_LAYER_THRESHOLDS = (
78
+ IndicatorLayerThreshold ("BuildingCompleteness" , "building_area" ),
79
+ IndicatorLayerThreshold ("GhsPopComparisonBuildings" , "building_count" ),
80
+ IndicatorLayerThreshold ("GhsPopComparisonRoads" , "jrc_road_length" ),
81
+ IndicatorLayerThreshold ("GhsPopComparisonRoads" , "major_roads_length" ),
82
+ IndicatorLayerThreshold ("MappingSaturation" , "building_count" ),
83
+ IndicatorLayerThreshold ("MappingSaturation" , "major_roads_length" ),
84
+ IndicatorLayerThreshold ("MappingSaturation" , "amenities" ),
85
+ IndicatorLayerThreshold ("MappingSaturation" , "jrc_health_count" ),
86
+ IndicatorLayerThreshold ("MappingSaturation" , "jrc_mass_gathering_sites_count" ),
87
+ IndicatorLayerThreshold ("MappingSaturation" , "jrc_railway_length" ),
88
+ IndicatorLayerThreshold ("MappingSaturation" , "jrc_road_length" ),
89
+ IndicatorLayerThreshold ("MappingSaturation" , "jrc_education_count" ),
90
+ IndicatorLayerThreshold ("MappingSaturation" , "mapaction_settlements_count" ),
91
+ IndicatorLayerThreshold ("MappingSaturation" , "mapaction_major_roads_length" ),
92
+ IndicatorLayerThreshold ("MappingSaturation" , "mapaction_rail_length" ),
93
+ IndicatorLayerThreshold ("MappingSaturation" , "mapaction_lakes_area" ),
94
+ IndicatorLayerThreshold ("MappingSaturation" , "mapaction_rivers_length" ),
95
+ IndicatorLayerThreshold ("MappingSaturation" , "ideal_vgi_infrastructure" ),
96
+ IndicatorLayerThreshold ("MappingSaturation" , "poi" ),
97
+ IndicatorLayerThreshold ("MappingSaturation" , "lulc" ),
98
+ IndicatorLayerThreshold ("Currentness" , "major_roads_count" ),
99
+ IndicatorLayerThreshold ("Currentness" , "building_count" ),
100
+ IndicatorLayerThreshold ("Currentness" , "amenities" ),
101
+ IndicatorLayerThreshold ("Currentness" , "jrc_health_count" ),
102
+ IndicatorLayerThreshold ("Currentness" , "jrc_education_count" ),
103
+ IndicatorLayerThreshold ("Currentness" , "jrc_road_count" ),
104
+ IndicatorLayerThreshold ("Currentness" , "jrc_railway_count" ),
105
+ IndicatorLayerThreshold ("Currentness" , "jrc_airport_count" ),
106
+ IndicatorLayerThreshold ("Currentness" , "jrc_water_treatment_plant_count" ),
107
+ IndicatorLayerThreshold ("Currentness" , "jrc_power_generation_plant_count" ),
108
+ IndicatorLayerThreshold ("Currentness" , "jrc_cultural_heritage_site_count" ),
109
+ IndicatorLayerThreshold ("Currentness" , "jrc_bridge_count" ),
110
+ IndicatorLayerThreshold ("Currentness" , "jrc_mass_gathering_sites_count" ),
111
+ IndicatorLayerThreshold ("Currentness" , "mapaction_settlements_count" ),
112
+ IndicatorLayerThreshold ("Currentness" , "mapaction_major_roads_length" ),
113
+ IndicatorLayerThreshold ("Currentness" , "mapaction_rail_length" ),
114
+ IndicatorLayerThreshold ("Currentness" , "mapaction_lakes_count" ),
115
+ IndicatorLayerThreshold ("Currentness" , "mapaction_rivers_length" ),
116
+ IndicatorLayerThreshold ("PoiDensity" , "poi" ),
117
+ IndicatorLayerThreshold ("TagsRatio" , "building_count" ),
118
+ IndicatorLayerThreshold ("TagsRatio" , "major_roads_length" ),
119
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_health_count" ),
120
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_education_count" ),
121
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_road_length" ),
122
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_airport_count" ),
123
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_power_generation_plant_count" ),
124
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_cultural_heritage_site_count" ),
125
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_bridge_count" ),
126
+ IndicatorLayerThreshold ("TagsRatio" , "jrc_mass_gathering_sites_count" ),
127
+ IndicatorLayerThreshold ("Minimal" , "minimal" ),
112
128
)
113
129
114
130
ATTRIBUTION_TEXTS = MappingProxyType (
@@ -274,9 +290,11 @@ def get_attribution(data_keys: list) -> str:
274
290
275
291
def get_valid_layers (indcator_name : str ) -> tuple :
276
292
"""Get valid Indicator/Layer combination of an Indicator."""
277
- return tuple ([tup [1 ] for tup in INDICATOR_LAYER if tup [0 ] == indcator_name ])
293
+ return tuple (
294
+ [tup [1 ] for tup in INDICATOR_LAYER_THRESHOLDS if tup [0 ] == indcator_name ]
295
+ )
278
296
279
297
280
298
def get_valid_indicators (layer_key : str ) -> tuple :
281
299
"""Get valid Indicator/Layer combination of a Layer."""
282
- return tuple ([tup [0 ] for tup in INDICATOR_LAYER if tup [1 ] == layer_key ])
300
+ return tuple ([tup [0 ] for tup in INDICATOR_LAYER_THRESHOLDS if tup [1 ] == layer_key ])
0 commit comments