population.py¶
population
¶
This class stores the attributes that characterize a population and the methods for its initialization and progression.
Attributes:
Name | Type | Description |
---|---|---|
Nparticles |
int |
Number of particles in the simulation. |
rng |
Generator |
Random number generator. |
random |
np.random |
Stores np.ramdon generator to use exclusively with NetworkX. |
disease |
disease |
Object with disease information and methods. |
homes |
dict |
Dictionary with information on every home. |
workersAvailable |
list |
List with available workers. |
max_encounters |
int |
Max number of encounter used on max_encounters filter. |
in_lckd |
np.ndarray bool |
Lockdown turned on or not for each step. |
tracing |
list |
List with the tracing for every step, tracing is stored as an dict of lists. |
tracing_infectious |
list |
List with the tracing of infectious particles for every step, tracing is stored as an dict of lists. |
infection_tree |
Graph |
Graph with disease spread information. |
Particles general attributes¶
Attributes bellow describes every particle in the current step.
Attributes:
Name | Type | Description |
---|---|---|
pid |
np.ndarray int |
Particle |
home_id |
np.ndarray int |
Id of the home for each particle, in the list of all homes. |
ages |
np.ndarray int |
Age group for each particle. |
placement |
np.ndarray int |
Placement marker for each particle. Placement tells where the particle is in the simulation (eg.: home, environment, services). |
activity |
np.ndarray int |
Activity marker for each particle. Activity tells what the particle is doing (eg.: free, working, visiting). |
has_tracing |
np.ndarray bool |
Mask for the tracing capability of every particle. |
workplace_id |
np.ndarray int |
Id of the service where particle works |
workplace_instance |
np.ndarray int |
Instance of the service where particles works. |
workplace_room |
np.ndarray int |
Room of the service particle works. |
worker_type |
np.ndarray int |
Type of worker for each particle. |
Particles states attributes¶
Attributes:
Name | Type | Description |
---|---|---|
states |
np.ndarray int |
State of the infection for every particle. |
symptoms |
np.ndarray int |
State of symptoms for every particles. |
quarantine_states |
np.ndarray int |
Quarantine states for every particle. |
diag_states |
np.ndarray int |
Last diagnostic state for every particle. |
Particles infection information attributes¶
Attributes:
Name | Type | Description |
---|---|---|
inf_source |
np.ndarray int |
Source of infection of each particle, pid of the particle that was responsible for the infection of the corresponding particle (NO_INFEC not infected, -1 initially infected). |
inf_placement |
np.ndarray int |
Placement of particles at time of infection (NO_INFEC -> not infected). |
inf_vector_sympt |
np.ndarray int |
Symptomatic state of the infection vector at the time the infection occurred (NO_INFEC -> no infection). |
time_exposed |
np.ndarray float |
Time in which a particle becomes exposed. |
time_infectious |
np.ndarray float |
Time in which a particle becomes infectious. |
time_recovered |
np.ndarray float |
Time in which a particle becomes recovered. |
time_quarantined |
np.ndarray float |
Time in which a particle was quarantined. |
time_traced |
np.ndarray float |
Time in which a particle was traced. |
Time series¶
Attributes:
Name | Type | Description |
---|---|---|
states_ts |
np.ndarray |
Time series of states attribute (conditional to
|
symptoms_ts |
np.ndarray |
Time series of symptoms attribute (conditional to
|
quarantine_states_ts |
np.ndarray |
Time series of quarantine_states attribute (conditional
to |
diag_states_ts |
np.ndarray |
Time series of diag_states attribute (conditional to
|
positions_ts |
np.ndarray |
Time series of positions attribute (conditional to
|
placement_ts |
np.ndarray |
Time series of placement attribute (conditional to
|
susceptible |
np.ndarray |
Time series of the number of susceptible particles on each step. |
exposed |
np.ndarray |
Time series of the number of exposed particles on each step. |
infectious |
np.ndarray |
Time series of the number of infectious particles on each step. |
recovered |
np.ndarray |
Time series of the number of recovered particles on each step. |
deceased |
np.ndarray |
Time series of the number of deceased particles on each step. |
R0t |
np.ndarray int |
Cumulative mean of spreads on time, converging to Basic Reproduction Number (R0) |
spreads |
np.ndarray int |
At each time, number of particles infected by the particle with corresponding column index. |
add_attribute(self, name, value, store=False, compress=False)
¶
Adds an attribute to the population object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str |
Name of the attribute. |
required |
value |
Any |
Initial value for the attribute. |
required |
store |
bool |
Select to store the attribute at the end of the simulation. Defaults to False. |
False |
compress |
bool |
Select if the attribute should be stored compressed or not. Defaults to False. |
False |
Source code in comorbuss/population.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
add_net_generator(self, plc, net_generator)
¶
Add a new encounters generator to be processed every step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plc |
int |
Placement marker. |
required |
net_generator |
net_generator |
An object with a gen method. |
required |
Source code in comorbuss/population.py
821 822 823 824 825 826 827 828 829 |
|
allocate_ages(self, parameters)
¶
Allocate ages to the population, giving priority so that kids don't live alone.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
homes |
list |
List of the home ids for each particle. |
required |
parameters |
dict |
Simulation parameters. |
required |
Returns:
Type | Description |
---|---|
np.ndarray |
Age group of each particle. |
Source code in comorbuss/population.py
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 |
|
count_cases(self)
¶
Count the number of cases at the last completed step of the time evolution
Source code in comorbuss/population.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
|
count_per_age_group(self, group)
¶
Counts the number of particles in a age group
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group |
int |
Id of the age group to be calculated |
required |
Returns:
Type | Description |
---|---|
int |
Number of particles in the given age group |
Source code in comorbuss/population.py
684 685 686 687 688 689 690 691 692 693 |
|
enable_tracing(self, buffer_length=None)
¶
Enables tracing. To be used only during initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer_length |
int |
Number of steps of the required tracing. If None will store tracing for entire simulation. Defaults to None. |
None |
Source code in comorbuss/population.py
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 |
|
gen_adhesion_mask(self, percentage)
¶
Create a boolean array indicating if particle of corresponding index is going to adhere to a given policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
percentage |
float |
Percentage of the population to be chosen. |
required |
Returns:
Type | Description |
---|---|
np.ndarray |
Array of booleans with the adhesion of each particle. |
Source code in comorbuss/population.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
gen_encounters_and_infections(self, attributes)
¶
Generates encounters masks for each context.
Source code in comorbuss/population.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
|
gen_homes(self)
¶
Generates a dictionary with homes information.
Returns:
Type | Description |
---|---|
dict |
Dictionary with homes information. |
Source code in comorbuss/population.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
gen_tracing_all(mask_encounters, mask_particles, nparticles)
staticmethod
¶
Trace all encounters for each particle mask_partipledof encounters to be traced
Returns:
Type | Description |
---|---|
dict |
Lists of pid that each particle encountered |
Source code in comorbuss/population.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
|
init_states(self, inf0, inf0_symp, homes_inf0_frac=0.5, homes_inf0_dict={})
¶
Create array of initial states and initial symptoms
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states |
np.ndarray |
array of states initialized with susceptible |
required |
symptoms |
np.ndarray |
arplotray of symptoms initialized with S.NO_INFEC |
required |
inf0 |
float |
list of percentages of population in each state [S, E, I, R] |
required |
inf0_symp |
float |
percentage of infectious population with each symptom [asymp, symp, severe] |
required |
Source code in comorbuss/population.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
mark_for_new_position(self, to_change, placement, activity)
¶
Mark particles for changes in position
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_change |
np.ndarray |
Mask or list of pids for particles to be changed |
required |
placement |
int |
New placement |
required |
activity |
int |
New activity |
required |
Source code in comorbuss/population.py
695 696 697 698 699 700 701 702 703 704 |
|
mean_time_in_state(self, state)
¶
Calculates the mean time for all population in a given state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
int |
id of the state, available states: S.STATE_S: 0, S.STATE_E = 1 and S.STATE_I: 2 |
required |
Returns:
Type | Description |
---|---|
float |
Mean time in the given state. |
Source code in comorbuss/population.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
|
process_encounters(self, nparticles, mask_particles, mask_encounters, plc, plc_inf_prob_weight, attributes, gen_new_inf)
¶
Process encounters from an encounters mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nparticles |
int |
Number of particles in this context. |
required |
mask_particles |
np.ndarray |
Mask of the particles in this context. |
required |
mask_encounters |
np.ndarray |
Mask of nparticles x nparticles size with the encounters in this context. |
required |
plc |
int |
Placement marker. |
required |
plc_inf_prob_weight |
float |
Infection weight of the placement. |
required |
attributes |
dict |
Attributes dict to be stored in the infection tree. |
required |
gen_new_inf |
function |
Function to generate new infections. |
required |
Returns:
Type | Description |
---|---|
[int, int, int, int] |
Counts of encounters, encounters with infectious, possible infections and new infections. |
Source code in comorbuss/population.py
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
|
to_exposed(self, attributes)
¶
Do states transitions: Susceptible --> Exposed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attributes |
dict |
Attributes dict to be stored in the infection tree. |
required |
Source code in comorbuss/population.py
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
|
to_infectious(self, attributes)
¶
Do states transitions: Exposed --> Infectious.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attributes |
dict |
Attributes dict to be stored in the infection tree. |
required |
Source code in comorbuss/population.py
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
to_recovered(self, attributes)
¶
Do states transitions: {Symptomatic, Asymptomatic} --> Recovered or deceased.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attributes |
dict |
Attributes dict to be stored in the infection tree. |
required |
Source code in comorbuss/population.py
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
|
to_symptoms(self, attributes)
¶
Do states transitions: Infectious --> {Symptomatic, Asymptomatic}.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attributes |
dict |
Attributes dict to be stored in the infection tree. |
required |
Source code in comorbuss/population.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
|
trace_particles(self, mask_origin, back_time)
¶
Use tracing information to identify particles that had contact with particles in a mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask_origin |
np.ndarray |
Mask with the particles search contacts. |
required |
back_time |
float |
Window of time to search from current step. |
required |
Returns:
Type | Description |
---|---|
np.ndarray |
Mask with traced particles. |
Source code in comorbuss/population.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
|
update_inf_tree_attributes(self, mask, attribute, value)
¶
Stores information in the infection tree
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask |
np.ndarray |
Mask with particles to update. |
required |
attribute |
str |
Name of the attribute to be stored. |
required |
value |
np.ndarray |
Data to be stored. |
required |
Source code in comorbuss/population.py
615 616 617 618 619 620 621 622 623 624 625 626 627 |
|
update_states(self)
¶
Update the state of the disease in every particle at the current time
Source code in comorbuss/population.py
1105 1106 1107 1108 1109 1110 1111 1112 1113 |
|