ODMatrix
Source code in tripsender\od.py
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 |
|
compute_routes(nrc_drive, nrc_bike, nrc_walk, nrc_transit)
This function computes the routes and durations for the OD matrix based on the mode of transport. The function iterates over the rows of the OD matrix and computes the route and duration based on the mode of transport. It user the NetworkRoutingComputer objects for each mode of transport to compute the route and duration.
:param nrc_drive: (NetworkRoutingComputer) A NetworkRoutingComputer object for driving :param nrc_bike: (NetworkRoutingComputer) A NetworkRoutingComputer object for biking :param nrc_walk: (NetworkRoutingComputer) A NetworkRoutingComputer object for walking :param nrc_transit: (NetworkRoutingComputer) A NetworkRoutingComputer object for transit
Source code in tripsender\od.py
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 |
|
assign_households_to_buildings(gdf_residential, area_per_person=32)
This function assigns the households to the buildings based on the area_per_person parameter.
Source code in tripsender\od.py
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 |
|
assign_to_multi_family_buildings(households, buildings, area_per_person)
This function assigns the households to multi family buildings.
Source code in tripsender\od.py
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 |
|
assign_to_single_family_buildings(households, buildings)
This function assigns the households to single family buildings.
Source code in tripsender\od.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
create_location_mapping(person, random_location=False)
Helper function to create a mapping of activity purposes to locations. It is possible to select random locations for each activity purpose by setting the random_location flag to True. If random_location is False, the first location from the preferred locations is selected for each activity purpose.
Source code in tripsender\od.py
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 |
|
generate_od_matrix(num_samples=None, random_location=False)
This function generates an OD matrix based on the activity sequences of the persons. The process of generating the OD matrix is as follows: 1 - Identify all the adults in the households 2 - For each adult, identify the activity sequence 3 - Get the location_mapping dictionary for the person 4 - For each activity, identify the origin, destination and mode of transport 4.1 - First origin is the home location 4.2 - Last destination is the home location 4.3 - Mode of transport is the mode of transport for the activity 5 - Append the origin, destination, mode, person and activity sequence to the OD_pairs list 6 - Create a dataframe from the OD_pairs list 7 - Create an ODMatrix object from the dataframe 8 - Return the ODMatrix object
Some caveats: - If the destination purpose is Travel, the destination is set to None. This is done by the create_location_mapping function
Source code in tripsender\od.py
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 |
|
get_gdf(area, feature, KEY='', VAL='', title='Data from Server', filter=False, local=True, web=True, plot=False, save=True)
A function to fetch spatial geometry from the PostGIS
server as GeoPandas GeoDataFrame
.
This function is simply a wrapper for the psycopg2
module.
It constructs an SQL
query based on the the params provided and requests data from the server.
:param area: (str) The name of the Primary area in the Model naming format.
:param feature: (str) The feature name to select from the PostGIS
database. (Refer to PostGIS naming convention)
:param KEY: (str: Optional) An optional attribute to filter from the data at the server level
:param VAL: (str: Optional) An optional value for a given key to match from the data at the server level
:param title: (str: Optional) An optional title for the plot
:param filter: (bool: Optional) An optional input to specify if the data must be filtered at the server level
:param local: (bool: Optional) Which server to fetch the data from
:param web: (bool: Optional) If True
, the result will be reprojected
:param plot: (bool: Optional) If True
, the result will be plotted
:return: (GeoPandas GeoDataFrame, plot(Optional)) The resulting GeoPandas GeoDataFrame
.
Source code in tripsender\od.py
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 |
|
get_landuse(local=False, web=False, clip=None, buffer_distance=1000)
A function to fetch land use data as a GeoPandas GeoDataFrame, with an option to clip it using a provided geometry and buffer the clip.
:param local: If True, data will be fetched from the local server. :param web: If True, result will be reprojected to EPSG:4326. :param clip: Geometry to clip the natural features. Expected to be a Shapely Polygon. :param buffer_distance: The distance to buffer around the clip geometry, default is 1000 meters. :return: A GeoDataFrame containing the land use data.
Source code in tripsender\od.py
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 |
|
get_pg_query(sql, local=True, web=True)
A utility function that fetches any data using an SQL
query from the PostGIS
Server
This function is a basic wrapper for the psycopg2
module with secrets included.
:param sql: (str) An SQL query string
:param local: (bool: Optional) If True
, data will be fetched from the local server
:param web: (bool: Optional) If True
, result will be reprojected to EPSG:4326
:return:
Source code in tripsender\od.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
get_pgcon(local=True)
A helper function to read the .pgpass
file. This is the authentication file for the PostGIS
server.
The function reads the file and returns a connection object to the PostGIS
server.
The server contains the spatial data for the region, including the road network and building footprints.
:param local: (bool: Optional) If True
, the function will connect to the local server.
:return: (psycopg2 connection) A connection object to the PostGIS
server.
Source code in tripsender\od.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
get_road(local=True, web=True, ped=True, clip=None, buffer_distance=1000)
A function to fetch road data as a GeoPandas GeoDataFrame, with an option to clip it using a provided geometry and buffer the clip.
:param local: If True, data will be fetched from the local server. :param web: If True, result will be reprojected to EPSG:4326. :param ped: If True, pedestrian roads will be included in the result. :param clip: Geometry to clip the road data. Expected to be a Shapely Polygon. :param buffer_distance: The distance to buffer around the clip geometry, default is 1000 meters. :return: A GeoDataFrame containing the road data.
Source code in tripsender\od.py
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 |
|
mark_empty_buildings()
This function marks the buildings as empty if the population_total is 0.
Source code in tripsender\od.py
415 416 417 418 419 420 421 |
|
process_residential_buildings(gdf_building, area_per_person=36)
This function processes the residential buildings to calculate the number of people living in each building. The function filters the buildings based on the area_per_person parameter and calculates the number of people living in each building. The function also calculates the number of floors in each building and the total Built-up Area (BTA) of each building. The function also assigns a UUID to each building.
The data for the area_per_person parameter is based on the average living area per person in Sweden. Reference: https://www.scb.se/en/finding-statistics/statistics-by-subject-area/household-finances/income-and-income-distribution/households-housing/pong/statistical-news/households-housing-2019/
A service area factor is applied to the area of the building based on the building type. The service area factor is 0.85 for 'Flerfamiljshus' and 0.9 for all other building types.
:param gdf_building: (GeoPandas GeoDataFrame) A GeoDataFrame containing the building footprints. :param area_per_person: (int: Optional) The area per person in square meters. Default is 36 m2. :return: (GeoPandas GeoDataFrame) A GeoDataFrame containing the processed residential buildings.
Source code in tripsender\od.py
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 |
|
sort_buildings_by_type_and_population()
This function sorts the buildings by type and population into single family and multi family buildings Buildings are sorted by population in descending order. Note: Population is calculated as the number of people living in the building based on the area_per_person parameter.
Returns: single_family_buildings (list): A list of single family buildings sorted by population multi_family_buildings (list): A list of multi family buildings sorted by population
Source code in tripsender\od.py
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 |
|
sort_households_by_type_and_count()
This function sorts the households by type and population into single family and multi family households Households are sorted by population in descending order. Returns: households_in_single_family_house (list): A list of single family households sorted by population households_in_multi_family_house (list): A list of multi family households sorted by population
Source code in tripsender\od.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|