grid_enrichment
This module is responsible for enrichment of the operational grid with elevation and landuse data.
GridEnrichment
Bases: Component
This class is responsible for enrichment of the operational grid with elevation and landuse data.
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 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 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 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 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 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 | |
assign_mapping_values(sdf, values_map, map_column, values_column, default_value=2)
staticmethod
Assigns mapping values to a DataFrame based on a specified column.
This function takes a DataFrame, a dictionary of mapping values, a column to map from, a column to map to, and a default value. It creates a new column in the DataFrame by mapping values from the map column to the values column using the values map. If a value in the map column is not found in the values map, the default value is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sdf
|
DataFrame
|
The DataFrame to assign mapping values to. |
required |
values_map
|
dict
|
The dictionary of mapping values. |
required |
map_column
|
str
|
The column to map from. |
required |
values_column
|
str
|
The column to map to. |
required |
default_value
|
any
|
The default value to use if a value in the map column is not found in the values map. Defaults to 2. |
2
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The DataFrame with the new column of mapped values. |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 | |
calculate_landuse_prior(grid_tiles)
Calculates the prior probability of land use for each tile in a grid.
This function takes a DataFrame of grid tiles, each with a 'weighted_sum' column representing the weighted sum of land use ratios. It calculates the total weighted sum across all tiles and then divides the weighted sum of each tile by this total to calculate the prior probability of land use for each tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_tiles
|
DataFrame
|
The DataFrame of grid tiles. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The DataFrame of grid tiles with the new column of prior probabilities. |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
calculate_landuse_ratios_per_tile(grid_tiles, landuse_sdf)
Calculates the land use ratios for each tile in a grid.
This function takes a DataFrame of grid tiles and a DataFrame of land use data. For each land use class, it calculates the ratio of the area of the class that intersects with each grid tile to the area of the tile. If a tile does not intersect with a land use class, the ratio for that class is set to 0.0. If a tile does not intersect with any land use class, the 'open_area_ratio' is set to 1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_tiles
|
DataFrame
|
The DataFrame of grid tiles. |
required |
landuse_sdf
|
DataFrame
|
The DataFrame of land use data. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The DataFrame of grid tiles with the new columns of land use ratios. |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 | |
calculate_transportation_buffer(transportation_sdf, category_buffer_m)
Calculates the buffer for each transportation feature based on its category.
This function takes a DataFrame of transportation features and a dictionary mapping categories to buffer distances. It assigns the appropriate buffer distance to each feature based on its category and then calculates the buffer geometry. The buffer geometry replaces the original geometry of each feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transportation_sdf
|
DataFrame
|
The DataFrame of transportation features. |
required |
category_buffer_m
|
dict
|
A dictionary mapping categories to buffer distances. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The DataFrame of transportation features with the buffer geometries. |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 | |
calculated_landuse_ratios_weighted_sum(grid_tiles, weights_dict, sum_column_name)
Calculates the weighted sum of land use ratios for each grid tile.
This function takes a DataFrame of grid tiles and a dictionary of weights for each land use ratio. It multiplies each land use ratio by its corresponding weight and then sums these weighted ratios to calculate a weighted sum for each grid tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_tiles
|
DataFrame
|
The DataFrame of grid tiles with landuse ratios. |
required |
weights_dict
|
Dict[str, float]
|
A dictionary where the keys are the names of the land use ratios |
required |
sum_column_name
|
str
|
The name of the new column that will contain the weighted sums. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The DataFrame of grid tiles with the new column of weighted sums. |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 | |
find_intersection_ratio(grid_tiles, landuse, landuse_class)
Finds the intersection ratio of a specific land use class for each tile in a grid.
This function takes a DataFrame of grid tiles, a DataFrame of land use data, and a land use class. It finds the intersection of each grid tile with the land use data for the specified class, calculates the area of the intersection, and divides this by the area of the tile to find the intersection ratio. The intersection ratio is added as a new column to the grid DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_tiles
|
DataFrame
|
The DataFrame of grid tiles. |
required |
landuse
|
DataFrame
|
The DataFrame of land use data. |
required |
landuse_class
|
str
|
The land use class to find the intersection ratio for. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The DataFrame of grid tiles with the new column of intersection ratios. |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 | |
map_landuse_to_grid(grid_sdf)
Maps land use and transportation data to a grid.
This function takes a grid DataFrame, prepares the transportation and land use data by filtering and cutting it to the extent of the current quadkey, and then merges the prepared data with the grid. It also calculates the land use ratios per tile in the grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_sdf
|
DataFrame
|
The grid DataFrame to which the land use and transportation data will be mapped. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The grid DataFrame with the mapped land use |
DataFrame
|
and transportation data as ratios of a total area. |
Raises:
| Type | Description |
|---|---|
Warning
|
If no data is found for the current quadkey, |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 | |
merge_transportation_by_grid(transportation_sdf, resolution)
Merges transportation data with a generated grid based on the specified resolution.
This function takes a DataFrame containing transportation data and a grid resolution. It first generates a grid that covers the extent of the transportation data. Then, it intersects the transportation data with this grid, merging the transportation geometries that fall within each grid cell. The result is a DataFrame where each row represents a grid cell, aggregated by transportation category and date, with a merged geometry for all transportation data within that cell.
Parameters: - transportation_sdf (DataFrame): A Spark DataFrame containing transportation data. - resolution (int): The resolution of the grid to generate, specified as the length of the side of each square grid cell in meters.
Returns: - DataFrame: A Spark DataFrame where each row represents merged transportation data.
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
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 | |
populate_grid_tiles_with_empty_ratios(grid_tiles)
Populates grid tiles with empty land use ratios.
This function takes a DataFrame of grid tiles and adds a new column for each land use class in weights dict. Each new column is initialized with a value of 0.0, representing an empty land use ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_tiles
|
DataFrame
|
The DataFrame of grid tiles. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pyspark.sql.DataFrame: The DataFrame of grid tiles with the new columns of empty land use ratios. |
Source code in multimno/components/execution/grid_enrichment/grid_enrichment.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |