pam.read.matsim
get_attributes_from_legs(elem)
#
get_attributes_from_person(elem)
#
Source code in src/pam/read/matsim.py
load_attributes_map(attributes_path)
#
Given path to MATSim attributes input, return dictionary of attributes (as dict).
Source code in src/pam/read/matsim.py
load_attributes_map_from_v12(plans_path)
#
parse_matsim_plan(plan_xml, person_id, version, simplify_pt_trips, crop, autocomplete, leg_attributes=True, leg_route=True)
#
Parse a MATSim plan.
Source code in src/pam/read/matsim.py
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 |
|
parse_veh_attribute(text)
#
read_matsim(plans_path, attributes_path=None, all_vehicles_path=None, electric_vehicles_path=None, weight=100, version=12, household_key=None, simplify_pt_trips=False, autocomplete=True, crop=False, keep_non_selected=False, leg_attributes=True, leg_route=True)
#
Load a MATSim format population into core population format.
It is possible to maintain the unity of housholds using a household uid in
the attributes input, i.e.:
xml <attribute class="java.lang.String" name="hid">hh_0001</attribute>
.
PARAMETER | DESCRIPTION |
---|---|
plans_path
|
path to matsim format xml
TYPE:
|
attributes_path
|
path to matsim format xml. Defaults to None.
TYPE:
|
all_vehicles_path
|
path to matsim all_vehicles xml file. Defaults to None.
TYPE:
|
electric_vehicles_path
|
path to matsim electric_vehicles xml. Defaults to None.
TYPE:
|
weight
|
int. Defaults to 100.
TYPE:
|
version
|
Defaults to 12.
TYPE:
|
household_key
|
Defaults to None.
TYPE:
|
simplify_pt_trips
|
bool, simplify legs in multi-leg trips. Defaults to False.
TYPE:
|
autocomplete
|
bool, fills missing leg and activity attributes. Defaults to True.
TYPE:
|
crop
|
bool, crop plans that go beyond 24 hours. Defaults to False.
TYPE:
|
keep_non_selected
|
Whether to parse non-selected plans (storing them in person.plans_non_selected). Defaults to False.
TYPE:
|
leg_attributes
|
Parse leg attributes such as routing mode. Defaults to True.
TYPE:
|
leg_route
|
Parse leg route. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Population
|
core.Population: |
Source code in src/pam/read/matsim.py
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 |
|
selected_plans(plans_path)
#
Given path to MATSim plans input, yield person id and plan for all selected plans.
Source code in src/pam/read/matsim.py
stream_matsim_persons(plans_path, attributes={}, vehicles_manager=None, weight=100, version=12, simplify_pt_trips=False, autocomplete=True, crop=False, keep_non_selected=False, leg_attributes=True, leg_route=True)
#
Stream a MATSim format population into core.Person objects. Expects agent attributes (and vehicles) to be supplied as optional dictionaries. This allows this function to support "version 11" plans.
TODO: a v12 only method could also stream attributes and would use less memory
PARAMETER | DESCRIPTION |
---|---|
plans_path
|
path to matsim format xml
TYPE:
|
attributes
|
map of person attributes, only required for v11. Defaults to {}.
TYPE:
|
vehicles_manager
|
Population vehicles manager. Defaults to None.
TYPE:
|
weight
|
path to matsim electric_vehicles xml. Defaults to 100.
TYPE:
|
version
|
Defaults to 12.
TYPE:
|
simplify_pt_trips
|
simplify legs in multi-leg trips. Defaults to False.
TYPE:
|
autocomplete
|
fills missing leg and activity attributes. Defaults to True.
TYPE:
|
crop
|
crop plans that go beyond 24 hours. Defaults to False.
TYPE:
|
keep_non_selected
|
Whether to parse non-selected plans (storing them in
TYPE:
|
leg_attributes
|
Parse leg attributes such as routing mode. Defaults to True.
TYPE:
|
leg_route
|
Parse leg route. Defaults to True.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
UserWarning
|
|
YIELDS | DESCRIPTION |
---|---|
Person
|
Iterator[core.Person]: |
Source code in src/pam/read/matsim.py
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 |
|
unpack_leg(leg, version)
#
unpack_leg_v12(leg)
#
Extract mode, route and attributes as available.
PARAMETER | DESCRIPTION |
---|---|
leg
|
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[str, Route, dict]
|
tuple[str, Route, dict]: mode, route, attributes |
Example
There are four known cases:
=== Unrouted ===
For example a leg missing both attributes and route elements, this is the case for non experienced or non routed plans:
=== Transit ===
This is a transit routed leg with the route encoded as json string and routingMode attribute:
<leg mode="pt" trav_time="00:43:42">
<attributes>
<attribute name="routingMode" class="java.lang.String">bus</attribute>
</attributes>
<route type="default_pt" start_link="1-2" end_link="3-4" trav_time="00:43:42" distance="10100.0">
{"transitRouteId":"work_bound","boardingTime":"07:30:00","transitLineId":"city_line","accessFacilityId":"home_stop_out","egressFacilityId":"work_stop_in"}
</route>
</leg>
Route must be transit i.e. there will not be a network route. Route attributes include: - type = "default_pt" - start_link - end_link - trav_time - distance
=== Network Routed ===
This is a network routed mode, eg car:
<leg mode="car" dep_time="07:58:00" trav_time="00:04:52">
<attributes>
<attribute name="enterVehicleTime" class="java.lang.Double">28680.0</attribute>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="4155" end_link="5221366698030330427_5221366698041252619" trav_time="00:04:52" distance="4898.473995989452" vehicleRefId="null">
4155 5221366345330551489_5221366345327939575 2623 4337 5221366343808222067_5221366343837130911 2984 1636 3671 6110 etc...
</route>
</leg>
Route attributes include: - type = "links" - start_link - end_link - trav_time - distance - vehicleRefId The network route is given as a space seperated sequence of link ids.
=== Teleported ===
This is a teleported route, eg walk/cycle:
<leg mode="walk" dep_time="09:23:00" trav_time="01:54:10">
<attributes>
<attribute name="routingMode" class="java.lang.String">walk</attribute>
</attributes>
<route type="generic" start_link="5221366698030330427_5221366698041252619" end_link="114" trav_time="01:54:10" distance="5710.003987453454"></route>
</leg>
Route attributes include: - type = "generic" - start_link - end_link - trav_time - distance The network route is empty.
Source code in src/pam/read/matsim.py
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 |
|