tools.py¶
check_dir(path, complete_path=None)
¶
Checks if a directory exists, if not recursively creates it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str |
Path to directory. |
required |
complete_path |
str |
Should not be set by user, original path to be printed if an error is encountered. |
None |
Exceptions:
Type | Description |
---|---|
OSError |
Unable to create directory. |
Source code in comorbuss/tools.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
e_dist(a, b, metric='euclidean')
¶
Distance calculation for 1D, 2D and 3D points using einsum : a, b - list, tuple, array in 1, 2 or 3D form : metric - euclidean ('e', 'eu'...), sqeuclidean ('s', 'sq'...), :-----------------------------------------------------------------------
Source code in comorbuss/tools.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
efficacy_calc(cases_vacc, not_cases_vacc, cases_not_vacc, not_cases_not_vacc, return_limits=False)
¶
Calculates efficacy of a vaccine from the number of cases and not cases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cases_vacc |
int |
Cases in the vaccinated population. |
required |
not_cases_vacc |
int |
Not cases in the vaccinated population. |
required |
cases_not_vacc |
int |
Cases in the not vaccinated population. |
required |
not_cases_not_vacc |
int |
Not cases in the not vaccinated population. |
required |
return_limits |
bool |
Return also upper and lower limits of efficacy. |
False |
Returns:
Type | Description |
---|---|
float |
float: [description] |
Source code in comorbuss/tools.py
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 |
|
filter_parse(f, comm, allowed_filters=[], comm_str='self.comm')
¶
Get a tuple of comparative and boolean operations and transform it in a expression that can be evaluated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
tuple |
Tuple with the operations. |
required |
comm |
community |
Community object of the simulation. |
required |
allowed_filters |
str |
List with allowed custom filters ("days", "tracing", "workers, "service", "diagnostic" or "vaccination"). |
[] |
Returns:
Type | Description |
---|---|
str, bool |
Expression that can be evaluated., True if parse successful. |
Source code in comorbuss/tools.py
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 |
|
function(f)
¶
Checks if f is callable, if true returns it, else raise TypeError.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
callable |
To be tested |
required |
Source code in comorbuss/tools.py
67 68 69 70 71 72 73 74 75 76 |
|
get_enc_pct_matrix(tracing, Nparticles, time_series=[], query_label=0, time_slice=slice(1, None, None))
¶
This function returns a percentage, for each entry of the matrix. The entry (i, j) represents the percentage of the time steps for which the particle i encounters particle j, if the time series match the query_label
Source code in comorbuss/tools.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
get_encounters_array_age_group(tracing, ages, ageGroups=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,17, 18, 19, 20]), dt=1, slice_rng=slice(1, None, None))
¶
This function returns an array whose entry i is the average number of encounters that a particle in the i-th age group has with another particle along a day
Source code in comorbuss/tools.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
|
get_encounters_matrix_age_group(matrix, ages, ageGroups)
¶
This function returns a matrix mtx_ageG which concentrates the entries of the provided matrix according to the age groups in ages
Source code in comorbuss/tools.py
419 420 421 422 423 424 425 426 427 |
|
in_list_of_dicts(list, item, key='name', return_dict=False)
¶
Checks if an item is contained in a list of dicts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list |
list |
List to search. |
required |
item |
any |
Item to be searched. |
required |
key |
str |
Key to search for item. If None will search on all keys of the dictionaries. Defaults to 'name'. |
'name' |
return_dict |
bool |
Returns dict instead of True. Defaults to False. |
False |
Returns:
Type | Description |
---|---|
bool |
True if item is found |
Source code in comorbuss/tools.py
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 |
|
load_demographics(city, state, parameters, filename='/home/nano/Apps/anaconda3/lib/python3.7/site-packages/COMORBUSS-1.0.0-py3.7.egg/data/demographic_data_brazil.csv')
¶
Loads population data and basic services information from database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
city |
str |
Name of the city. |
required |
state |
str |
Two characters state abbreviation. |
required |
parameters |
dict |
Parameters dictionary |
required |
filename |
str |
File with the csv database. Defaults to DEMO_DATA_FILE. |
'/home/nano/Apps/anaconda3/lib/python3.7/site-packages/COMORBUSS-1.0.0-py3.7.egg/data/demographic_data_brazil.csv' |
Source code in comorbuss/tools.py
626 627 628 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 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 |
|
load_hdf5(filename='', keep_open=False, version_check=True)
¶
Loads simulation parameters and results from an hdf5 file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
Filename to load, if not given a prompt window will be shown to the user to select the file. |
'' |
Returns:
Type | Description |
---|---|
dict, string |
Loaded data and filename for the loaded file. |
Source code in comorbuss/tools.py
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 |
|
normalize(l)
¶
Normalizes a list of floats.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list |
list |
List of floats. |
required |
Returns:
Type | Description |
---|---|
list |
Normalized list. |
Source code in comorbuss/tools.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
plot_enc_pct_matrix(tracing, time_series=[], query_label=0, slice_rng=slice(1, None, None), size=(5, 4), title='')
¶
This function returns a probability matrix. The entry (i, j) of the matrix is the percentage of time steps in slice_rng for which: 1-there are encounters between particles i and j, and 2-the time_series for the step where the encounter ocurred matches the query_label. This matrix can be interpreted as the probability that one particle encounters another when time_series matches query_label
Source code in comorbuss/tools.py
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 |
|
recursive_copy(object)
¶
Makes a recursive copy of a nested dict or list object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object |
Union[dict, list] |
Object to be copied. |
required |
Returns:
Type | Description |
---|---|
Union[dict, list] |
Union[dict, list]: Copy of the original object. |
Source code in comorbuss/tools.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
save_hdf5(comms, out_file, to_store=[], to_store_srvc=[], skip_defaults=False, try_append=False)
¶
Store simulation parameters and results in hdf5 files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comms |
list |
A list of comunities to be stored (all comunities must have the same parameters and vary only the seed). |
required |
out_file |
string |
Filename to save data. |
required |
to_store |
list |
Extras results to be stored, must follow
|
[] |
to_store_srvc |
list |
Extra services data to be stored, must
follow |
[] |
skip_defaults |
bool |
Skip default to stores ( |
False |
try_append |
bool |
Try to append to an existing file (file must have the same parameters). Defaults to False. |
False |
Source code in comorbuss/tools.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 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 851 |
|