migration
Layer
Bases: dict
The Layer object represents a mapping from source node (IDs) to destination node (IDs) for a particular age, gender, age+gender combination, or all users if no age or gender dependence. Users will not generally interact directly with Layer objects.
Source code in emod_api/migration/migration.py
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 | |
DatavalueCount
property
Get (maximum) number of data values for any node in this layer
Returns:
| Type | Description |
|---|---|
int
|
Maximum number of data values for any node in this layer |
NodeCount
property
Get the number of (source) nodes with rates in this layer
Returns:
| Type | Description |
|---|---|
int
|
Number of (source) nodes with rates in this layer |
__getitem__(key)
Allows indexing directly into this object with source node id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
int
|
source node id |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of outbound rates for the given node id |
Source code in emod_api/migration/migration.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
Migration
Bases: object
Represents migration data in a mapping from source node (IDs) to destination node (IDs) with rates for each pairing.
Migration data may be age dependent, gender dependent, both, or the same for all ages and genders. A migration file (along with JSON metadata) can be loaded from the static method Migration.from_file() and inspected and/or modified. Migration objects can be started from scratch with Migration(), and populated with appropriate source-dest rate data and saved to a file with the to_file() method. Given migration = Migration(), syntax is as follows:
age and gender agnostic: migration[source_id][dest_id]
age dependent: migration[source_id:age] # age should be >= 0, ages > last bucket value use last bucket value
gender dependent: migration[source_id:gender] # gender one of Migration.MALE or Migration.FEMALE
age and gender dependent: migration[source_id:gender:age] # gender one of Migration.MALE or Migration.FEMALE
EMOD/DTK format migration files (and associated metadata files) can be written with migration.to_file(
Source code in emod_api/migration/migration.py
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 | |
AgesYears
property
writable
List of ages - ages < first value use first bucket, ages > last value use last bucket.
Author
property
writable
str: Author value for metadata for this migration datafile
DatavalueCount
property
int: Maximum data value count for any layer in this migration datafile
DateCreated
property
writable
datetime: date/time stamp of this datafile
GenderDataType
property
writable
int: gender data type for this datafile - SAME_FOR_BOTH_GENDERS or ONE_FOR_EACH_GENDER
IdReference
property
writable
str: ID reference metadata value
InterpolationType
property
writable
int: interpolation type for this migration data file - LINEAR_INTERPOLATION or PIECEWISE_CONSTANT
MigrationType
property
writable
int: migration type for this migration data file - LOCAL | AIR | REGIONAL | SEA | FAMILY | INTERVENTION
NodeCount
property
int: maximum number of source nodes in any layer of this migration data file
NodeOffsets
property
dict: mapping from source node id to offset to destination and rate data in binary data
Tool
property
writable
str: tool metadata value
__getitem__(key)
allows indexing on this object to read/write rate data Args: key (slice): source node id:gender:age (gender and age depend on GenderDataType and AgesYears properties) Returns: dict for specified node/gender/age
Source code in emod_api/migration/migration.py
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 | |
to_file(binaryfile, metafile=None, value_limit=100)
Write current data to given file (and .json metadata file)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binaryfile
|
Path
|
path to output file (metadata will be written to same path with ".json" appended) |
required |
metafile
|
Path
|
override standard metadata file naming |
None
|
value_limit
|
int
|
limit on number of destination values to write for each source node (default = 100) |
100
|
Returns:
| Type | Description |
|---|---|
Path
|
path to binary file |
Source code in emod_api/migration/migration.py
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 | |
from_csv(filename, id_ref, mig_type=None)
Create migration from csv file. The file should have columns 'source' for the source node, 'destination' for the destination node, and 'rate' for the migration rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Path
|
csv file |
required |
Returns:
| Type | Description |
|---|---|
Migration
|
Migration object |
Source code in emod_api/migration/migration.py
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
from_file(binaryfile, metafile=None)
Reads migration data file from given binary (and associated JSON metadata file)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binaryfile
|
Path
|
path to binary file (metadata file is assumed to be at same location with ".json" suffix) |
required |
metafile
|
Path
|
use given metafile rather than inferring metafile name from the binary file name |
None
|
Returns:
| Type | Description |
|---|---|
Migration
|
Migration object representing binary data in the given file. |
Source code in emod_api/migration/migration.py
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 | |
from_params(demographics_file_path=None, pop=1000000.0, num_nodes=100, mig_factor=1.0, frac_rural=0.3, id_ref='from_params', migration_type=Migration.LOCAL)
This function is for creating a migration file that goes with a (multinode) demographics file created from a few parameters, as opposed to one from real-world data. Note that the 'demographics_file_path" input param is not used at this time but in future will be exploited to ensure nodes, etc., match.
Source code in emod_api/migration/migration.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |