Application Programming Interface ¶
aggregate_zones(mgra_gdf, method='kmeans', n_zones=2000, random_state=0, cluster_factors=None, cluster_factors_onehot=None, use_xy=True, explicit_agg=(), explicit_col='mgra', agg_instruction=None, start_cluster_ids=13)
¶
Aggregate zones.
Parameters ¶
mgra_gdf : mgra_gdf (GeoDataFrame)
Geometry and attibutes of MGRAs
method : method (array)
default {‘kmeans’, ‘agglom’, ‘agglom_adj’}
n_zones : n_zones (int)
random_state : random_state (RandomState or int)
cluster_factors : cluster_factors (dict)
cluster_factors_onehot : cluster_factors_onehot (dict)
use_xy : use_xy (bool or float)
Use X and Y coordinates as a cluster factor, use a float to scale the
x-y coordinates from the CRS if needed.
explicit_agg : explicit_agg (list[int or list])
A list containing integers (individual MGRAs that should not be aggregated)
or lists of integers (groups of MGRAs that should be aggregated exactly as
given, with no less and no more)
explicit_col : explicit_col (str)
The name of the column containing the ID’s from explicit_agg
, usually ‘taz’
agg_instruction : agg_instruction (dict)
Dictionary passed to pandas agg
that says how to aggregate data columns.
start_cluster_ids : start_cluster_ids (int, default 13)
Cluster id’s start at this value. Can be 1, but typically SANDAG has the
smallest id’s reserved for external zones, so starting at a greater value
is typical.
Returns ¶
GeoDataFrame
Source code in rsm/zone_agg.py
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 |
|
agg_input_files(model_dir='.', rsm_dir='.', taz_cwk_file='taz_crosswalk.csv', mgra_cwk_file='mgra_crosswalk.csv', agg_zones=2000, ext_zones=12, input_files=['microMgraEquivMinutes.csv', 'microMgraTapEquivMinutes.csv', 'walkMgraTapEquivMinutes.csv', 'walkMgraEquivMinutes.csv', 'bikeTazLogsum.csv', 'bikeMgraLogsum.csv', 'zone.term', 'zones.park', 'tap.ptype', 'accessam.csv', 'ParkLocationAlts.csv', 'CrossBorderDestinationChoiceSoaAlternatives.csv', 'TourDcSoaDistanceAlts.csv', 'DestinationChoiceAlternatives.csv', 'SoaTazDistAlts.csv', 'TripMatrices.csv', 'transponderModelAccessibilities.csv', 'crossBorderTours.csv', 'internalExternalTrips.csv', 'visitorTours.csv', 'visitorTrips.csv', 'householdAVTrips.csv', 'crossBorderTrips.csv', 'TNCTrips.csv', 'airport_out.SAN.csv', 'airport_out.CBX.csv', 'TNCtrips.csv'])
¶
Parameters ¶
model_dir : model_dir (path_like) path to full model run, default “.” rsm_dir : rsm_dir (path_like) path to RSM, default “.” taz_cwk_file : taz_cwk_file (csv file) default taz_crosswalk.csv taz to aggregated zones file. Should be located in RSM input folder mgra_cwk_file : mgra_cwk_file (csv file) default mgra_crosswalk.csv mgra to aggregated zones file. Should be located in RSM input folder input_files : input_files (csv + other files) list of input files to be aggregated. Should include the following files “microMgraEquivMinutes.csv”, “microMgraTapEquivMinutes.csv”, “walkMgraTapEquivMinutes.csv”, “walkMgraEquivMinutes.csv”, “bikeTazLogsum.csv”, “bikeMgraLogsum.csv”, “zone.term”, “zones.park”, “tap.ptype”, “accessam.csv”, “ParkLocationAlts.csv”, “CrossBorderDestinationChoiceSoaAlternatives.csv”, “TourDcSoaDistanceAlts.csv”, “DestinationChoiceAlternatives.csv”, “SoaTazDistAlts.csv”, “TripMatrices.csv”, “transponderModelAccessibilities.csv”, “crossBorderTours.csv”, “internalExternalTrips.csv”, “visitorTours.csv”, “visitorTrips.csv”, “householdAVTrips.csv”, “crossBorderTrips.csv”, “TNCTrips.csv”, “airport_out.SAN.csv”, “airport_out.CBX.csv”, “TNCtrips.csv”
Returns ¶
Aggregated files in the RSM input/output/uec directory
Source code in rsm/input_agg.py
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 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 |
|
copy_transit_demand(matrix_names, input_dir='.', output_dir='.')
¶
copies the omx transit demand matrix to rsm directory
Parameters ¶
matrix_names : matrix_names (list) omx matrix filenames to aggregate input_dir : input_dir (Path-like) default “.” output_dir : output_dir (Path-like) default “.”
Returns ¶
Source code in rsm/translate.py
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 |
|
translate_emmebank_demand(input_databank, output_databank, cores_to_aggregate, agg_zone_mapping)
¶
aggregates the demand matrix cores from one emme databank and loads them into another databank
Parameters ¶
input_databank : input_databank (Emme databank) Emme databank output_databank : output_databank (Emme databank) Emme databank cores_to_aggregate : cores_to_aggregate (list) matrix corenames to aggregate agg_zone_mapping: agg_zone_mapping (Path-like or pandas.DataFrame) zone number mapping between original and aggregated zones. columns: original zones as ‘taz’ and aggregated zones as ‘cluster_id’
Returns ¶
None. Loads the trip matrices into emmebank.
Source code in rsm/translate.py
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 |
|
translate_omx_demand(matrix_names, agg_zone_mapping, input_dir='.', output_dir='.')
¶
aggregates the omx demand matrix to aggregated zone system
Parameters ¶
matrix_names : matrix_names (list) omx matrix filenames to aggregate agg_zone_mapping: agg_zone_mapping (path_like or pandas.DataFrame) zone number mapping between original and aggregated zones. columns: original zones as ‘taz’ and aggregated zones as ‘cluster_id’ input_dir : input_dir (path_like) default “.” output_dir : output_dir (path_like) default “.”
Returns ¶
Source code in rsm/translate.py
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 |
|
rsm_household_sampler(input_dir='.', output_dir='.', prev_iter_access=None, curr_iter_access=None, study_area=None, input_household='households.csv', input_person='persons.csv', taz_crosswalk='taz_crosswalk.csv', mgra_crosswalk='mgra_crosswalk.csv', compare_access_columns=('NONMAN_AUTO', 'NONMAN_TRANSIT', 'NONMAN_NONMOTOR', 'NONMAN_SOV_0'), default_sampling_rate=0.25, lower_bound_sampling_rate=0.15, upper_bound_sampling_rate=1.0, random_seed=42, output_household='sampled_households.csv', output_person='sampled_person.csv')
¶
Take an intelligent sampling of households.
Parameters ¶
input_dir : input_dir (path_like)
default “.”
output_dir : output_dir (path_like)
default “.”
prev_iter_access : prev_iter_access (Path-like or pandas.DataFrame)
Accessibility in an old (default, no treatment, etc) run is given (preloaded)
or read in from here. Give as a relative path (from input_dir
) or an
absolute path.
curr_iter_access : curr_iter_access (Path-like or pandas.DataFrame)
Accessibility in the latest run is given (preloaded) or read in from here.
Give as a relative path (from input_dir
) or an absolute path.
study_area : study_area (array-like)
Array of RSM zone (these are numbered 1 to N in the RSM) in the study area.
These zones are sampled at 100% if differential sampling is also turned on.
input_household : input_household (Path-like or pandas.DataFrame)
Complete synthetic household file. This data will be filtered to match the
sampling of households and written out to a new CSV file.
input_person : input_person (Path-like or pandas.DataFrame)
Complete synthetic persons file. This data will be filtered to match the
sampling of households and written out to a new CSV file.
compare_access_columns : compare_access_columns (Collection[str])
Column names in the accessibility file to use for comparing accessibility.
Only changes in the values in these columns will be evaluated.
default_sampling_rate : default_sampling_rate (float)
The default sampling rate, in the range (0,1]
lower_bound_sampling_rate : lower_bound_sampling_rate (float)
Sampling rates by zone will be truncated so they are never lower than this.
upper_bound_sampling_rate : upper_bound_sampling_rate (float)
Sampling rates by zone will be truncated so they are never higher than this.
Returns ¶
sample_households_df, sample_persons_df : sample_households_df, sample_persons_df (pandas.DataFrame) These are the sampled population to resimulate. They are also written to the output_dir
Source code in rsm/sampler.py
10 11 12 13 14 15 16 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 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 |
|
rsm_assemble(orig_indiv, orig_joint, rsm_indiv, rsm_joint, households, mgra_crosswalk=None, taz_crosswalk=None, sample_rate=0.25, study_area_taz=None, run_assembler=1)
¶
Assemble and evaluate RSM trip making.
Parameters ¶
orig_indiv : orig_indiv (path_like)
Trips table from “original” model run, should be comprehensive simulation
of all individual trips for all synthetic households.
orig_joint : orig_joint (path_like)
Joint trips table from “original” model run, should be comprehensive simulation
of all joint trips for all synthetic households.
rsm_indiv : rsm_indiv (path_like)
Trips table from RSM model run, should be a simulation of all individual
trips for potentially only a subset of all synthetic households.
rsm_joint : rsm_joint (path_like)
Trips table from RSM model run, should be a simulation of all joint
trips for potentially only a subset of all synthetic households (the
same sampled households as in rsm_indiv
).
households : households (path_like)
Synthetic household file, used to get home zones for households.
mgra_crosswalk : mgra_crosswalk (path_like, optional)
Crosswalk from original MGRA to clustered zone ids. Provide this crosswalk
if the orig_indiv
and orig_joint
files reference the original MGRA system
and those id’s need to be converted to aggregated values before merging.
sample_rate : sample_rate (float)
Default/fixed sample rate if sampler was turned off
this is used to scale the trips if run_assembler is 0
run_assembler : run_assembler (boolean)
Flag to indicate whether to run RSM assembler or not.
1 is to run assembler, 0 is to turn if off
setting this to 0 is only an option if sampler is turned off
sample_rate : float
default/fixed sample rate if sampler was turned off
this is used to scale the trips if run_assembler is 0
study_area_rsm_zones : list
it is list of study area RSM zones
Returns ¶
final_trips_rsm : final_ind_trips (pd.DataFrame) Assembled trip table for RSM run, filling in archived trip values for non-resimulated households. combined_trips_by_zone : final_jnt_trips (pd.DataFrame) Summary table of changes in trips by mode, by household home zone. Used to check whether undersampled zones have stable travel behavior.
Separate tables for individual and joint trips, as required by java.
Source code in rsm/assembler.py
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 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 |
|