Models API¶
osm_powerplants.models
¶
Data models for OpenStreetMap power plant processing.
This module defines the core data structures used throughout the OSM module, including power plant units, geometries, and rejection tracking. It provides type-safe representations of OSM elements and their attributes.
Key components: Unit: Individual power plant representation Units: Collection of power plants with filtering and export PlantGeometry: Spatial representation with geometric operations RejectionReason: Enumeration of data quality issues
PROCESSING_PARAMETERS = ['capacity_extraction', 'capacity_estimation', 'units_clustering', 'source_mapping', 'technology_mapping', 'source_technology_mapping', 'plants_only', 'missing_name_allowed', 'missing_technology_allowed', 'missing_start_date_allowed', 'sources', 'units_reconstruction']
module-attribute
¶
Unit
dataclass
¶
Power plant unit data structure.
Represents a single power generation unit with standardized attributes. This is the core data structure for power plant information, compatible with powerplantmatching's standard format.
Attributes:
| Name | Type | Description |
|---|---|---|
projectID |
str
|
Unique identifier for the unit |
Country |
(str, optional)
|
Country name or code |
lat |
(float, optional)
|
Latitude coordinate |
lon |
(float, optional)
|
Longitude coordinate |
type |
(str, optional)
|
Plant type (e.g., 'plant', 'generator') |
Fueltype |
(str, optional)
|
Primary fuel type from standard list |
Technology |
(str, optional)
|
Generation technology from standard list |
Capacity |
(float, optional)
|
Electrical capacity in MW |
Name |
(str, optional)
|
Plant name |
generator_count |
(int, optional)
|
Number of generators if aggregated |
Set |
(str, optional)
|
Plant set type (PP, CHP, Store) |
capacity_source |
(str, optional)
|
How capacity was determined ('tag', 'estimated', etc.) |
DateIn |
(int, optional)
|
Commissioning year |
id |
(str, optional)
|
OSM element ID (e.g., 'node/123456') |
created_at |
(str, optional)
|
Timestamp when unit was processed |
config_hash |
(str, optional)
|
Hash of configuration used for processing |
config_version |
(str, optional)
|
Version of configuration |
processing_parameters |
(dict, optional)
|
Parameters used during processing |
Examples:
>>> unit = Unit(
... projectID="OSM_node_123456",
... Country="Germany",
... lat=52.5200,
... lon=13.4050,
... Fueltype="Solar",
... Technology="PV",
... Capacity=10.5
... )
Source code in src/osm_powerplants/models.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 168 169 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 | |
to_dict()
¶
is_valid_for_config(current_config)
¶
Check if unit was processed with compatible configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_config
|
dict
|
Current processing configuration |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if unit's config hash matches current config |
Source code in src/osm_powerplants/models.py
Units
¶
Collection of power plant units with filtering and analysis methods.
Provides methods for filtering, statistics, and exporting power plant data in various formats. Acts as a container for Unit objects with convenient access patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
list[Unit]
|
Initial list of units to store |
None
|
Examples:
>>> units = Units()
>>> units.add_unit(Unit(projectID="test1", Country="Germany"))
>>> units.filter_by_country("Germany")
<Units with 1 units>
>>> stats = units.get_statistics()
>>> units.save_csv("output.csv")
Source code in src/osm_powerplants/models.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | |
add_unit(unit)
¶
add_units(units)
¶
filter_by_country(country)
¶
Filter units by country.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country
|
str
|
Country name to filter by |
required |
Returns:
| Type | Description |
|---|---|
Units
|
New Units instance with filtered data |
Source code in src/osm_powerplants/models.py
filter_by_fueltype(fueltype)
¶
Filter units by fuel type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fueltype
|
str
|
Fuel type to filter by |
required |
Returns:
| Type | Description |
|---|---|
Units
|
New Units instance with filtered data |
Source code in src/osm_powerplants/models.py
filter_by_technology(technology)
¶
Filter units by technology.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
technology
|
str
|
Technology type to filter by |
required |
Returns:
| Type | Description |
|---|---|
Units
|
New Units instance with filtered data |
Source code in src/osm_powerplants/models.py
get_statistics()
¶
Calculate summary statistics for the collection.
Returns:
| Type | Description |
|---|---|
dict
|
Statistics including counts, capacity totals, and coverage |
Notes
Statistics include: - Total unit count - Units with valid coordinates - Coverage percentage - Unique countries, fuel types, and technologies - Total and average capacity
Source code in src/osm_powerplants/models.py
generate_geojson_report()
¶
Generate GeoJSON FeatureCollection from units.
Creates a GeoJSON representation suitable for mapping tools. Only includes units with valid coordinates.
Returns:
| Type | Description |
|---|---|
dict
|
GeoJSON FeatureCollection with power plant features |
Source code in src/osm_powerplants/models.py
save_geojson_report(filepath)
¶
Save units as GeoJSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to save GeoJSON file |
required |
Source code in src/osm_powerplants/models.py
to_dataframe()
¶
Convert units to pandas DataFrame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with unit data, empty if no units |
Source code in src/osm_powerplants/models.py
save_csv(filepath)
¶
Save units to CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to save CSV file |
required |
Source code in src/osm_powerplants/models.py
PlantGeometry
dataclass
¶
Spatial representation of a power plant.
Handles geometric operations for plant boundaries, supporting point, polygon, and multi-polygon geometries from OSM data.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
OSM element identifier |
type |
{node, way, relation}
|
OSM element type |
geometry |
geometry
|
Shapely geometry object (Point, Polygon, or MultiPolygon) |
element_data |
(dict, optional)
|
Original OSM element data |
Examples:
>>> from shapely.geometry import Point
>>> geom = PlantGeometry(
... id="way/123456",
... type="way",
... geometry=Point(13.4050, 52.5200)
... )
>>> geom.contains_point(52.5201, 13.4051, buffer_meters=100)
True
Source code in src/osm_powerplants/models.py
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 358 359 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 438 439 440 441 442 443 444 | |
bounds
property
¶
Get bounding box coordinates.
Returns:
| Type | Description |
|---|---|
tuple
|
(min_lon, min_lat, max_lon, max_lat) |
contains_point(lat, lon, buffer_meters=None)
¶
Check if a coordinate is within the plant geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude coordinate |
required |
lon
|
float
|
Longitude coordinate |
required |
buffer_meters
|
float
|
Buffer distance in meters. Default 50m for points. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if point is within geometry (with buffer if applicable) |
Source code in src/osm_powerplants/models.py
intersects(other, buffer_meters=None)
¶
Check if this geometry intersects with another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
PlantGeometry
|
Another plant geometry to check intersection with |
required |
buffer_meters
|
float
|
Buffer distance in meters for point geometries |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if geometries intersect |
Source code in src/osm_powerplants/models.py
get_centroid()
¶
Get the centroid coordinates of the geometry.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
(latitude, longitude) of centroid, or (None, None) if error |
Source code in src/osm_powerplants/models.py
buffer(distance_meters)
¶
Create a buffered version of this geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance_meters
|
float
|
Buffer distance in meters |
required |
Returns:
| Type | Description |
|---|---|
PlantGeometry
|
New geometry with buffer applied |
Source code in src/osm_powerplants/models.py
RejectionReason
¶
Bases: Enum
Enumeration of reasons why OSM elements are rejected during processing.
Each reason represents a specific data quality issue that prevents an element from being included in the final dataset.