vector_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 emodpy_malaria/migration/vector_migration.py
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 emodpy_malaria/migration/vector_migration.py
VectorMigration
Bases: object
Represents vector migration data in a mapping from source node (IDs) to destination node (IDs) with rates for each pairing.
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 emodpy_malaria/migration/vector_migration.py
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 | |
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 | REGIONAL
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 emodpy_malaria/migration/vector_migration.py
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 emodpy_malaria/migration/vector_migration.py
from_csv(filename_path, id_reference, migration_type='LOCAL_MIGRATION', author=None)
Create migration from csv file. The file should have columns 'from_node' for the node ids from which vector is migrating, 'to_node' for the node ids that the vector is migrating to, and 'rate' for the migration rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename_path
|
str
|
name (if same folder) or path+name of the csv file |
required |
id_reference
|
str
|
IdReference parameter to set for the migration file, it needs to be the same as IdReference parameter in your demographics files. |
required |
migration_type
|
str
|
"LOCAL_MIGRATION" or "REGIONAL_MIGRATION" setting, "LOCAL_MIGRATION" can have 8 "to_nodes" while "REGIONAL_MIGRATION" can have 30, default is "LOCAL_MIGRATION" |
'LOCAL_MIGRATION'
|
author
|
str
|
optional metadata of who is the author(you) of the migration file, default - your username or empty string will be used |
None
|
Returns:
| Type | Description |
|---|---|
VectorMigration
|
Migration object to be manipulated or written out as a file using to_file() function |
Source code in emodpy_malaria/migration/vector_migration.py
from_demographics_and_gravity_params(demographics_object, gravity_params, filename=None)
This function takes a demographics object, creates a vector migration file based on the populations and
distances of nodes and saves to be used by the sim
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
demographics_object
|
MalaraiDemographics
|
demographics object created by Demographics class (use Demographics.from_file() to load a demographics file you already have and pass in the returned object) |
required |
gravity_params
|
list
|
a list of four parameters that will affect the gravity model gravity_params[0] denoted as g[0], etc, and they are used in the following way: migration_rate = g[0] * (from_node_population^(g[1]-1)) * (to_node_population^g[2]) * (distance^g[3]) if rate >= 1, 1 is used. |
required |
filename
|
str
|
name of migration file to be created and added to the experiment, Default: vector_migration.bin |
None
|
Returns:
| Type | Description |
|---|---|
VectorMigration
|
VectorMigration object |
Source code in emodpy_malaria/migration/vector_migration.py
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 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
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 |
|---|---|
VectorMigration
|
Migration object representing binary data in the given file. |
Source code in emodpy_malaria/migration/vector_migration.py
from_params(demographics_file_path=None, population=1000000.0, num_nodes=100, migration_factor=1.0, fraction_rural=0.3, id_ref='IfReference', migration_type=VectorMigration.LOCAL_MIGRATION)
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.