API reference¶
Generated from the docstrings.
Bulk API¶
characterize_roofs ¶
characterize_roofs(polygons, service='fr-lidar', *, crs=None, params=None, split=False, workers=8, id_column=None, meta_prefix='meta_', progress=None, capacity=None, tilt=30.0)
Characterizes the roof planes under a set of polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygons
|
GeoDataFrame, DataFrame with a geometry column, GeoJSON dict,
|
list of features / shapely geometries, or a path (GeoJSON, GeoPackage, (Geo)Parquet, ...). See geometry.to_geodataframe. |
required |
service
|
a DSMService, a service name from pypvroof.catalog
|
|
'fr-lidar'
|
crs
|
CRS of the input when it does not carry one (default EPSG:4326)
|
|
None
|
params
|
dict or TheilSenParams, estimator parameters
|
|
None
|
split
|
split multimodal polygons into homogeneous parts
|
|
False
|
workers
|
number of polygons processed concurrently (threads). The work is
|
dominated by I/O for remote services; mind their usage limits. |
8
|
id_column
|
column identifying the input polygons, copied into
|
|
None
|
meta_prefix
|
prefix of the columns holding the service metadata
|
|
'meta_'
|
progress
|
optional callable(done, total)
|
|
None
|
capacity
|
None (no capacity), "constant", "linear", "clustered" or a
|
coefficient in kWp/m²: adds an |
None
|
tilt
|
tilt (degrees) given by the heuristics (service=None only)
|
|
30.0
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame with the input columns (renamed with an `_input` suffix when
|
|
they clash with the output ones), parent_id, part, the result columns
|
|
(tilt, azimuth, status, inspect, surface_proj, surface, diagnostics) and
|
|
the service metadata.
|
|
Source code in pypvroof/bulk.py
Installed capacity¶
installed_capacity ¶
installed_capacity(surface, method='constant', *, coefficient=DEFAULT_COEFFICIENT, clusters=4, data=None)
Installed capacity (kWp) from the panel surface (m²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface
|
float or array - like
|
Panel surface in m² ( |
required |
method
|
str or float
|
"constant", "linear", "clustered", or a coefficient in kWp/m². |
'constant'
|
coefficient
|
float
|
Coefficient of the "constant" method (kWp/m²). |
DEFAULT_COEFFICIENT
|
clusters
|
int
|
Number of surface classes of the "clustered" method. |
4
|
data
|
DataFrame
|
Calibration registry with columns |
None
|
Returns:
| Type | Description |
|---|---|
float for a scalar input, numpy array otherwise.
|
|
Source code in pypvroof/capacity.py
Heuristics¶
bbox_azimuth ¶
(azimuth, elongation) of each polygon, from its minimum rotated rectangle.
geoms are shapely geometries in a projected (metric) CRS. The azimuth is
in degrees, 0 = north, clockwise, in [90, 270]; the elongation is the long
side over the short side of the rectangle. NaN for empty geometries.
Source code in pypvroof/heuristics.py
Theil-Sen¶
TheilSenParams
dataclass
¶
Parameters of the estimator. Distances in metres, angles in degrees.
estimate ¶
Estimates tilt and azimuth from an elevation grid.
z : 2D elevations (NaN = no data) transform : affine transform of the grid (metres) mask : boolean grid, pixels to use (polygon, usually eroded) edge_distance : optional grid, distance (m) of each pixel to the polygon's edge; enables the edge-band test for secondary planes return_labels : also return (rows, cols, labels, planes) for splitting
Returns a dict: status, inspect, tilt, azimuth, n_pixels, n_modes, primary_share, inlier_frac, rmse, roughness, offset_suspected, modes (list of {tilt, azimuth, share}).
Source code in pypvroof/theilsen.py
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 | |
Services¶
get_service ¶
Builds a service from a specification:
- a DSMService instance (returned as is)
- a name from the catalogue (pypvroof.catalog), e.g. "fr-lidar"
(IGNLidarService), "fr-correl" (IGNCorrelService), "nl-ahn",
"uk-england", "ch-swisssurface3d"; **kwargs override its settings
- a path to a folder -> LocalRasterService(folder, **kwargs)
Source code in pypvroof/dsm.py
available_services ¶
Table of the services of the catalogue (name, region, product, resolution, CRS, licence).
Source code in pypvroof/catalog.py
services_at ¶
Names of the services whose approximate extent contains (lon, lat), the most specific first (smallest extent; catalogue order on ties, so that "fr-lidar" comes before "fr-correl"). The extents are rough: a service may still answer "no_coverage", in which case the next one can be tried.
Source code in pypvroof/catalog.py
service ¶
Builds the service name of the catalogue; overrides replace its settings.
Source code in pypvroof/catalog.py
DSMService ¶
Base class of the DSM services.
Subclasses set crs (the CRS of the elevation grids, in which polygons
must be passed to fetch) and implement fetch(geometry).
Source code in pypvroof/dsm.py
fetch ¶
Returns a FetchResult for a shapely polygon expressed in self.crs.
The grid must cover the polygon's bounding box (plus any margin).
DSMPatch
dataclass
¶
Elevation grid around a polygon.
z : 2D float array of elevations (metres), NaN where there is no data transform : affine transform of the grid (rasterio convention, north up) crs : coordinate reference system of the grid (projected, metres)
Source code in pypvroof/dsm.py
pixel_centers ¶
Coordinates (x, y) of the centers of the given pixels.
FetchResult
dataclass
¶
IGNLidarService ¶
Bases: RemoteDSMService
IGN LiDAR HD elevation models served by the Géoplateforme WMS-R (https://data.geopf.fr/wms-r), as raw float32 GeoTIFFs on any extent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
"MNS" (digital surface model, default), "MNT" or "MNH"
|
|
'MNS'
|
margin
|
metres added around the polygon bounding box
|
|
1.0
|
resolution
|
pixel size (0.5 m, the native resolution of the product)
|
|
0.5
|
grid_origin
|
offset of the native pixel grid (the IGN tiles' edges are at
|
x.25 / x.75), so that requested pixels match native ones (no resampling) |
0.25
|
timeout
|
HTTP settings. Retries apply to network errors,
|
HTTP 429 and 5xx, with exponential backoff and jitter. |
30
|
retries
|
HTTP settings. Retries apply to network errors,
|
HTTP 429 and 5xx, with exponential backoff and jitter. |
30
|
backoff
|
HTTP settings. Retries apply to network errors,
|
HTTP 429 and 5xx, with exponential backoff and jitter. |
30
|
fetch_metadata
|
query the LiDAR HD WFS index for the acquisition metadata
|
of the tile containing the polygon (cached per 1 km tile) |
True
|
user_agent
|
User-Agent header sent to the service
|
|
None
|
Notes
meta keys: source, product, and if fetch_metadata: tile,
date_debut_acquisition, date_fin_acquisition, date_edition, code_mission
(or metadata_error). On errors: http_status, error.
Source code in pypvroof/dsm.py
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 | |
IGNCorrelService ¶
Bases: IGNLidarService
IGN "MNS Correl" surface model (50 cm), served by the Géoplateforme WMS-R.
It is computed by correlation of the aerial images of the BD ORTHO, i.e. from the same images as the orthophotos: it is consistent in time and geometry with detections made on the BD ORTHO, and covers areas without LiDAR HD. Correlation is less precise than LiDAR, especially on low-texture surfaces (dark panels, uniform roofs) and near roof edges.
Same parameters as IGNLidarService, without product; there is no
acquisition metadata index (fetch_metadata is ignored).
meta keys: source ("ign-mns-correl"), product.
Source code in pypvroof/dsm.py
LocalRasterService ¶
Bases: DSMService
Elevation rasters stored locally.
Expected format: single-band GeoTIFFs whose pixel values are elevations (in metres), georeferenced in a projected CRS (Lambert-93 / EPSG:2154 for IGN products, e.g. LiDAR HD MNS tiles or a thumbnail exported from the WMS-R). Any file name is accepted; the folder is indexed by extent when the service is created. All rasters must share the same CRS. A polygon spanning several rasters is handled (the rasters are mosaicked).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
directory containing the rasters
|
|
required |
pattern
|
glob pattern of the raster files (searched recursively)
|
|
'*.tif'
|
margin
|
metres added around the polygon bounding box
|
|
1.0
|
crs
|
CRS to assume for rasters without one
|
|
None
|
Notes
meta keys: source ("local"), files (names of the rasters used), and
tags (the GeoTIFF tags of the first raster, if any).
Source code in pypvroof/dsm.py
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 | |
WCSService ¶
Bases: RemoteDSMService
Elevation model served by an OGC Web Coverage Service (WCS 2.0.1 or
1.0.0) returning GeoTIFFs. Most national LiDAR surface models in Europe
are published this way; see pypvroof.catalog for ready-made presets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
endpoint of the WCS (without query string)
|
|
required |
coverage
|
coverage identifier (CoverageId in 2.0.1, coverage in 1.0.0)
|
|
required |
crs
|
CRS of the coverage (EPSG code or any pyproj input); polygons are
|
reprojected to it |
required |
resolution
|
native pixel size (metres)
|
|
required |
grid_origin
|
offset of the native pixel grid (0 for grids aligned on
|
whole metres) |
0.0
|
version
|
"2.0.1" (subsets in native pixels) or "1.0.0" (bbox + size)
|
|
'2.0.1'
|
axis_labels
|
labels of the (easting, northing) axes for 2.0.1 subsets,
|
as given by DescribeCoverage (e.g. ("x", "y"), ("E", "N")) |
('x', 'y')
|
format
|
output format requested
|
|
'image/tiff'
|
source
|
name reported in `meta["source"]`
|
|
None
|
attribution
|
licence / attribution string reported in `meta`
|
|
None
|
margin
|
as for IGNLidarService
|
|
1.0
|
timeout
|
as for IGNLidarService
|
|
1.0
|
retries
|
as for IGNLidarService
|
|
1.0
|
backoff
|
as for IGNLidarService
|
|
1.0
|
user_agent
|
as for IGNLidarService
|
|
1.0
|
Notes
meta keys: source, coverage, attribution. On errors: http_status, error.
Source code in pypvroof/dsm.py
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 | |
STACCogService ¶
Bases: RemoteDSMService
Elevation model published as Cloud-Optimized GeoTIFF tiles indexed by a STAC API (e.g. swisstopo swissSURFACE3D Raster). For each polygon, the tiles intersecting it are found with a STAC search (cached per tile footprint) and only the needed window is read (HTTP range requests).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stac_url
|
STAC API root (e.g. https://data.geo.admin.ch/api/stac/v0.9)
|
|
required |
collection
|
collection id
|
|
required |
crs
|
CRS of the tiles
|
|
required |
asset_filter
|
function (asset_key, asset_dict) -> bool selecting the
|
GeoTIFF asset of an item |
required |
tile_size
|
size (metres) of the tiles, used to cache the searches
|
|
1000.0
|
latest
|
when several items cover a tile (several acquisitions), keep
|
the most recent one |
True
|
source
|
as
|
for WCSService |
None
|
attribution
|
as
|
for WCSService |
None
|
margin
|
as
|
for WCSService |
None
|
timeout
|
as
|
for WCSService |
None
|
retries
|
as
|
for WCSService |
None
|
backoff
|
as
|
for WCSService |
None
|
user_agent
|
as
|
for WCSService |
None
|
Notes
meta keys: source, attribution, items (ids of the items used),
datetime (acquisition date of the items, if given).
Source code in pypvroof/dsm.py
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 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 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 | |
Visualization¶
plot_polygon ¶
plot_polygon(polygon, services=('fr-lidar', 'fr-correl'), crs=None, margin=6.0, params=None, ortho=None, figsize_per_panel=(5.0, 4.2))
Figure with the orthophoto (if ortho) and, below, the elevation grid of
each service around the polygon, with the estimated tilt / azimuth.
polygon : a GeoJSON feature / geometry, a shapely polygon, or a one-row
GeoDataFrame (CRS from crs, default EPSG:4326)
services : services or specifications ("fr-lidar", "fr-correl", "nl-ahn", a folder...)
ortho : show the IGN orthophoto (France only); by default, when the
first service is an IGN one
Source code in pypvroof/viz.py
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |