MESQUAL Folium Visualization System Base¶
base_viz_system
¶
PropertyMapper
¶
Maps data item attributes to visual properties for folium map visualization.
Core abstraction for converting model data, KPI values, or static values into visual properties (colors, sizes, positions, etc.) for map elements. Used throughout the folium visualization system to create dynamic, data-driven map styling.
The PropertyMapper encapsulates a transformation function that takes a VisualizableDataItem and returns a styled value. This enables powerful declarative map styling where visual properties are automatically computed from underlying data.
Examples:
Basic color mapping from KPI values:
>>> color_mapper = PropertyMapper.from_kpi_value(lambda v: 'red' if v > 0 else 'blue')
Size mapping from model attributes:
>>> size_mapper = PropertyMapper.from_item_attr('capacity', lambda c: c / 100)
Static styling:
>>> border_mapper = PropertyMapper.from_static_value('#000000')
Complex conditional styling:
>>> def complex_color(data_item: KPIDataItem):
... kpi_val = data_item.kpi.value
... threshold = data_item.get_object_attribute('threshold')
... return 'green' if kpi_val > threshold else 'red'
>>> mapper = PropertyMapper(complex_color)
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
from_static_value
classmethod
¶
from_static_value(value: Any) -> PropertyMapper
Create mapper that returns the same value for all data items.
Used for consistent styling across all map elements (e.g., all borders the same color, all markers the same size).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Static value to return for all data items |
required |
Returns:
| Type | Description |
|---|---|
PropertyMapper
|
PropertyMapper that always returns the static value |
Examples:
>>> border_color = PropertyMapper.from_static_value('#FFFFFF')
>>> opacity = PropertyMapper.from_static_value(0.8)
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
from_item_attr
classmethod
¶
from_item_attr(attribute: str, mapping: Callable[[Any], Any] = None) -> PropertyMapper
Create mapper from model/object attribute with optional transformation.
Extracts values from model data attributes (geometry, capacity, name, etc.) and optionally applies a transformation function. The attribute is resolved from the underlying model DataFrame or object data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attribute
|
str
|
Name of the attribute to extract (e.g., 'geometry', 'capacity'), must be an entry in the object pd.Series |
required |
mapping
|
Callable[[Any], Any]
|
Optional transformation function to apply to the attribute value |
None
|
Returns:
| Type | Description |
|---|---|
PropertyMapper
|
PropertyMapper that extracts and optionally transforms the attribute |
Examples:
>>> # Direct attribute access
>>> geom_mapper = PropertyMapper.from_item_attr('geometry')
>>>
>>> # With color scale transformation
>>> color_scale = SegmentedContinuousColorscale(...)
>>> color_mapper = PropertyMapper.from_item_attr('capacity', color_scale)
>>>
>>> # With custom transformation
>>> size_mapper = PropertyMapper.from_item_attr('power_mw',
... lambda mw: min(max(mw/10, 5), 50))
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
from_kpi_value
classmethod
¶
from_kpi_value(mapping: Callable[[Any], Any]) -> PropertyMapper
Create mapper from KPI values with transformation function.
Specifically designed for KPIDataItem objects, extracts the computed KPI value and applies a transformation. Used for styling based on energy system metrics like power flows, prices, or emissions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
Callable[[Any], Any]
|
Transformation function applied to the KPI value |
required |
Returns:
| Type | Description |
|---|---|
PropertyMapper
|
PropertyMapper that transforms KPI values |
Examples:
>>> # Color mapping for power flows
>>> flow_colors = PropertyMapper.from_kpi_value(
... lambda v: 'red' if v > 1000 else 'green'
... )
>>>
>>> # Size mapping for prices
>>> price_sizes = PropertyMapper.from_kpi_value(
... lambda p: min(max(p * 2, 10), 100)
... )
>>>
>>> # Using value mapping system
>>> colorscale = SegmentedContinuousColorscale(...)
>>> colors = PropertyMapper.from_kpi_value(colorscale)
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
ResolvedFeature
dataclass
¶
Container for resolved feature properties.
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
FeatureResolver
¶
Bases: Generic[ResolvedFeatureType]
Resolves visual feature properties from data items using PropertyMappers.
Central orchestrator for map element styling that takes a VisualizableDataItem and a collection of PropertyMappers, then produces a ResolvedFeature containing all computed visual properties. Handles default values, tooltip generation, and property normalization.
The FeatureResolver acts as a bridge between data and visualization, converting raw data items into styled features ready for folium map rendering. It supports automatic tooltip/popup generation and flexible property mapping.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
ResolvedFeatureType
|
The specific resolved feature type (e.g., ResolvedAreaFeature) |
required |
Examples:
>>> resolver = AreaFeatureResolver(
... fill_color=PropertyMapper.from_kpi_value(color_scale),
... fill_opacity=PropertyMapper.from_static_value(0.8),
... tooltip=True # Auto-generate tooltip
... )
>>> resolved = resolver.resolve_feature(kpi_data_item)
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
FoliumObjectGenerator
¶
Bases: Generic[FeatureResolverType], ABC
Abstract base class for generating folium map objects from data items.
Defines the interface for converting VisualizableDataItems into folium map elements (areas, lines, markers, etc.). Each generator type handles a specific kind of map visualization and uses a corresponding FeatureResolver to compute visual properties.
The generator pattern enables modular, composable map building where different visualization types can be combined within the same map. Generators can process both model DataFrames and KPI collections.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
FeatureResolverType
|
The specific feature resolver type used by this generator |
required |
Examples:
Typical usage in map building:
>>> area_gen = AreaGenerator(AreaFeatureResolver(fill_color=...))
>>> line_gen = LineGenerator(LineFeatureResolver(line_color=...))
>>>
>>> fg = folium.FeatureGroup('My Data')
>>> area_gen.generate_objects_for_model_df(model_df, fg)
>>> line_gen.generate_objects_for_kpi_collection(kpi_collection, fg)
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
generate
abstractmethod
¶
generate(data_item: VisualizableDataItem, feature_group: FeatureGroup) -> None
Generate folium object and add it to the feature group.
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
396 397 398 399 | |
generate_objects_for_model_df
¶
generate_objects_for_model_df(model_df: DataFrame, feature_group: FeatureGroup, **kwargs) -> FeatureGroup
Add model DataFrame data to the map.
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
401 402 403 404 405 406 407 408 409 410 411 412 413 | |
generate_objects_for_kpi_collection
¶
generate_objects_for_kpi_collection(kpi_collection: KPICollection, feature_group: FeatureGroup, **kwargs) -> FeatureGroup
Add KPI data to the map.
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
415 416 417 418 419 420 421 422 423 424 425 | |
generate_object_for_single_kpi
¶
generate_object_for_single_kpi(kpi: KPI, feature_group: FeatureGroup, kpi_collection: KPICollection = None, **kwargs) -> FeatureGroup
Add a single KPI to the map with optional context.
Source code in submodules/mesqual/mesqual/visualizations/folium_viz_system/base_viz_system.py
427 428 429 430 431 432 433 434 435 436 437 | |