community.py¶
community
¶
Main class, initialize and evolves a community.
Attributes:
Name | Type | Description |
---|---|---|
given_parameters |
dict |
Parameters given at the initialization without triage and normalization. |
parameters |
dict |
Parameters used on the simulation, triaged and normalized. |
initOk |
bool |
True indicates no error at the initialization, False indicates an error. |
simOk |
bool |
True indicates that the simulation ended without errors. |
events |
list |
A list where all events generated during the simulation is stored,
each event is a list of tree elements, the first is the event's message, the
second is the time the event was generated and the third is the type of event.
Events can be printed with |
random_seed |
int |
Seed for all random number generators on the simulation. |
Nparticles |
int |
Number of particles used in the simulation. |
Nsteps |
int |
Number of time steps used on the simulation. |
Nhours |
int |
Number of hours in the simulation. |
dt |
float |
Size of the time step, can be set with the parameter |
time_of_the_day |
float |
Current time of the day in the simulation. |
scenario_id |
string |
Generated scenario id for the current simulation. |
free_hours |
list |
A two elements list indicating the window of time the particles are allowed to move trough the city. |
srv |
services_infrastructure |
A [ |
pop |
population |
A |
to_execute |
list |
A list of all functions to be executed on every step of the |
__init__(self, skip_triage=False, **parameters)
special
¶
Community class initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**parameters |
dict |
Parameters dictionary for the simulation |
{} |
skip_triage |
bool |
Skips parameters triage (code might not work) |
False |
Source code in comorbuss/community.py
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 |
|
add_to_execution(self, function, priority=0, time_of_the_day=(0, 24))
¶
Adds a function to the execution list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function |
callable |
Function or method to be called. |
required |
priority |
int |
Priority to be executed each step, lower priority functions will be executed first each step. Defaults to 0. |
0 |
time_of_the_day |
tuple |
An specific hour of the day or a tuple containing an window to execute function. Defaults to (0, 24). |
(0, 24) |
Source code in comorbuss/community.py
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 |
|
add_to_store(self, name, eval_str, compress=False)
¶
Adds a value to the to_store list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str |
Name to be save the data. |
required |
eval_str |
str |
String to be evaluate to load data |
required |
compress |
bool |
Compress data marker. Defaults to False. |
False |
Source code in comorbuss/community.py
552 553 554 555 556 557 558 559 560 561 |
|
assign_homes(self, parameters)
¶
Assing a home to each individual in a population.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
dict |
Simulation parameters. |
required |
Returns:
Type | Description |
---|---|
np.array |
Array of size Nparticles with the home id for each particle. |
Source code in comorbuss/community.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
assign_neighborhoods(self, parameters)
¶
Randomly assign a neighborhood for each particle in the simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
dict |
Simulation parameters. |
required |
Returns:
Type | Description |
---|---|
np.array |
Array of size Nparticles with the neighborhood id for each particle. |
Source code in comorbuss/community.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
|
compute_R0t(self)
¶
Calculate the Basic Reproduction Number for each time
The Basic Reproduction Number is the mean number of particles infected by one particle
Source code in comorbuss/community.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
event_log(self, message, msgtype)
¶
Stores a message in the simulation log.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str |
Message. |
required |
msgtype |
int |
Message type marker, see |
required |
Source code in comorbuss/community.py
381 382 383 384 385 386 387 388 |
|
init_module(self, module, module_parameters)
¶
Load and initialize a module from the modules folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name |
str |
Module name. |
required |
module_parameters |
Any |
Module_parameters |
required |
Source code in comorbuss/community.py
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 |
|
isolation(self)
¶
Run social isolation mechanics, to be isolated as a module.
Source code in comorbuss/community.py
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 |
|
lockdown(self)
¶
Run lockdown mechanics, to be isolated as a module.
Source code in comorbuss/community.py
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 |
|
log_and_raise(self, message, error)
¶
Log an error message, print all messages and raise an exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str |
Message. |
required |
error |
Exception |
Exception to be raised. |
required |
Source code in comorbuss/community.py
368 369 370 371 372 373 374 375 376 377 |
|
log_results(self)
¶
Add results to the simulation log.
Source code in comorbuss/community.py
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 |
|
print_events(self)
¶
Prints events registered during execution.
Source code in comorbuss/community.py
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 |
|
save_events(self, filename)
¶
Saves events registered during execution to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
string |
Filename to save events. |
required |
Returns:
Type | Description |
---|---|
file |
File object. |
Source code in comorbuss/community.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
simulate(self)
¶
Runs the simulation, in each step all functions on self.to_execute will run.
Source code in comorbuss/community.py
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 |
|
store_time_series(self)
¶
Stores current step data on time series for post processing.
Source code in comorbuss/community.py
482 483 484 485 486 487 488 489 490 491 492 |
|
update_position(self)
¶
Updates the position of the particles according to a day cycle
Source code in comorbuss/community.py
604 605 606 607 608 609 610 611 612 613 614 615 |
|