-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mnt_d_Github_synthpops_synthpops_contacts_py.html
1917 lines (1917 loc) · 623 KB
/
_mnt_d_Github_synthpops_synthpops_contacts_py.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
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
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
507
508
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
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
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
770
771
772
773
774
775
776
777
778
779
780
781
782
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
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
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
877
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
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<title>Coverage for /mnt/d/Github/synthpops/synthpops/contacts.py: 74%</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.hotkeys.js"></script>
<script type="text/javascript" src="jquery.isonscreen.js"></script>
<script type="text/javascript" src="coverage_html.js"></script>
<script type="text/javascript">
jQuery(document).ready(coverage.pyfile_ready);
</script>
</head>
<body class="pyfile">
<div id="header">
<div class="content">
<h1>Coverage for <b>/mnt/d/Github/synthpops/synthpops/contacts.py</b> :
<span class="pc_cov">74%</span>
</h1>
<img id="keyboard_icon" src="keybd_closed.png" alt="Show keyboard shortcuts" />
<h2 class="stats">
1003 statements
<button type="button" class="run shortkey_r button_toggle_run" title="Toggle lines run">745 run</button>
<button type="button" class="mis show_mis shortkey_m button_toggle_mis" title="Toggle lines missing">258 missing</button>
<button type="button" class="exc show_exc shortkey_x button_toggle_exc" title="Toggle lines excluded">0 excluded</button>
</h2>
</div>
</div>
<div class="help_panel">
<img id="panel_icon" src="keybd_open.png" alt="Hide keyboard shortcuts" />
<p class="legend">Hot-keys on this page</p>
<div>
<p class="keyhelp">
<span class="key">r</span>
<span class="key">m</span>
<span class="key">x</span>
<span class="key">p</span> toggle line displays
</p>
<p class="keyhelp">
<span class="key">j</span>
<span class="key">k</span> next/prev highlighted chunk
</p>
<p class="keyhelp">
<span class="key">0</span> (zero) top of page
</p>
<p class="keyhelp">
<span class="key">1</span> (one) first highlighted chunk
</p>
</div>
</div>
<div id="source">
<p id="t1" class="pln"><span class="n"><a href="#t1">1</a></span><span class="t"><span class="str">"""</span> </span><span class="r"></span></p>
<p id="t2" class="pln"><span class="n"><a href="#t2">2</a></span><span class="t"><span class="str">Generate contacts between people in the population, with many options possible.</span> </span><span class="r"></span></p>
<p id="t3" class="pln"><span class="n"><a href="#t3">3</a></span><span class="t"><span class="str">"""</span> </span><span class="r"></span></p>
<p id="t4" class="pln"><span class="n"><a href="#t4">4</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t5" class="run"><span class="n"><a href="#t5">5</a></span><span class="t"><span class="key">import</span> <span class="nam">os</span> </span><span class="r"></span></p>
<p id="t6" class="run"><span class="n"><a href="#t6">6</a></span><span class="t"><span class="key">import</span> <span class="nam">numpy</span> <span class="key">as</span> <span class="nam">np</span> </span><span class="r"></span></p>
<p id="t7" class="run"><span class="n"><a href="#t7">7</a></span><span class="t"><span class="key">import</span> <span class="nam">pandas</span> <span class="key">as</span> <span class="nam">pd</span> </span><span class="r"></span></p>
<p id="t8" class="run"><span class="n"><a href="#t8">8</a></span><span class="t"><span class="key">import</span> <span class="nam">numba</span> <span class="key">as</span> <span class="nam">nb</span> </span><span class="r"></span></p>
<p id="t9" class="run"><span class="n"><a href="#t9">9</a></span><span class="t"><span class="key">import</span> <span class="nam">sciris</span> <span class="key">as</span> <span class="nam">sc</span> </span><span class="r"></span></p>
<p id="t10" class="run"><span class="n"><a href="#t10">10</a></span><span class="t"><span class="key">import</span> <span class="nam">networkx</span> <span class="key">as</span> <span class="nam">nx</span> </span><span class="r"></span></p>
<p id="t11" class="run"><span class="n"><a href="#t11">11</a></span><span class="t"><span class="key">from</span> <span class="op">.</span> <span class="key">import</span> <span class="nam">data_distributions</span> <span class="key">as</span> <span class="nam">spdata</span> </span><span class="r"></span></p>
<p id="t12" class="run"><span class="n"><a href="#t12">12</a></span><span class="t"><span class="key">from</span> <span class="op">.</span> <span class="key">import</span> <span class="nam">sampling</span> <span class="key">as</span> <span class="nam">spsamp</span> </span><span class="r"></span></p>
<p id="t13" class="run"><span class="n"><a href="#t13">13</a></span><span class="t"><span class="key">from</span> <span class="op">.</span> <span class="key">import</span> <span class="nam">base</span> <span class="key">as</span> <span class="nam">spb</span> </span><span class="r"></span></p>
<p id="t14" class="run"><span class="n"><a href="#t14">14</a></span><span class="t"><span class="key">from</span> <span class="op">.</span> <span class="key">import</span> <span class="nam">school_modules</span> <span class="key">as</span> <span class="nam">spsm</span> </span><span class="r"></span></p>
<p id="t15" class="run"><span class="n"><a href="#t15">15</a></span><span class="t"><span class="key">from</span> <span class="op">.</span> <span class="key">import</span> <span class="nam">read_write</span> <span class="key">as</span> <span class="nam">sprw</span> </span><span class="r"></span></p>
<p id="t16" class="run"><span class="n"><a href="#t16">16</a></span><span class="t"><span class="key">from</span> <span class="op">.</span><span class="nam">config</span> <span class="key">import</span> <span class="nam">datadir</span><span class="op">,</span> <span class="nam">logger</span> <span class="key">as</span> <span class="nam">log</span><span class="op">,</span> <span class="nam">checkmem</span> </span><span class="r"></span></p>
<p id="t17" class="run"><span class="n"><a href="#t17">17</a></span><span class="t"><span class="key">from</span> <span class="nam">copy</span> <span class="key">import</span> <span class="nam">deepcopy</span> </span><span class="r"></span></p>
<p id="t18" class="pln"><span class="n"><a href="#t18">18</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t19" class="pln"><span class="n"><a href="#t19">19</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t20" class="run"><span class="n"><a href="#t20">20</a></span><span class="t"><span class="key">def</span> <span class="nam">make_popdict</span><span class="op">(</span><span class="nam">n</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">uids</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">ages</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">sexes</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">location</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_demography</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> <span class="nam">id_len</span><span class="op">=</span><span class="num">6</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t21" class="pln"><span class="n"><a href="#t21">21</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t22" class="pln"><span class="n"><a href="#t22">22</a></span><span class="t"><span class="str"> Create a dictionary of n people with age, sex and loc keys</span> </span><span class="r"></span></p>
<p id="t23" class="pln"><span class="n"><a href="#t23">23</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t24" class="pln"><span class="n"><a href="#t24">24</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t25" class="pln"><span class="n"><a href="#t25">25</a></span><span class="t"><span class="str"> n (int) : number of people</span> </span><span class="r"></span></p>
<p id="t26" class="pln"><span class="n"><a href="#t26">26</a></span><span class="t"><span class="str"> uids (list) : supplied uids of individuals</span> </span><span class="r"></span></p>
<p id="t27" class="pln"><span class="n"><a href="#t27">27</a></span><span class="t"><span class="str"> ages (list) : supplied ages of individuals</span> </span><span class="r"></span></p>
<p id="t28" class="pln"><span class="n"><a href="#t28">28</a></span><span class="t"><span class="str"> sexes (list) : supplied sexes of individuals</span> </span><span class="r"></span></p>
<p id="t29" class="pln"><span class="n"><a href="#t29">29</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t30" class="pln"><span class="n"><a href="#t30">30</a></span><span class="t"><span class="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t31" class="pln"><span class="n"><a href="#t31">31</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in</span> </span><span class="r"></span></p>
<p id="t32" class="pln"><span class="n"><a href="#t32">32</a></span><span class="t"><span class="str"> use_demography (bool) : If True, use demographic data</span> </span><span class="r"></span></p>
<p id="t33" class="pln"><span class="n"><a href="#t33">33</a></span><span class="t"><span class="str"> id_len (int) : length of the uid</span> </span><span class="r"></span></p>
<p id="t34" class="pln"><span class="n"><a href="#t34">34</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t35" class="pln"><span class="n"><a href="#t35">35</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t36" class="pln"><span class="n"><a href="#t36">36</a></span><span class="t"><span class="str"> A dictionary where keys are the uid of each person and the values are another dictionary containing values for other attributes of the person</span> </span><span class="r"></span></p>
<p id="t37" class="pln"><span class="n"><a href="#t37">37</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t38" class="run"><span class="n"><a href="#t38">38</a></span><span class="t"> <span class="nam">log</span><span class="op">.</span><span class="nam">debug</span><span class="op">(</span><span class="str">'make_popdict()'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t39" class="pln"><span class="n"><a href="#t39">39</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t40" class="run"><span class="n"><a href="#t40">40</a></span><span class="t"> <span class="nam">min_people</span> <span class="op">=</span> <span class="num">1000</span> </span><span class="r"></span></p>
<p id="t41" class="pln"><span class="n"><a href="#t41">41</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t42" class="run"><span class="n"><a href="#t42">42</a></span><span class="t"> <span class="key">if</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> <span class="nam">location</span> <span class="op">=</span> <span class="str">'seattle_metro'</span> </span><span class="r"></span></p>
<p id="t43" class="run"><span class="n"><a href="#t43">43</a></span><span class="t"> <span class="key">if</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> <span class="nam">state_location</span> <span class="op">=</span> <span class="str">'Washington'</span> </span><span class="r"></span></p>
<p id="t44" class="pln"><span class="n"><a href="#t44">44</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t45" class="pln"><span class="n"><a href="#t45">45</a></span><span class="t"> <span class="com"># A list of UIDs was supplied as the first argument</span> </span><span class="r"></span></p>
<p id="t46" class="run"><span class="n"><a href="#t46">46</a></span><span class="t"> <span class="key">if</span> <span class="nam">uids</span> <span class="key">is</span> <span class="key">not</span> <span class="key">None</span><span class="op">:</span> <span class="com"># UIDs were supplied, use them</span> </span><span class="r"></span></p>
<p id="t47" class="run"><span class="n"><a href="#t47">47</a></span><span class="t"> <span class="nam">n</span> <span class="op">=</span> <span class="nam">len</span><span class="op">(</span><span class="nam">uids</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t48" class="pln"><span class="n"><a href="#t48">48</a></span><span class="t"> <span class="com"># if uids are ints</span> </span><span class="r"></span></p>
<p id="t49" class="run"><span class="n"><a href="#t49">49</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t50" class="run"><span class="n"><a href="#t50">50</a></span><span class="t"> <span class="nam">uid_mapping</span> <span class="op">=</span> <span class="op">{</span><span class="nam">uid</span><span class="op">:</span> <span class="nam">int</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> <span class="key">for</span> <span class="nam">u</span><span class="op">,</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">uids</span><span class="op">)</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t51" class="pln"><span class="n"><a href="#t51">51</a></span><span class="t"> <span class="com"># if uids are strings then map them to an int</span> </span><span class="r"></span></p>
<p id="t52" class="mis show_mis"><span class="n"><a href="#t52">52</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t53" class="mis show_mis"><span class="n"><a href="#t53">53</a></span><span class="t"> <span class="nam">uid_mapping</span> <span class="op">=</span> <span class="op">{</span><span class="nam">uid</span><span class="op">:</span> <span class="nam">u</span> <span class="key">for</span> <span class="nam">u</span><span class="op">,</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">uids</span><span class="op">)</span><span class="op">}</span> <span class="com"># replacing uids for uid_mapping since uids might be strings</span> </span><span class="r"></span></p>
<p id="t54" class="pln"><span class="n"><a href="#t54">54</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> <span class="com"># Not supplied, generate</span> </span><span class="r"></span></p>
<p id="t55" class="run"><span class="n"><a href="#t55">55</a></span><span class="t"> <span class="nam">n</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t56" class="run"><span class="n"><a href="#t56">56</a></span><span class="t"> <span class="nam">uids</span> <span class="op">=</span> <span class="nam">list</span><span class="op">(</span><span class="nam">range</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t57" class="run"><span class="n"><a href="#t57">57</a></span><span class="t"> <span class="nam">uid_mapping</span> <span class="op">=</span> <span class="op">{</span><span class="nam">u</span><span class="op">:</span> <span class="nam">u</span> <span class="key">for</span> <span class="nam">u</span> <span class="key">in</span> <span class="nam">uids</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t58" class="pln"><span class="n"><a href="#t58">58</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t59" class="pln"><span class="n"><a href="#t59">59</a></span><span class="t"> <span class="com"># Check that there are enough people</span> </span><span class="r"></span></p>
<p id="t60" class="run"><span class="n"><a href="#t60">60</a></span><span class="t"> <span class="key">if</span> <span class="nam">n</span> <span class="op"><</span> <span class="nam">min_people</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t61" class="mis show_mis"><span class="n"><a href="#t61">61</a></span><span class="t"> <span class="nam">print</span><span class="op">(</span><span class="str">f'Warning: with {n}<{min_people} people, contact matrices will be approximate'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t62" class="pln"><span class="n"><a href="#t62">62</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t63" class="pln"><span class="n"><a href="#t63">63</a></span><span class="t"> <span class="com"># Optionally take in either ages or sexes, too</span> </span><span class="r"></span></p>
<p id="t64" class="run"><span class="n"><a href="#t64">64</a></span><span class="t"> <span class="key">if</span> <span class="nam">ages</span> <span class="key">is</span> <span class="key">None</span> <span class="key">and</span> <span class="nam">sexes</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t65" class="run"><span class="n"><a href="#t65">65</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_demography</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t66" class="mis show_mis"><span class="n"><a href="#t66">66</a></span><span class="t"> <span class="key">if</span> <span class="nam">country_location</span> <span class="op">!=</span> <span class="str">'usa'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t67" class="pln"><span class="n"><a href="#t67">67</a></span><span class="t"> <span class="com"># no sex data for places outside of the US</span> </span><span class="r"></span></p>
<p id="t68" class="mis show_mis"><span class="n"><a href="#t68">68</a></span><span class="t"> <span class="nam">gen_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_age_n</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">n</span><span class="op">=</span><span class="nam">n</span><span class="op">,</span> <span class="nam">location</span><span class="op">=</span><span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t69" class="pln"><span class="n"><a href="#t69">69</a></span><span class="t"> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t70" class="mis show_mis"><span class="n"><a href="#t70">70</a></span><span class="t"> <span class="nam">gen_sexes</span> <span class="op">=</span> <span class="nam">list</span><span class="op">(</span><span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">binomial</span><span class="op">(</span><span class="num">1</span><span class="op">,</span> <span class="nam">p</span><span class="op">=</span><span class="num">0.5</span><span class="op">,</span> <span class="nam">size</span><span class="op">=</span><span class="nam">n</span><span class="op">)</span><span class="op">)</span> <span class="com"># randomly assign sex</span> </span><span class="r"></span></p>
<p id="t71" class="pln"><span class="n"><a href="#t71">71</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t72" class="mis show_mis"><span class="n"><a href="#t72">72</a></span><span class="t"> <span class="key">if</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span> <span class="op">=</span> <span class="str">'seattle_metro'</span><span class="op">,</span> <span class="str">'Washington'</span> <span class="com"># currently defaults to Seattle based data</span> </span><span class="r"></span></p>
<p id="t73" class="mis show_mis"><span class="n"><a href="#t73">73</a></span><span class="t"> <span class="nam">gen_ages</span><span class="op">,</span> <span class="nam">gen_sexes</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_usa_age_sex_n</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">location</span><span class="op">=</span><span class="nam">location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t74" class="pln"><span class="n"><a href="#t74">74</a></span><span class="t"> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t75" class="pln"><span class="n"><a href="#t75">75</a></span><span class="t"> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">,</span> <span class="nam">n_people</span><span class="op">=</span><span class="nam">n</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t76" class="pln"><span class="n"><a href="#t76">76</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t77" class="pln"><span class="n"><a href="#t77">77</a></span><span class="t"> <span class="com"># not using any demography data so simply creating uniformly distributed ages and sex for n people</span> </span><span class="r"></span></p>
<p id="t78" class="run"><span class="n"><a href="#t78">78</a></span><span class="t"> <span class="nam">gen_ages</span><span class="op">,</span> <span class="nam">gen_sexes</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_age_sex_n</span><span class="op">(</span><span class="key">None</span><span class="op">,</span> <span class="key">None</span><span class="op">,</span> <span class="key">None</span><span class="op">,</span> <span class="nam">n_people</span><span class="op">=</span><span class="nam">n</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t79" class="pln"><span class="n"><a href="#t79">79</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t80" class="pln"><span class="n"><a href="#t80">80</a></span><span class="t"> <span class="com"># you only have ages...</span> </span><span class="r"></span></p>
<p id="t81" class="run"><span class="n"><a href="#t81">81</a></span><span class="t"> <span class="key">elif</span> <span class="nam">ages</span> <span class="key">is</span> <span class="key">not</span> <span class="key">None</span> <span class="key">and</span> <span class="nam">sexes</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t82" class="run"><span class="n"><a href="#t82">82</a></span><span class="t"> <span class="key">if</span> <span class="nam">country_location</span> <span class="op">==</span> <span class="str">'usa'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t83" class="mis show_mis"><span class="n"><a href="#t83">83</a></span><span class="t"> <span class="key">if</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span> <span class="op">=</span> <span class="str">'seattle_metro'</span><span class="op">,</span> <span class="str">'Washington'</span> <span class="com"># currently defaults to Seattle based data</span> </span><span class="r"></span></p>
<p id="t84" class="mis show_mis"><span class="n"><a href="#t84">84</a></span><span class="t"> <span class="nam">gen_ages</span><span class="op">,</span> <span class="nam">gen_sexes</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_usa_sex_n</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">ages</span><span class="op">,</span> <span class="nam">location</span><span class="op">=</span><span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t85" class="pln"><span class="n"><a href="#t85">85</a></span><span class="t"> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t86" class="pln"><span class="n"><a href="#t86">86</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t87" class="run"><span class="n"><a href="#t87">87</a></span><span class="t"> <span class="nam">gen_ages</span> <span class="op">=</span> <span class="nam">ages</span> </span><span class="r"></span></p>
<p id="t88" class="run"><span class="n"><a href="#t88">88</a></span><span class="t"> <span class="nam">gen_sexes</span> <span class="op">=</span> <span class="nam">list</span><span class="op">(</span><span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">binomial</span><span class="op">(</span><span class="num">1</span><span class="op">,</span> <span class="nam">p</span><span class="op">=</span><span class="num">0.5</span><span class="op">,</span> <span class="nam">size</span><span class="op">=</span><span class="nam">n</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t89" class="pln"><span class="n"><a href="#t89">89</a></span><span class="t"> <span class="com"># raise NotImplementedError('Currently, only locations in the US are supported.')</span> </span><span class="r"></span></p>
<p id="t90" class="pln"><span class="n"><a href="#t90">90</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t91" class="pln"><span class="n"><a href="#t91">91</a></span><span class="t"> <span class="com"># you only have sexes...</span> </span><span class="r"></span></p>
<p id="t92" class="run"><span class="n"><a href="#t92">92</a></span><span class="t"> <span class="key">elif</span> <span class="nam">ages</span> <span class="key">is</span> <span class="key">None</span> <span class="key">and</span> <span class="nam">sexes</span> <span class="key">is</span> <span class="key">not</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t93" class="mis show_mis"><span class="n"><a href="#t93">93</a></span><span class="t"> <span class="key">if</span> <span class="nam">country_location</span> <span class="op">==</span> <span class="str">'usa'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t94" class="mis show_mis"><span class="n"><a href="#t94">94</a></span><span class="t"> <span class="key">if</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span> <span class="op">=</span> <span class="str">'seattle_metro'</span><span class="op">,</span> <span class="str">'Washington'</span> </span><span class="r"></span></p>
<p id="t95" class="mis show_mis"><span class="n"><a href="#t95">95</a></span><span class="t"> <span class="nam">gen_ages</span><span class="op">,</span> <span class="nam">gen_sexes</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_usa_age_n</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">sexes</span><span class="op">,</span> <span class="nam">location</span><span class="op">=</span><span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t96" class="pln"><span class="n"><a href="#t96">96</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t97" class="pln"><span class="n"><a href="#t97">97</a></span><span class="t"> <span class="com"># gen_sexes = sexes</span> </span><span class="r"></span></p>
<p id="t98" class="pln"><span class="n"><a href="#t98">98</a></span><span class="t"> <span class="com"># gen_ages = sp.get_age_n(datadir,n=n,location=location,state_location=state_location,country_location=country_location)</span> </span><span class="r"></span></p>
<p id="t99" class="mis show_mis"><span class="n"><a href="#t99">99</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">'Currently, only locations in the US are supported'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t100" class="pln"><span class="n"><a href="#t100">100</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t101" class="pln"><span class="n"><a href="#t101">101</a></span><span class="t"> <span class="com"># randomize your generated ages and sexes</span> </span><span class="r"></span></p>
<p id="t102" class="run"><span class="n"><a href="#t102">102</a></span><span class="t"> <span class="key">if</span> <span class="nam">ages</span> <span class="key">is</span> <span class="key">None</span> <span class="key">or</span> <span class="nam">sexes</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t103" class="run"><span class="n"><a href="#t103">103</a></span><span class="t"> <span class="nam">random_inds</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">permutation</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t104" class="run"><span class="n"><a href="#t104">104</a></span><span class="t"> <span class="nam">ages</span> <span class="op">=</span> <span class="op">[</span><span class="nam">gen_ages</span><span class="op">[</span><span class="nam">r</span><span class="op">]</span> <span class="key">for</span> <span class="nam">r</span> <span class="key">in</span> <span class="nam">random_inds</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t105" class="run"><span class="n"><a href="#t105">105</a></span><span class="t"> <span class="nam">sexes</span> <span class="op">=</span> <span class="op">[</span><span class="nam">gen_sexes</span><span class="op">[</span><span class="nam">r</span><span class="op">]</span> <span class="key">for</span> <span class="nam">r</span> <span class="key">in</span> <span class="nam">random_inds</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t106" class="pln"><span class="n"><a href="#t106">106</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t107" class="pln"><span class="n"><a href="#t107">107</a></span><span class="t"> <span class="com"># you have both ages and sexes so we'll just populate that for you...</span> </span><span class="r"></span></p>
<p id="t108" class="run"><span class="n"><a href="#t108">108</a></span><span class="t"> <span class="nam">popdict</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t109" class="run"><span class="n"><a href="#t109">109</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span><span class="op">,</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">uids</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t110" class="run"><span class="n"><a href="#t110">110</a></span><span class="t"> <span class="nam">u</span> <span class="op">=</span> <span class="nam">uid_mapping</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t111" class="run"><span class="n"><a href="#t111">111</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">u</span><span class="op">]</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t112" class="run"><span class="n"><a href="#t112">112</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">u</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">ages</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t113" class="run"><span class="n"><a href="#t113">113</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">u</span><span class="op">]</span><span class="op">[</span><span class="str">'sex'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">sexes</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t114" class="run"><span class="n"><a href="#t114">114</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">u</span><span class="op">]</span><span class="op">[</span><span class="str">'loc'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t115" class="run"><span class="n"><a href="#t115">115</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">u</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span> <span class="op">=</span> <span class="op">{</span><span class="str">'M'</span><span class="op">:</span> <span class="nam">set</span><span class="op">(</span><span class="op">)</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t116" class="pln"><span class="n"><a href="#t116">116</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t117" class="run"><span class="n"><a href="#t117">117</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t118" class="pln"><span class="n"><a href="#t118">118</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t119" class="pln"><span class="n"><a href="#t119">119</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t120" class="run"><span class="n"><a href="#t120">120</a></span><span class="t"><span class="key">def</span> <span class="nam">make_contacts_generic</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">network_distr_args</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t121" class="pln"><span class="n"><a href="#t121">121</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t122" class="pln"><span class="n"><a href="#t122">122</a></span><span class="t"><span class="str"> Create contact network regardless of age, according to network distribution properties. Can be used by webapp.</span> </span><span class="r"></span></p>
<p id="t123" class="pln"><span class="n"><a href="#t123">123</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t124" class="pln"><span class="n"><a href="#t124">124</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t125" class="pln"><span class="n"><a href="#t125">125</a></span><span class="t"><span class="str"> popdict (dict) : dictionary of all individuals</span> </span><span class="r"></span></p>
<p id="t126" class="pln"><span class="n"><a href="#t126">126</a></span><span class="t"><span class="str"> network_distr_args (dict): network distribution parameters dictionary for average_degree, network_type, and directionality</span> </span><span class="r"></span></p>
<p id="t127" class="pln"><span class="n"><a href="#t127">127</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t128" class="pln"><span class="n"><a href="#t128">128</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t129" class="pln"><span class="n"><a href="#t129">129</a></span><span class="t"><span class="str"> A dictionary of individuals with contacts drawn from given network distribution parameters.</span> </span><span class="r"></span></p>
<p id="t130" class="pln"><span class="n"><a href="#t130">130</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t131" class="pln"><span class="n"><a href="#t131">131</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t132" class="run"><span class="n"><a href="#t132">132</a></span><span class="t"> <span class="nam">n_contacts</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_degree'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t133" class="run"><span class="n"><a href="#t133">133</a></span><span class="t"> <span class="nam">network_type</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'network_type'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t134" class="run"><span class="n"><a href="#t134">134</a></span><span class="t"> <span class="nam">directed</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'directed'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t135" class="pln"><span class="n"><a href="#t135">135</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t136" class="run"><span class="n"><a href="#t136">136</a></span><span class="t"> <span class="nam">uids</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">.</span><span class="nam">keys</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t137" class="run"><span class="n"><a href="#t137">137</a></span><span class="t"> <span class="nam">uids</span> <span class="op">=</span> <span class="op">[</span><span class="nam">uid</span> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">uids</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t138" class="pln"><span class="n"><a href="#t138">138</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t139" class="run"><span class="n"><a href="#t139">139</a></span><span class="t"> <span class="nam">N</span> <span class="op">=</span> <span class="nam">len</span><span class="op">(</span><span class="nam">popdict</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t140" class="run"><span class="n"><a href="#t140">140</a></span><span class="t"> <span class="key">if</span> <span class="nam">n_contacts</span> <span class="op">></span> <span class="nam">N</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t141" class="mis show_mis"><span class="n"><a href="#t141">141</a></span><span class="t"> <span class="nam">print</span><span class="op">(</span><span class="str">f'Average degree cannot be larger than the size of the population. Creating a completely connected graph now instead.'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t142" class="mis show_mis"><span class="n"><a href="#t142">142</a></span><span class="t"> <span class="nam">n_contacts</span> <span class="op">=</span> <span class="nam">N</span> </span><span class="r"></span></p>
<p id="t143" class="pln"><span class="n"><a href="#t143">143</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t144" class="run"><span class="n"><a href="#t144">144</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t145" class="run"><span class="n"><a href="#t145">145</a></span><span class="t"> <span class="nam">p</span> <span class="op">=</span> <span class="nam">float</span><span class="op">(</span><span class="nam">n_contacts</span><span class="op">)</span> <span class="op">/</span> <span class="nam">N</span> </span><span class="r"></span></p>
<p id="t146" class="pln"><span class="n"><a href="#t146">146</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t147" class="run"><span class="n"><a href="#t147">147</a></span><span class="t"> <span class="nam">G</span> <span class="op">=</span> <span class="nam">nx</span><span class="op">.</span><span class="nam">erdos_renyi_graph</span><span class="op">(</span><span class="nam">N</span><span class="op">,</span> <span class="nam">p</span><span class="op">,</span> <span class="nam">directed</span><span class="op">=</span><span class="nam">directed</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t148" class="pln"><span class="n"><a href="#t148">148</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t149" class="run"><span class="n"><a href="#t149">149</a></span><span class="t"> <span class="nam">A</span> <span class="op">=</span> <span class="op">[</span><span class="nam">a</span> <span class="key">for</span> <span class="nam">a</span> <span class="key">in</span> <span class="nam">G</span><span class="op">.</span><span class="nam">adjacency</span><span class="op">(</span><span class="op">)</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t150" class="pln"><span class="n"><a href="#t150">150</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t151" class="run"><span class="n"><a href="#t151">151</a></span><span class="t"> <span class="key">for</span> <span class="nam">n</span><span class="op">,</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">uids</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t152" class="pln"><span class="n"><a href="#t152">152</a></span><span class="t"> <span class="com"># source_uid = uids[n]</span> </span><span class="r"></span></p>
<p id="t153" class="run"><span class="n"><a href="#t153">153</a></span><span class="t"> <span class="nam">targets</span> <span class="op">=</span> <span class="op">[</span><span class="nam">t</span> <span class="key">for</span> <span class="nam">t</span> <span class="key">in</span> <span class="nam">A</span><span class="op">[</span><span class="nam">n</span><span class="op">]</span><span class="op">[</span><span class="num">1</span><span class="op">]</span><span class="op">.</span><span class="nam">keys</span><span class="op">(</span><span class="op">)</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t154" class="run"><span class="n"><a href="#t154">154</a></span><span class="t"> <span class="nam">target_uids</span> <span class="op">=</span> <span class="op">[</span><span class="nam">uids</span><span class="op">[</span><span class="nam">target</span><span class="op">]</span> <span class="key">for</span> <span class="nam">target</span> <span class="key">in</span> <span class="nam">targets</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t155" class="run"><span class="n"><a href="#t155">155</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="str">'M'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">set</span><span class="op">(</span><span class="nam">target_uids</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t156" class="pln"><span class="n"><a href="#t156">156</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t157" class="run"><span class="n"><a href="#t157">157</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t158" class="pln"><span class="n"><a href="#t158">158</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t159" class="pln"><span class="n"><a href="#t159">159</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t160" class="run"><span class="n"><a href="#t160">160</a></span><span class="t"><span class="key">def</span> <span class="nam">make_contacts_without_social_layers_152</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">n_contacts_dic</span><span class="op">,</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">,</span> <span class="nam">network_distr_args</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t161" class="pln"><span class="n"><a href="#t161">161</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t162" class="pln"><span class="n"><a href="#t162">162</a></span><span class="t"><span class="str"> Create contact network according to overall age-mixing contact matrices. Does not capture clustering or microstructure,</span> </span><span class="r"></span></p>
<p id="t163" class="pln"><span class="n"><a href="#t163">163</a></span><span class="t"><span class="str"> therefore exact households, schools, or workplaces are not created. However, this does separate agents according to their</span> </span><span class="r"></span></p>
<p id="t164" class="pln"><span class="n"><a href="#t164">164</a></span><span class="t"><span class="str"> age and gives them contacts likely for their age. For all ages, the average number of contacts is constant with this</span> </span><span class="r"></span></p>
<p id="t165" class="pln"><span class="n"><a href="#t165">165</a></span><span class="t"><span class="str"> method, although location specific data may prove this to not be true.</span> </span><span class="r"></span></p>
<p id="t166" class="pln"><span class="n"><a href="#t166">166</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t167" class="pln"><span class="n"><a href="#t167">167</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t168" class="pln"><span class="n"><a href="#t168">168</a></span><span class="t"><span class="str"> popdict (dict) : dictionary of all individuals</span> </span><span class="r"></span></p>
<p id="t169" class="pln"><span class="n"><a href="#t169">169</a></span><span class="t"><span class="str"> n_contacts_dic (dict) : number of contacts to draw on average by setting</span> </span><span class="r"></span></p>
<p id="t170" class="pln"><span class="n"><a href="#t170">170</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t171" class="pln"><span class="n"><a href="#t171">171</a></span><span class="t"><span class="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t172" class="pln"><span class="n"><a href="#t172">172</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in</span> </span><span class="r"></span></p>
<p id="t173" class="pln"><span class="n"><a href="#t173">173</a></span><span class="t"><span class="str"> sheet_name (string) : name of the sheet in the excel file with contact patterns</span> </span><span class="r"></span></p>
<p id="t174" class="pln"><span class="n"><a href="#t174">174</a></span><span class="t"><span class="str"> network_distr_args (dict) : network distribution parameters dictionary for average_degree, network_type, and directionality, can also include powerlaw exponents,</span> </span><span class="r"></span></p>
<p id="t175" class="pln"><span class="n"><a href="#t175">175</a></span><span class="t"><span class="str"> block sizes (re: SBMs), clustering distribution, or other properties needed to generate network structures. Checkout</span> </span><span class="r"></span></p>
<p id="t176" class="pln"><span class="n"><a href="#t176">176</a></span><span class="t"><span class="str"> https://networkx.github.io/documentation/stable/reference/generators.html#module-networkx.generators for what's possible</span> </span><span class="r"></span></p>
<p id="t177" class="pln"><span class="n"><a href="#t177">177</a></span><span class="t"><span class="str"> Default 'network_type' is 'poisson_degree' for Erdos-Renyi random graphs in large n limit.</span> </span><span class="r"></span></p>
<p id="t178" class="pln"><span class="n"><a href="#t178">178</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t179" class="pln"><span class="n"><a href="#t179">179</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t180" class="pln"><span class="n"><a href="#t180">180</a></span><span class="t"><span class="str"> A dictionary of individuals with attributes, including their age and the ids of their contacts drawn from given network distribution parameters and the ages of contacts drawn according to overall age mixing data.</span> </span><span class="r"></span></p>
<p id="t181" class="pln"><span class="n"><a href="#t181">181</a></span><span class="t"><span class="str"> A single social setting or layer of contacts.</span> </span><span class="r"></span></p>
<p id="t182" class="pln"><span class="n"><a href="#t182">182</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t183" class="pln"><span class="n"><a href="#t183">183</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t184" class="pln"><span class="n"><a href="#t184">184</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t185" class="run"><span class="n"><a href="#t185">185</a></span><span class="t"> <span class="nam">uids_by_age_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_uids_by_age_dic</span><span class="op">(</span><span class="nam">popdict</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t186" class="run"><span class="n"><a href="#t186">186</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_census_age_brackets</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t187" class="run"><span class="n"><a href="#t187">187</a></span><span class="t"> <span class="nam">num_agebrackets</span> <span class="op">=</span> <span class="nam">len</span><span class="op">(</span><span class="nam">age_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t188" class="run"><span class="n"><a href="#t188">188</a></span><span class="t"> <span class="nam">age_by_brackets_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_age_by_brackets_dic</span><span class="op">(</span><span class="nam">age_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t189" class="pln"><span class="n"><a href="#t189">189</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t190" class="run"><span class="n"><a href="#t190">190</a></span><span class="t"> <span class="nam">age_mixing_matrix_dic</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_contact_matrix_dic</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">=</span><span class="nam">sheet_name</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t191" class="run"><span class="n"><a href="#t191">191</a></span><span class="t"> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="str">'M'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">combine_matrices</span><span class="op">(</span><span class="nam">age_mixing_matrix_dic</span><span class="op">,</span> <span class="nam">n_contacts_dic</span><span class="op">,</span> <span class="nam">num_agebrackets</span><span class="op">)</span> <span class="com"># may need to normalize matrices before applying this method to K. Prem et al matrices because of the difference in what the raw matrices represent</span> </span><span class="r"></span></p>
<p id="t192" class="pln"><span class="n"><a href="#t192">192</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t193" class="run"><span class="n"><a href="#t193">193</a></span><span class="t"> <span class="nam">n_contacts</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_degree'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t194" class="run"><span class="n"><a href="#t194">194</a></span><span class="t"> <span class="nam">directed</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'directed'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t195" class="run"><span class="n"><a href="#t195">195</a></span><span class="t"> <span class="nam">network_type</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'network_type'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t196" class="pln"><span class="n"><a href="#t196">196</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t197" class="run"><span class="n"><a href="#t197">197</a></span><span class="t"> <span class="nam">k</span> <span class="op">=</span> <span class="str">'M'</span> </span><span class="r"></span></p>
<p id="t198" class="run"><span class="n"><a href="#t198">198</a></span><span class="t"> <span class="key">if</span> <span class="nam">directed</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t199" class="mis show_mis"><span class="n"><a href="#t199">199</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t200" class="mis show_mis"><span class="n"><a href="#t200">200</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t201" class="mis show_mis"><span class="n"><a href="#t201">201</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t202" class="mis show_mis"><span class="n"><a href="#t202">202</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t203" class="mis show_mis"><span class="n"><a href="#t203">203</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t204" class="pln"><span class="n"><a href="#t204">204</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t205" class="run"><span class="n"><a href="#t205">205</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t206" class="run"><span class="n"><a href="#t206">206</a></span><span class="t"> <span class="nam">n_contacts</span> <span class="op">=</span> <span class="nam">n_contacts</span><span class="op">/</span><span class="num">2</span> </span><span class="r"></span></p>
<p id="t207" class="run"><span class="n"><a href="#t207">207</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t208" class="run"><span class="n"><a href="#t208">208</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t209" class="run"><span class="n"><a href="#t209">209</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t210" class="run"><span class="n"><a href="#t210">210</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t211" class="run"><span class="n"><a href="#t211">211</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t212" class="run"><span class="n"><a href="#t212">212</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t213" class="pln"><span class="n"><a href="#t213">213</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t214" class="run"><span class="n"><a href="#t214">214</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t215" class="pln"><span class="n"><a href="#t215">215</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t216" class="pln"><span class="n"><a href="#t216">216</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t217" class="run"><span class="n"><a href="#t217">217</a></span><span class="t"><span class="key">def</span> <span class="nam">make_contacts_with_social_layers_152</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">n_contacts_dic</span><span class="op">,</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">,</span> <span class="nam">activity_args</span><span class="op">,</span> <span class="nam">network_distr_args</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t218" class="pln"><span class="n"><a href="#t218">218</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t219" class="pln"><span class="n"><a href="#t219">219</a></span><span class="t"><span class="str"> Create contact network according to overall age-mixing contact matrices. Does not capture clustering or microstructure,</span> </span><span class="r"></span></p>
<p id="t220" class="pln"><span class="n"><a href="#t220">220</a></span><span class="t"><span class="str"> therefore exact households, schools, or workplaces are not created. However, this does separate agents according to their</span> </span><span class="r"></span></p>
<p id="t221" class="pln"><span class="n"><a href="#t221">221</a></span><span class="t"><span class="str"> age and gives them contacts likely for their age specified by the social settings they are likely to participate in.</span> </span><span class="r"></span></p>
<p id="t222" class="pln"><span class="n"><a href="#t222">222</a></span><span class="t"><span class="str"> For all ages, the average number of contacts is constant with this method, although location specific data very wel may</span> </span><span class="r"></span></p>
<p id="t223" class="pln"><span class="n"><a href="#t223">223</a></span><span class="t"><span class="str"> prove this to not be true. In general, college students may also be workers, however here they are only students and we</span> </span><span class="r"></span></p>
<p id="t224" class="pln"><span class="n"><a href="#t224">224</a></span><span class="t"><span class="str"> assume that any of their contacts in the work environment are likely to look like their contacts at school.</span> </span><span class="r"></span></p>
<p id="t225" class="pln"><span class="n"><a href="#t225">225</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t226" class="pln"><span class="n"><a href="#t226">226</a></span><span class="t"><span class="str"> Essentially recreates an age-specific compartmental model's concept of contacts but for an agent based modeling framework.</span> </span><span class="r"></span></p>
<p id="t227" class="pln"><span class="n"><a href="#t227">227</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t228" class="pln"><span class="n"><a href="#t228">228</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t229" class="pln"><span class="n"><a href="#t229">229</a></span><span class="t"><span class="str"> popdict (dict) : dictionary of all individuals</span> </span><span class="r"></span></p>
<p id="t230" class="pln"><span class="n"><a href="#t230">230</a></span><span class="t"><span class="str"> n_contacts_dic (dict) : number of contacts to draw on average by setting</span> </span><span class="r"></span></p>
<p id="t231" class="pln"><span class="n"><a href="#t231">231</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t232" class="pln"><span class="n"><a href="#t232">232</a></span><span class="t"><span class="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t233" class="pln"><span class="n"><a href="#t233">233</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in</span> </span><span class="r"></span></p>
<p id="t234" class="pln"><span class="n"><a href="#t234">234</a></span><span class="t"><span class="str"> sheet_name (string) : name of the sheet in the excel file with contact patterns</span> </span><span class="r"></span></p>
<p id="t235" class="pln"><span class="n"><a href="#t235">235</a></span><span class="t"><span class="str"> activity_args (dict) : dictionary of age bounds for participating in different activities like going to school or working, also student-teacher ratio</span> </span><span class="r"></span></p>
<p id="t236" class="pln"><span class="n"><a href="#t236">236</a></span><span class="t"><span class="str"> network_distr_args (dict) : network distribution parameters dictionary for average_degree, network_type, and directionality, can also include powerlaw exponents,</span> </span><span class="r"></span></p>
<p id="t237" class="pln"><span class="n"><a href="#t237">237</a></span><span class="t"><span class="str"> block sizes (re: SBMs), clustering distribution, or other properties needed to generate network structures. Checkout</span> </span><span class="r"></span></p>
<p id="t238" class="pln"><span class="n"><a href="#t238">238</a></span><span class="t"><span class="str"> https://networkx.github.io/documentation/stable/reference/generators.html#module-networkx.generators for what's possible</span> </span><span class="r"></span></p>
<p id="t239" class="pln"><span class="n"><a href="#t239">239</a></span><span class="t"><span class="str"> Default 'network_type' is 'poisson_degree' for Erdos-Renyi random graphs in large n limit.</span> </span><span class="r"></span></p>
<p id="t240" class="pln"><span class="n"><a href="#t240">240</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t241" class="pln"><span class="n"><a href="#t241">241</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t242" class="pln"><span class="n"><a href="#t242">242</a></span><span class="t"><span class="str"> A dictionary of individuals with contacts with attributes, including their age and the ids of their contacts drawn from given network distribution parameters and the ages of contacts drawn according to age mixing data.</span> </span><span class="r"></span></p>
<p id="t243" class="pln"><span class="n"><a href="#t243">243</a></span><span class="t"><span class="str"> Multiple social settings or layers so contacts are listed for different layers.</span> </span><span class="r"></span></p>
<p id="t244" class="pln"><span class="n"><a href="#t244">244</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t245" class="pln"><span class="n"><a href="#t245">245</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t246" class="pln"><span class="n"><a href="#t246">246</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t247" class="run"><span class="n"><a href="#t247">247</a></span><span class="t"> <span class="nam">uids_by_age_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_uids_by_age_dic</span><span class="op">(</span><span class="nam">popdict</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t248" class="run"><span class="n"><a href="#t248">248</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_census_age_brackets</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t249" class="run"><span class="n"><a href="#t249">249</a></span><span class="t"> <span class="nam">num_agebrackets</span> <span class="op">=</span> <span class="nam">len</span><span class="op">(</span><span class="nam">age_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t250" class="run"><span class="n"><a href="#t250">250</a></span><span class="t"> <span class="nam">age_by_brackets_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_age_by_brackets_dic</span><span class="op">(</span><span class="nam">age_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t251" class="pln"><span class="n"><a href="#t251">251</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t252" class="run"><span class="n"><a href="#t252">252</a></span><span class="t"> <span class="nam">age_mixing_matrix_dic</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_contact_matrix_dic</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">=</span><span class="nam">sheet_name</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t253" class="run"><span class="n"><a href="#t253">253</a></span><span class="t"> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="str">'M'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">combine_matrices</span><span class="op">(</span><span class="nam">age_mixing_matrix_dic</span><span class="op">,</span> <span class="nam">n_contacts_dic</span><span class="op">,</span> <span class="nam">num_agebrackets</span><span class="op">)</span> <span class="com"># may need to normalize matrices before applying this method to K. Prem et al matrices because of the difference in what the raw matrices represent</span> </span><span class="r"></span></p>
<p id="t254" class="pln"><span class="n"><a href="#t254">254</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t255" class="run"><span class="n"><a href="#t255">255</a></span><span class="t"> <span class="nam">directed</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'directed'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t256" class="run"><span class="n"><a href="#t256">256</a></span><span class="t"> <span class="nam">network_type</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'network_type'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t257" class="pln"><span class="n"><a href="#t257">257</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t258" class="pln"><span class="n"><a href="#t258">258</a></span><span class="t"> <span class="com"># currently not set to capture school enrollment rates or work enrollment rates</span> </span><span class="r"></span></p>
<p id="t259" class="run"><span class="n"><a href="#t259">259</a></span><span class="t"> <span class="nam">student_n_dic</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">dcp</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t260" class="run"><span class="n"><a href="#t260">260</a></span><span class="t"> <span class="nam">non_student_n_dic</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">dcp</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t261" class="pln"><span class="n"><a href="#t261">261</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t262" class="pln"><span class="n"><a href="#t262">262</a></span><span class="t"> <span class="com"># this might not be needed because students will choose their teachers, but if directed then this makes teachers point to students as well</span> </span><span class="r"></span></p>
<p id="t263" class="run"><span class="n"><a href="#t263">263</a></span><span class="t"> <span class="nam">n_students</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">sum</span><span class="op">(</span><span class="op">[</span><span class="nam">len</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">[</span><span class="nam">a</span><span class="op">]</span><span class="op">)</span> <span class="key">for</span> <span class="nam">a</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span><span class="op">,</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_max'</span><span class="op">]</span><span class="op">+</span><span class="num">1</span><span class="op">)</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t264" class="run"><span class="n"><a href="#t264">264</a></span><span class="t"> <span class="nam">n_workers</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">sum</span><span class="op">(</span><span class="op">[</span><span class="nam">len</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">[</span><span class="nam">a</span><span class="op">]</span><span class="op">)</span> <span class="key">for</span> <span class="nam">a</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_min'</span><span class="op">]</span><span class="op">,</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">+</span><span class="num">1</span><span class="op">)</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t265" class="run"><span class="n"><a href="#t265">265</a></span><span class="t"> <span class="nam">n_teachers</span> <span class="op">=</span> <span class="nam">n_students</span><span class="op">/</span><span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_teacher_ratio'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t266" class="run"><span class="n"><a href="#t266">266</a></span><span class="t"> <span class="nam">teachers_school_weight</span> <span class="op">=</span> <span class="nam">n_teachers</span><span class="op">/</span><span class="nam">n_workers</span> </span><span class="r"></span></p>
<p id="t267" class="pln"><span class="n"><a href="#t267">267</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t268" class="run"><span class="n"><a href="#t268">268</a></span><span class="t"> <span class="nam">student_n_dic</span><span class="op">[</span><span class="str">'W'</span><span class="op">]</span> <span class="op">=</span> <span class="num">0</span> </span><span class="r"></span></p>
<p id="t269" class="run"><span class="n"><a href="#t269">269</a></span><span class="t"> <span class="nam">non_student_n_dic</span><span class="op">[</span><span class="str">'S'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">teachers_school_weight</span> <span class="com"># make some teachers</span> </span><span class="r"></span></p>
<p id="t270" class="pln"><span class="n"><a href="#t270">270</a></span><span class="t"> <span class="com"># 5 categories as defined by activity_args:</span> </span><span class="r"></span></p>
<p id="t271" class="pln"><span class="n"><a href="#t271">271</a></span><span class="t"> <span class="com"># infants & toddlers : H, C</span> </span><span class="r"></span></p>
<p id="t272" class="pln"><span class="n"><a href="#t272">272</a></span><span class="t"> <span class="com"># school-aged students : H, S, C</span> </span><span class="r"></span></p>
<p id="t273" class="pln"><span class="n"><a href="#t273">273</a></span><span class="t"> <span class="com"># college-aged students / workers : H, S, W, C</span> </span><span class="r"></span></p>
<p id="t274" class="pln"><span class="n"><a href="#t274">274</a></span><span class="t"> <span class="com"># non-student workers : H, W, C</span> </span><span class="r"></span></p>
<p id="t275" class="pln"><span class="n"><a href="#t275">275</a></span><span class="t"> <span class="com"># retired elderly : H, C - some may be workers too but it's low. directed means they won't have contacts in the workplace, but undirected means they will at least a little.</span> </span><span class="r"></span></p>
<p id="t276" class="pln"><span class="n"><a href="#t276">276</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t277" class="pln"><span class="n"><a href="#t277">277</a></span><span class="t"> <span class="com"># will follow degree distribution well</span> </span><span class="r"></span></p>
<p id="t278" class="run"><span class="n"><a href="#t278">278</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t279" class="run"><span class="n"><a href="#t279">279</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="nam">n_contacts_dic</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t280" class="run"><span class="n"><a href="#t280">280</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">set</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t281" class="pln"><span class="n"><a href="#t281">281</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t282" class="run"><span class="n"><a href="#t282">282</a></span><span class="t"> <span class="key">if</span> <span class="nam">directed</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t283" class="pln"><span class="n"><a href="#t283">283</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t284" class="mis show_mis"><span class="n"><a href="#t284">284</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t285" class="mis show_mis"><span class="n"><a href="#t285">285</a></span><span class="t"> <span class="nam">age</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t286" class="mis show_mis"><span class="n"><a href="#t286">286</a></span><span class="t"> <span class="key">if</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t287" class="mis show_mis"><span class="n"><a href="#t287">287</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t288" class="mis show_mis"><span class="n"><a href="#t288">288</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t289" class="mis show_mis"><span class="n"><a href="#t289">289</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t290" class="mis show_mis"><span class="n"><a href="#t290">290</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t291" class="mis show_mis"><span class="n"><a href="#t291">291</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t292" class="pln"><span class="n"><a href="#t292">292</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t293" class="mis show_mis"><span class="n"><a href="#t293">293</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t294" class="mis show_mis"><span class="n"><a href="#t294">294</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t295" class="mis show_mis"><span class="n"><a href="#t295">295</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t296" class="mis show_mis"><span class="n"><a href="#t296">296</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t297" class="mis show_mis"><span class="n"><a href="#t297">297</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t298" class="mis show_mis"><span class="n"><a href="#t298">298</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t299" class="pln"><span class="n"><a href="#t299">299</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t300" class="mis show_mis"><span class="n"><a href="#t300">300</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t301" class="mis show_mis"><span class="n"><a href="#t301">301</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t302" class="mis show_mis"><span class="n"><a href="#t302">302</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t303" class="mis show_mis"><span class="n"><a href="#t303">303</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t304" class="mis show_mis"><span class="n"><a href="#t304">304</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t305" class="mis show_mis"><span class="n"><a href="#t305">305</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t306" class="pln"><span class="n"><a href="#t306">306</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t307" class="mis show_mis"><span class="n"><a href="#t307">307</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t308" class="mis show_mis"><span class="n"><a href="#t308">308</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'W'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t309" class="mis show_mis"><span class="n"><a href="#t309">309</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t310" class="mis show_mis"><span class="n"><a href="#t310">310</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">non_student_n_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t311" class="mis show_mis"><span class="n"><a href="#t311">311</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t312" class="mis show_mis"><span class="n"><a href="#t312">312</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t313" class="pln"><span class="n"><a href="#t313">313</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t314" class="mis show_mis"><span class="n"><a href="#t314">314</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t315" class="mis show_mis"><span class="n"><a href="#t315">315</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t316" class="mis show_mis"><span class="n"><a href="#t316">316</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t317" class="mis show_mis"><span class="n"><a href="#t317">317</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t318" class="mis show_mis"><span class="n"><a href="#t318">318</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t319" class="mis show_mis"><span class="n"><a href="#t319">319</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t320" class="pln"><span class="n"><a href="#t320">320</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t321" class="pln"><span class="n"><a href="#t321">321</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t322" class="run"><span class="n"><a href="#t322">322</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t323" class="run"><span class="n"><a href="#t323">323</a></span><span class="t"> <span class="nam">age</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t324" class="run"><span class="n"><a href="#t324">324</a></span><span class="t"> <span class="key">if</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t325" class="run"><span class="n"><a href="#t325">325</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t326" class="run"><span class="n"><a href="#t326">326</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t327" class="run"><span class="n"><a href="#t327">327</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t328" class="run"><span class="n"><a href="#t328">328</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t329" class="run"><span class="n"><a href="#t329">329</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t330" class="run"><span class="n"><a href="#t330">330</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t331" class="run"><span class="n"><a href="#t331">331</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t332" class="pln"><span class="n"><a href="#t332">332</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t333" class="run"><span class="n"><a href="#t333">333</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t334" class="run"><span class="n"><a href="#t334">334</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t335" class="run"><span class="n"><a href="#t335">335</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t336" class="run"><span class="n"><a href="#t336">336</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t337" class="run"><span class="n"><a href="#t337">337</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t338" class="run"><span class="n"><a href="#t338">338</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t339" class="run"><span class="n"><a href="#t339">339</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t340" class="run"><span class="n"><a href="#t340">340</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t341" class="pln"><span class="n"><a href="#t341">341</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t342" class="run"><span class="n"><a href="#t342">342</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t343" class="run"><span class="n"><a href="#t343">343</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t344" class="run"><span class="n"><a href="#t344">344</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t345" class="run"><span class="n"><a href="#t345">345</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t346" class="run"><span class="n"><a href="#t346">346</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t347" class="run"><span class="n"><a href="#t347">347</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t348" class="run"><span class="n"><a href="#t348">348</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t349" class="run"><span class="n"><a href="#t349">349</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t350" class="pln"><span class="n"><a href="#t350">350</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t351" class="run"><span class="n"><a href="#t351">351</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t352" class="run"><span class="n"><a href="#t352">352</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'W'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t353" class="run"><span class="n"><a href="#t353">353</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t354" class="run"><span class="n"><a href="#t354">354</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">non_student_n_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t355" class="run"><span class="n"><a href="#t355">355</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t356" class="run"><span class="n"><a href="#t356">356</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t357" class="run"><span class="n"><a href="#t357">357</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t358" class="run"><span class="n"><a href="#t358">358</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t359" class="pln"><span class="n"><a href="#t359">359</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t360" class="run"><span class="n"><a href="#t360">360</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t361" class="run"><span class="n"><a href="#t361">361</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t362" class="run"><span class="n"><a href="#t362">362</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t363" class="run"><span class="n"><a href="#t363">363</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t364" class="run"><span class="n"><a href="#t364">364</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t365" class="run"><span class="n"><a href="#t365">365</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t366" class="run"><span class="n"><a href="#t366">366</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t367" class="run"><span class="n"><a href="#t367">367</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t368" class="pln"><span class="n"><a href="#t368">368</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t369" class="run"><span class="n"><a href="#t369">369</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t370" class="pln"><span class="n"><a href="#t370">370</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t371" class="pln"><span class="n"><a href="#t371">371</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t372" class="run"><span class="n"><a href="#t372">372</a></span><span class="t"><span class="key">def</span> <span class="nam">make_contacts_without_social_layers_and_sex</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">n_contacts_dic</span><span class="op">,</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">,</span> <span class="nam">network_distr_args</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t373" class="pln"><span class="n"><a href="#t373">373</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t374" class="pln"><span class="n"><a href="#t374">374</a></span><span class="t"><span class="str"> Create contact network according to overall age-mixing contact matrices for the US. Does not capture clustering or microstructure, therefore</span> </span><span class="r"></span></p>
<p id="t375" class="pln"><span class="n"><a href="#t375">375</a></span><span class="t"><span class="str"> exact households, schools, or workplaces are not created. However, this does separate agents according to their age and gives them contacts</span> </span><span class="r"></span></p>
<p id="t376" class="pln"><span class="n"><a href="#t376">376</a></span><span class="t"><span class="str"> likely for their age. For all ages, the average number of contacts is constant, although location specific data may prove this to not be true.</span> </span><span class="r"></span></p>
<p id="t377" class="pln"><span class="n"><a href="#t377">377</a></span><span class="t"><span class="str"> Individuals also have a sex, though this in general does not have an impact on their contact patterns.</span> </span><span class="r"></span></p>
<p id="t378" class="pln"><span class="n"><a href="#t378">378</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t379" class="pln"><span class="n"><a href="#t379">379</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t380" class="pln"><span class="n"><a href="#t380">380</a></span><span class="t"><span class="str"> popdict (dict) : dictionary of all individuals</span> </span><span class="r"></span></p>
<p id="t381" class="pln"><span class="n"><a href="#t381">381</a></span><span class="t"><span class="str"> n_contacts_dic (dict) : number of contacts to draw on average by setting</span> </span><span class="r"></span></p>
<p id="t382" class="pln"><span class="n"><a href="#t382">382</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t383" class="pln"><span class="n"><a href="#t383">383</a></span><span class="t"><span class="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t384" class="pln"><span class="n"><a href="#t384">384</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in</span> </span><span class="r"></span></p>
<p id="t385" class="pln"><span class="n"><a href="#t385">385</a></span><span class="t"><span class="str"> sheet_name (string) : name of the sheet in the excel file with contact patterns</span> </span><span class="r"></span></p>
<p id="t386" class="pln"><span class="n"><a href="#t386">386</a></span><span class="t"><span class="str"> network_distr_args (dict) : network distribution parameters dictionary for average_degree, network_type, and directionality, can also include powerlaw exponents,</span> </span><span class="r"></span></p>
<p id="t387" class="pln"><span class="n"><a href="#t387">387</a></span><span class="t"><span class="str"> block sizes (re: SBMs), clustering distribution, or other properties needed to generate network structures. Checkout</span> </span><span class="r"></span></p>
<p id="t388" class="pln"><span class="n"><a href="#t388">388</a></span><span class="t"><span class="str"> https://networkx.github.io/documentation/stable/reference/generators.html#module-networkx.generators for what's possible</span> </span><span class="r"></span></p>
<p id="t389" class="pln"><span class="n"><a href="#t389">389</a></span><span class="t"><span class="str"> Default 'network_type' is 'poisson_degree' for Erdos-Renyi random graphs in large n limit.</span> </span><span class="r"></span></p>
<p id="t390" class="pln"><span class="n"><a href="#t390">390</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t391" class="pln"><span class="n"><a href="#t391">391</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t392" class="pln"><span class="n"><a href="#t392">392</a></span><span class="t"><span class="str"> A dictionary of individuals with attributes, including their age and the ids of their contacts drawn from given network distribution parameters and the ages of contacts drawn according to overall age mixing data.</span> </span><span class="r"></span></p>
<p id="t393" class="pln"><span class="n"><a href="#t393">393</a></span><span class="t"><span class="str"> A single social setting or layer of contacts.</span> </span><span class="r"></span></p>
<p id="t394" class="pln"><span class="n"><a href="#t394">394</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t395" class="pln"><span class="n"><a href="#t395">395</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t396" class="pln"><span class="n"><a href="#t396">396</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t397" class="pln"><span class="n"><a href="#t397">397</a></span><span class="t"> <span class="com"># using a flat contact matrix</span> </span><span class="r"></span></p>
<p id="t398" class="mis show_mis"><span class="n"><a href="#t398">398</a></span><span class="t"> <span class="nam">uids_by_age_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_uids_by_age_dic</span><span class="op">(</span><span class="nam">popdict</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t399" class="mis show_mis"><span class="n"><a href="#t399">399</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_census_age_brackets</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t400" class="pln"><span class="n"><a href="#t400">400</a></span><span class="t"> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t401" class="mis show_mis"><span class="n"><a href="#t401">401</a></span><span class="t"> <span class="nam">age_by_brackets_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_age_by_brackets_dic</span><span class="op">(</span><span class="nam">age_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t402" class="mis show_mis"><span class="n"><a href="#t402">402</a></span><span class="t"> <span class="nam">num_agebrackets</span> <span class="op">=</span> <span class="nam">len</span><span class="op">(</span><span class="nam">age_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t403" class="pln"><span class="n"><a href="#t403">403</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t404" class="mis show_mis"><span class="n"><a href="#t404">404</a></span><span class="t"> <span class="nam">age_mixing_matrix_dic</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_contact_matrix_dic</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t405" class="mis show_mis"><span class="n"><a href="#t405">405</a></span><span class="t"> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="str">'M'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">combine_matrices</span><span class="op">(</span><span class="nam">age_mixing_matrix_dic</span><span class="op">,</span> <span class="nam">n_contacts_dic</span><span class="op">,</span> <span class="nam">num_agebrackets</span><span class="op">)</span> <span class="com"># may need to normalize matrices before applying this method to K. Prem et al matrices because of the difference in what the raw matrices represent</span> </span><span class="r"></span></p>
<p id="t406" class="pln"><span class="n"><a href="#t406">406</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t407" class="mis show_mis"><span class="n"><a href="#t407">407</a></span><span class="t"> <span class="nam">n_contacts</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_degree'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t408" class="mis show_mis"><span class="n"><a href="#t408">408</a></span><span class="t"> <span class="nam">directed</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'directed'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t409" class="mis show_mis"><span class="n"><a href="#t409">409</a></span><span class="t"> <span class="nam">network_type</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'network_type'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t410" class="pln"><span class="n"><a href="#t410">410</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t411" class="mis show_mis"><span class="n"><a href="#t411">411</a></span><span class="t"> <span class="nam">k</span> <span class="op">=</span> <span class="str">'M'</span> </span><span class="r"></span></p>
<p id="t412" class="pln"><span class="n"><a href="#t412">412</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t413" class="mis show_mis"><span class="n"><a href="#t413">413</a></span><span class="t"> <span class="key">if</span> <span class="nam">directed</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t414" class="mis show_mis"><span class="n"><a href="#t414">414</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t415" class="mis show_mis"><span class="n"><a href="#t415">415</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t416" class="mis show_mis"><span class="n"><a href="#t416">416</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t417" class="mis show_mis"><span class="n"><a href="#t417">417</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t418" class="mis show_mis"><span class="n"><a href="#t418">418</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t419" class="pln"><span class="n"><a href="#t419">419</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t420" class="pln"><span class="n"><a href="#t420">420</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t421" class="mis show_mis"><span class="n"><a href="#t421">421</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t422" class="mis show_mis"><span class="n"><a href="#t422">422</a></span><span class="t"> <span class="nam">n_contacts</span> <span class="op">=</span> <span class="nam">n_contacts</span><span class="op">/</span><span class="num">2</span> </span><span class="r"></span></p>
<p id="t423" class="mis show_mis"><span class="n"><a href="#t423">423</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t424" class="mis show_mis"><span class="n"><a href="#t424">424</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t425" class="mis show_mis"><span class="n"><a href="#t425">425</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t426" class="mis show_mis"><span class="n"><a href="#t426">426</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t427" class="mis show_mis"><span class="n"><a href="#t427">427</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t428" class="mis show_mis"><span class="n"><a href="#t428">428</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t429" class="pln"><span class="n"><a href="#t429">429</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t430" class="mis show_mis"><span class="n"><a href="#t430">430</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t431" class="pln"><span class="n"><a href="#t431">431</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t432" class="pln"><span class="n"><a href="#t432">432</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t433" class="run"><span class="n"><a href="#t433">433</a></span><span class="t"><span class="key">def</span> <span class="nam">make_contacts_with_social_layers_and_sex</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">n_contacts_dic</span><span class="op">,</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">,</span> <span class="nam">activity_args</span><span class="op">,</span> <span class="nam">network_distr_args</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t434" class="pln"><span class="n"><a href="#t434">434</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t435" class="pln"><span class="n"><a href="#t435">435</a></span><span class="t"><span class="str"> Create contact network according to overall age-mixing contact matrices for the US.</span> </span><span class="r"></span></p>
<p id="t436" class="pln"><span class="n"><a href="#t436">436</a></span><span class="t"><span class="str"> Does not capture clustering or microstructure, therefore exact households, schools, or workplaces are not created.</span> </span><span class="r"></span></p>
<p id="t437" class="pln"><span class="n"><a href="#t437">437</a></span><span class="t"><span class="str"> However, this does separate agents according to their age and gives them contacts likely for their age specified by</span> </span><span class="r"></span></p>
<p id="t438" class="pln"><span class="n"><a href="#t438">438</a></span><span class="t"><span class="str"> the social settings they are likely to participate in. College students may also be workers, however here they are</span> </span><span class="r"></span></p>
<p id="t439" class="pln"><span class="n"><a href="#t439">439</a></span><span class="t"><span class="str"> only students and we assume that any of their contacts in the work environment are likely to look like their contacts at school.</span> </span><span class="r"></span></p>
<p id="t440" class="pln"><span class="n"><a href="#t440">440</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t441" class="pln"><span class="n"><a href="#t441">441</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t442" class="pln"><span class="n"><a href="#t442">442</a></span><span class="t"><span class="str"> popdict (dict) : dictionary of all individuals</span> </span><span class="r"></span></p>
<p id="t443" class="pln"><span class="n"><a href="#t443">443</a></span><span class="t"><span class="str"> n_contacts_dic (dict) : number of contacts to draw on average by setting</span> </span><span class="r"></span></p>
<p id="t444" class="pln"><span class="n"><a href="#t444">444</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t445" class="pln"><span class="n"><a href="#t445">445</a></span><span class="t"><span class="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t446" class="pln"><span class="n"><a href="#t446">446</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in</span> </span><span class="r"></span></p>
<p id="t447" class="pln"><span class="n"><a href="#t447">447</a></span><span class="t"><span class="str"> sheet_name (string) : name of the sheet in the excel file with contact patterns</span> </span><span class="r"></span></p>
<p id="t448" class="pln"><span class="n"><a href="#t448">448</a></span><span class="t"><span class="str"> activity_args (dict) : dictionary of age bounds for participating in different activities like going to school or working, also student-teacher ratio</span> </span><span class="r"></span></p>
<p id="t449" class="pln"><span class="n"><a href="#t449">449</a></span><span class="t"><span class="str"> network_distr_args (dict) : network distribution parameters dictionary for average_degree, network_type, and directionality, can also include powerlaw exponents,</span> </span><span class="r"></span></p>
<p id="t450" class="pln"><span class="n"><a href="#t450">450</a></span><span class="t"><span class="str"> block sizes (re: SBMs), clustering distribution, or other properties needed to generate network structures. Checkout</span> </span><span class="r"></span></p>
<p id="t451" class="pln"><span class="n"><a href="#t451">451</a></span><span class="t"><span class="str"> https://networkx.github.io/documentation/stable/reference/generators.html#module-networkx.generators for what's possible</span> </span><span class="r"></span></p>
<p id="t452" class="pln"><span class="n"><a href="#t452">452</a></span><span class="t"><span class="str"> Default 'network_type' is 'poisson_degree' for Erdos-Renyi random graphs in large n limit.</span> </span><span class="r"></span></p>
<p id="t453" class="pln"><span class="n"><a href="#t453">453</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t454" class="pln"><span class="n"><a href="#t454">454</a></span><span class="t"><span class="str"> A dictionary of individuals with attributes, including their age and the ids of their contacts drawn from given network distribution parameters and the ages of contacts drawn according to age mixing data.</span> </span><span class="r"></span></p>
<p id="t455" class="pln"><span class="n"><a href="#t455">455</a></span><span class="t"><span class="str"> Multiple social settings or layers so contacts are listed for different layers.</span> </span><span class="r"></span></p>
<p id="t456" class="pln"><span class="n"><a href="#t456">456</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t457" class="pln"><span class="n"><a href="#t457">457</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t458" class="pln"><span class="n"><a href="#t458">458</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t459" class="pln"><span class="n"><a href="#t459">459</a></span><span class="t"> <span class="com"># use a contact matrix dictionary and n_contacts_dic for the average number of contacts in each layer</span> </span><span class="r"></span></p>
<p id="t460" class="run"><span class="n"><a href="#t460">460</a></span><span class="t"> <span class="nam">uids_by_age_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_uids_by_age_dic</span><span class="op">(</span><span class="nam">popdict</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t461" class="pln"><span class="n"><a href="#t461">461</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t462" class="run"><span class="n"><a href="#t462">462</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_census_age_brackets</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t463" class="pln"><span class="n"><a href="#t463">463</a></span><span class="t"> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t464" class="run"><span class="n"><a href="#t464">464</a></span><span class="t"> <span class="nam">age_by_brackets_dic</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">get_age_by_brackets_dic</span><span class="op">(</span><span class="nam">age_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t465" class="pln"><span class="n"><a href="#t465">465</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t466" class="run"><span class="n"><a href="#t466">466</a></span><span class="t"> <span class="nam">age_mixing_matrix_dic</span> <span class="op">=</span> <span class="nam">spdata</span><span class="op">.</span><span class="nam">get_contact_matrix_dic</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t467" class="pln"><span class="n"><a href="#t467">467</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t468" class="run"><span class="n"><a href="#t468">468</a></span><span class="t"> <span class="nam">directed</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'directed'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t469" class="run"><span class="n"><a href="#t469">469</a></span><span class="t"> <span class="nam">network_type</span> <span class="op">=</span> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'network_type'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t470" class="pln"><span class="n"><a href="#t470">470</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t471" class="run"><span class="n"><a href="#t471">471</a></span><span class="t"> <span class="nam">student_n_dic</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">dcp</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t472" class="run"><span class="n"><a href="#t472">472</a></span><span class="t"> <span class="nam">non_student_n_dic</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">dcp</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t473" class="pln"><span class="n"><a href="#t473">473</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t474" class="pln"><span class="n"><a href="#t474">474</a></span><span class="t"> <span class="com"># this might not be needed because students will choose their teachers, but if directed then this makes teachers point to students as well</span> </span><span class="r"></span></p>
<p id="t475" class="run"><span class="n"><a href="#t475">475</a></span><span class="t"> <span class="nam">n_students</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">sum</span><span class="op">(</span><span class="op">[</span><span class="nam">len</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">[</span><span class="nam">a</span><span class="op">]</span><span class="op">)</span> <span class="key">for</span> <span class="nam">a</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span><span class="op">,</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_max'</span><span class="op">]</span><span class="op">+</span><span class="num">1</span><span class="op">)</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t476" class="run"><span class="n"><a href="#t476">476</a></span><span class="t"> <span class="nam">n_workers</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">sum</span><span class="op">(</span><span class="op">[</span><span class="nam">len</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">[</span><span class="nam">a</span><span class="op">]</span><span class="op">)</span> <span class="key">for</span> <span class="nam">a</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_min'</span><span class="op">]</span><span class="op">,</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">+</span><span class="num">1</span><span class="op">)</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t477" class="run"><span class="n"><a href="#t477">477</a></span><span class="t"> <span class="nam">n_teachers</span> <span class="op">=</span> <span class="nam">n_students</span><span class="op">/</span><span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_teacher_ratio'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t478" class="run"><span class="n"><a href="#t478">478</a></span><span class="t"> <span class="nam">teachers_school_weight</span> <span class="op">=</span> <span class="nam">n_teachers</span><span class="op">/</span><span class="nam">n_workers</span> </span><span class="r"></span></p>
<p id="t479" class="pln"><span class="n"><a href="#t479">479</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t480" class="run"><span class="n"><a href="#t480">480</a></span><span class="t"> <span class="nam">student_n_dic</span><span class="op">[</span><span class="str">'W'</span><span class="op">]</span> <span class="op">=</span> <span class="num">0</span> </span><span class="r"></span></p>
<p id="t481" class="run"><span class="n"><a href="#t481">481</a></span><span class="t"> <span class="nam">non_student_n_dic</span><span class="op">[</span><span class="str">'S'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">teachers_school_weight</span> <span class="com"># make some teachers</span> </span><span class="r"></span></p>
<p id="t482" class="pln"><span class="n"><a href="#t482">482</a></span><span class="t"> <span class="com"># 5 categories :</span> </span><span class="r"></span></p>
<p id="t483" class="pln"><span class="n"><a href="#t483">483</a></span><span class="t"> <span class="com"># infants & toddlers : H, C</span> </span><span class="r"></span></p>
<p id="t484" class="pln"><span class="n"><a href="#t484">484</a></span><span class="t"> <span class="com"># school-aged students : H, S, C</span> </span><span class="r"></span></p>
<p id="t485" class="pln"><span class="n"><a href="#t485">485</a></span><span class="t"> <span class="com"># college-aged students / workers : H, S, W, C</span> </span><span class="r"></span></p>
<p id="t486" class="pln"><span class="n"><a href="#t486">486</a></span><span class="t"> <span class="com"># non-student workers : H, W, C</span> </span><span class="r"></span></p>
<p id="t487" class="pln"><span class="n"><a href="#t487">487</a></span><span class="t"> <span class="com"># retired elderly : H, C - some may be workers too but it's low. directed means they won't have contacts in the workplace, but undirected means they will at least a little.</span> </span><span class="r"></span></p>
<p id="t488" class="pln"><span class="n"><a href="#t488">488</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t489" class="pln"><span class="n"><a href="#t489">489</a></span><span class="t"> <span class="com"># will follow degree distribution well</span> </span><span class="r"></span></p>
<p id="t490" class="run"><span class="n"><a href="#t490">490</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t491" class="run"><span class="n"><a href="#t491">491</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="nam">n_contacts_dic</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t492" class="run"><span class="n"><a href="#t492">492</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">set</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t493" class="pln"><span class="n"><a href="#t493">493</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t494" class="run"><span class="n"><a href="#t494">494</a></span><span class="t"> <span class="key">if</span> <span class="nam">directed</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t495" class="pln"><span class="n"><a href="#t495">495</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t496" class="mis show_mis"><span class="n"><a href="#t496">496</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t497" class="mis show_mis"><span class="n"><a href="#t497">497</a></span><span class="t"> <span class="nam">age</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t498" class="mis show_mis"><span class="n"><a href="#t498">498</a></span><span class="t"> <span class="key">if</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t499" class="mis show_mis"><span class="n"><a href="#t499">499</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t500" class="mis show_mis"><span class="n"><a href="#t500">500</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t501" class="mis show_mis"><span class="n"><a href="#t501">501</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t502" class="mis show_mis"><span class="n"><a href="#t502">502</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t503" class="mis show_mis"><span class="n"><a href="#t503">503</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t504" class="pln"><span class="n"><a href="#t504">504</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t505" class="mis show_mis"><span class="n"><a href="#t505">505</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t506" class="mis show_mis"><span class="n"><a href="#t506">506</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t507" class="mis show_mis"><span class="n"><a href="#t507">507</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t508" class="mis show_mis"><span class="n"><a href="#t508">508</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t509" class="mis show_mis"><span class="n"><a href="#t509">509</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t510" class="mis show_mis"><span class="n"><a href="#t510">510</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t511" class="pln"><span class="n"><a href="#t511">511</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t512" class="mis show_mis"><span class="n"><a href="#t512">512</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t513" class="mis show_mis"><span class="n"><a href="#t513">513</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t514" class="mis show_mis"><span class="n"><a href="#t514">514</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t515" class="pln"><span class="n"><a href="#t515">515</a></span><span class="t"> <span class="com"># people at school and work? how??? college students going to school might actually look like their work environments anyways so for now this is just going to have schools and no work</span> </span><span class="r"></span></p>
<p id="t516" class="mis show_mis"><span class="n"><a href="#t516">516</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t517" class="mis show_mis"><span class="n"><a href="#t517">517</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t518" class="mis show_mis"><span class="n"><a href="#t518">518</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t519" class="pln"><span class="n"><a href="#t519">519</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t520" class="mis show_mis"><span class="n"><a href="#t520">520</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t521" class="mis show_mis"><span class="n"><a href="#t521">521</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'W'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t522" class="mis show_mis"><span class="n"><a href="#t522">522</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t523" class="mis show_mis"><span class="n"><a href="#t523">523</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">non_student_n_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t524" class="mis show_mis"><span class="n"><a href="#t524">524</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t525" class="mis show_mis"><span class="n"><a href="#t525">525</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t526" class="pln"><span class="n"><a href="#t526">526</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t527" class="mis show_mis"><span class="n"><a href="#t527">527</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t528" class="mis show_mis"><span class="n"><a href="#t528">528</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t529" class="mis show_mis"><span class="n"><a href="#t529">529</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t530" class="mis show_mis"><span class="n"><a href="#t530">530</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t531" class="mis show_mis"><span class="n"><a href="#t531">531</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t532" class="mis show_mis"><span class="n"><a href="#t532">532</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t533" class="pln"><span class="n"><a href="#t533">533</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t534" class="pln"><span class="n"><a href="#t534">534</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t535" class="run"><span class="n"><a href="#t535">535</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t536" class="run"><span class="n"><a href="#t536">536</a></span><span class="t"> <span class="nam">age</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t537" class="run"><span class="n"><a href="#t537">537</a></span><span class="t"> <span class="key">if</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t538" class="run"><span class="n"><a href="#t538">538</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t539" class="run"><span class="n"><a href="#t539">539</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t540" class="run"><span class="n"><a href="#t540">540</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t541" class="run"><span class="n"><a href="#t541">541</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t542" class="run"><span class="n"><a href="#t542">542</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t543" class="run"><span class="n"><a href="#t543">543</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t544" class="run"><span class="n"><a href="#t544">544</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t545" class="pln"><span class="n"><a href="#t545">545</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t546" class="run"><span class="n"><a href="#t546">546</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'student_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t547" class="run"><span class="n"><a href="#t547">547</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t548" class="run"><span class="n"><a href="#t548">548</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t549" class="run"><span class="n"><a href="#t549">549</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t550" class="run"><span class="n"><a href="#t550">550</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t551" class="run"><span class="n"><a href="#t551">551</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t552" class="run"><span class="n"><a href="#t552">552</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t553" class="run"><span class="n"><a href="#t553">553</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t554" class="pln"><span class="n"><a href="#t554">554</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t555" class="run"><span class="n"><a href="#t555">555</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'college_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t556" class="run"><span class="n"><a href="#t556">556</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t557" class="run"><span class="n"><a href="#t557">557</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t558" class="run"><span class="n"><a href="#t558">558</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t559" class="run"><span class="n"><a href="#t559">559</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t560" class="run"><span class="n"><a href="#t560">560</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t561" class="run"><span class="n"><a href="#t561">561</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t562" class="run"><span class="n"><a href="#t562">562</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t563" class="pln"><span class="n"><a href="#t563">563</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t564" class="run"><span class="n"><a href="#t564">564</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_min'</span><span class="op">]</span> <span class="key">and</span> <span class="nam">age</span> <span class="op"><</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t565" class="run"><span class="n"><a href="#t565">565</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'W'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t566" class="run"><span class="n"><a href="#t566">566</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t567" class="run"><span class="n"><a href="#t567">567</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">non_student_n_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t568" class="run"><span class="n"><a href="#t568">568</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t569" class="run"><span class="n"><a href="#t569">569</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t570" class="run"><span class="n"><a href="#t570">570</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t571" class="run"><span class="n"><a href="#t571">571</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t572" class="pln"><span class="n"><a href="#t572">572</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t573" class="run"><span class="n"><a href="#t573">573</a></span><span class="t"> <span class="key">elif</span> <span class="nam">age</span> <span class="op">>=</span> <span class="nam">activity_args</span><span class="op">[</span><span class="str">'worker_age_max'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t574" class="run"><span class="n"><a href="#t574">574</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t575" class="run"><span class="n"><a href="#t575">575</a></span><span class="t"> <span class="key">if</span> <span class="nam">network_type</span> <span class="op">==</span> <span class="str">'poisson_degree'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t576" class="run"><span class="n"><a href="#t576">576</a></span><span class="t"> <span class="nam">nc</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">pt</span><span class="op">(</span><span class="nam">n_contacts_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">/</span><span class="num">2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t577" class="run"><span class="n"><a href="#t577">577</a></span><span class="t"> <span class="nam">contact_ages</span> <span class="op">=</span> <span class="nam">spsamp</span><span class="op">.</span><span class="nam">sample_n_contact_ages_with_matrix</span><span class="op">(</span><span class="nam">nc</span><span class="op">,</span> <span class="nam">age</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">,</span> <span class="nam">age_mixing_matrix_dic</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t578" class="run"><span class="n"><a href="#t578">578</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">union</span><span class="op">(</span><span class="nam">spsamp</span><span class="op">.</span><span class="nam">get_n_contact_ids_by_age</span><span class="op">(</span><span class="nam">uids_by_age_dic</span><span class="op">,</span> <span class="nam">contact_ages</span><span class="op">,</span> <span class="nam">age_brackets</span><span class="op">,</span> <span class="nam">age_by_brackets_dic</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t579" class="run"><span class="n"><a href="#t579">579</a></span><span class="t"> <span class="key">for</span> <span class="nam">c</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t580" class="run"><span class="n"><a href="#t580">580</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">c</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t581" class="pln"><span class="n"><a href="#t581">581</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t582" class="run"><span class="n"><a href="#t582">582</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t583" class="pln"><span class="n"><a href="#t583">583</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t584" class="pln"><span class="n"><a href="#t584">584</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t585" class="run"><span class="n"><a href="#t585">585</a></span><span class="t"><span class="key">def</span> <span class="nam">rehydrate</span><span class="op">(</span><span class="nam">data</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t586" class="pln"><span class="n"><a href="#t586">586</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t587" class="pln"><span class="n"><a href="#t587">587</a></span><span class="t"><span class="str"> Populate popdict with uids, ages and contacts from generated microstructure data</span> </span><span class="r"></span></p>
<p id="t588" class="pln"><span class="n"><a href="#t588">588</a></span><span class="t"><span class="str"> that was saved to data object</span> </span><span class="r"></span></p>
<p id="t589" class="pln"><span class="n"><a href="#t589">589</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t590" class="pln"><span class="n"><a href="#t590">590</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t591" class="pln"><span class="n"><a href="#t591">591</a></span><span class="t"><span class="str"> data (pop object)</span> </span><span class="r"></span></p>
<p id="t592" class="pln"><span class="n"><a href="#t592">592</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t593" class="pln"><span class="n"><a href="#t593">593</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t594" class="pln"><span class="n"><a href="#t594">594</a></span><span class="t"><span class="str"> Popdict (sc.objdict)</span> </span><span class="r"></span></p>
<p id="t595" class="pln"><span class="n"><a href="#t595">595</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t596" class="mis show_mis"><span class="n"><a href="#t596">596</a></span><span class="t"> <span class="nam">popdict</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">dcp</span><span class="op">(</span><span class="nam">data</span><span class="op">[</span><span class="str">'popdict'</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t597" class="mis show_mis"><span class="n"><a href="#t597">597</a></span><span class="t"> <span class="nam">mapping</span> <span class="op">=</span> <span class="op">{</span><span class="str">'H'</span><span class="op">:</span> <span class="str">'households'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">:</span> <span class="str">'schools'</span><span class="op">,</span> <span class="str">'W'</span><span class="op">:</span> <span class="str">'workplaces'</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t598" class="mis show_mis"><span class="n"><a href="#t598">598</a></span><span class="t"> <span class="key">for</span> <span class="nam">key</span><span class="op">,</span> <span class="nam">label</span> <span class="key">in</span> <span class="nam">mapping</span><span class="op">.</span><span class="nam">items</span><span class="op">(</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t599" class="mis show_mis"><span class="n"><a href="#t599">599</a></span><span class="t"> <span class="key">for</span> <span class="nam">r</span> <span class="key">in</span> <span class="nam">data</span><span class="op">[</span><span class="nam">label</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t600" class="mis show_mis"><span class="n"><a href="#t600">600</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">r</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t601" class="mis show_mis"><span class="n"><a href="#t601">601</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">key</span><span class="op">]</span> <span class="op">=</span> <span class="nam">set</span><span class="op">(</span><span class="nam">r</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t602" class="mis show_mis"><span class="n"><a href="#t602">602</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">key</span><span class="op">]</span><span class="op">.</span><span class="nam">remove</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t603" class="pln"><span class="n"><a href="#t603">603</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t604" class="mis show_mis"><span class="n"><a href="#t604">604</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t605" class="pln"><span class="n"><a href="#t605">605</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t606" class="pln"><span class="n"><a href="#t606">606</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t607" class="run"><span class="n"><a href="#t607">607</a></span><span class="t"><span class="key">def</span> <span class="nam">save_synthpop</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">contacts</span><span class="op">,</span> <span class="nam">location</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t608" class="pln"><span class="n"><a href="#t608">608</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t609" class="pln"><span class="n"><a href="#t609">609</a></span><span class="t"><span class="str"> Save pop data object to file.</span> </span><span class="r"></span></p>
<p id="t610" class="pln"><span class="n"><a href="#t610">610</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t611" class="pln"><span class="n"><a href="#t611">611</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t612" class="pln"><span class="n"><a href="#t612">612</a></span><span class="t"><span class="str"> datadir (string) : file path to the data directory</span> </span><span class="r"></span></p>
<p id="t613" class="pln"><span class="n"><a href="#t613">613</a></span><span class="t"><span class="str"> contacts (dict) : dictionary of people with contacts</span> </span><span class="r"></span></p>
<p id="t614" class="pln"><span class="n"><a href="#t614">614</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t615" class="pln"><span class="n"><a href="#t615">615</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t616" class="pln"><span class="n"><a href="#t616">616</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t617" class="pln"><span class="n"><a href="#t617">617</a></span><span class="t"><span class="str"> None</span> </span><span class="r"></span></p>
<p id="t618" class="pln"><span class="n"><a href="#t618">618</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t619" class="pln"><span class="n"><a href="#t619">619</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t620" class="mis show_mis"><span class="n"><a href="#t620">620</a></span><span class="t"> <span class="nam">filename</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_synthpop_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">len</span><span class="op">(</span><span class="nam">contacts</span><span class="op">)</span><span class="op">)</span> <span class="op">+</span> <span class="str">'.pop'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t621" class="mis show_mis"><span class="n"><a href="#t621">621</a></span><span class="t"> <span class="nam">sc</span><span class="op">.</span><span class="nam">saveobj</span><span class="op">(</span><span class="nam">filename</span><span class="op">=</span><span class="nam">filename</span><span class="op">,</span> <span class="nam">obj</span><span class="op">=</span><span class="nam">contacts</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t622" class="pln"><span class="n"><a href="#t622">622</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t623" class="pln"><span class="n"><a href="#t623">623</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t624" class="run"><span class="n"><a href="#t624">624</a></span><span class="t"><span class="key">def</span> <span class="nam">create_reduced_contacts_with_group_types</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">group_1</span><span class="op">,</span> <span class="nam">group_2</span><span class="op">,</span> <span class="nam">setting</span><span class="op">,</span> <span class="nam">average_degree</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">p_matrix</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">force_cross_edges</span><span class="op">=</span><span class="key">True</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t625" class="pln"><span class="n"><a href="#t625">625</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t626" class="pln"><span class="n"><a href="#t626">626</a></span><span class="t"><span class="str"> Create contacts between members of group 1 and group 2, fixing the average degree, and the</span> </span><span class="r"></span></p>
<p id="t627" class="pln"><span class="n"><a href="#t627">627</a></span><span class="t"><span class="str"> probability of an edge between any two groups controlled by p_matrix if provided.</span> </span><span class="r"></span></p>
<p id="t628" class="pln"><span class="n"><a href="#t628">628</a></span><span class="t"><span class="str"> Forces inter group edge for each individual in group 1 with force_cross_groups equal to True.</span> </span><span class="r"></span></p>
<p id="t629" class="pln"><span class="n"><a href="#t629">629</a></span><span class="t"><span class="str"> This means not everyone in group 2 will have a contact with group 1.</span> </span><span class="r"></span></p>
<p id="t630" class="pln"><span class="n"><a href="#t630">630</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t631" class="pln"><span class="n"><a href="#t631">631</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t632" class="pln"><span class="n"><a href="#t632">632</a></span><span class="t"><span class="str"> group_1 (list) : list of ids for group 1</span> </span><span class="r"></span></p>
<p id="t633" class="pln"><span class="n"><a href="#t633">633</a></span><span class="t"><span class="str"> group_2 (list) : list of ids for group 2</span> </span><span class="r"></span></p>
<p id="t634" class="pln"><span class="n"><a href="#t634">634</a></span><span class="t"><span class="str"> average_degree (int) : average degree across group 1 and 2</span> </span><span class="r"></span></p>
<p id="t635" class="pln"><span class="n"><a href="#t635">635</a></span><span class="t"><span class="str"> p_matrix (np.ndarray) : probability matrix for edges between any two groups</span> </span><span class="r"></span></p>
<p id="t636" class="pln"><span class="n"><a href="#t636">636</a></span><span class="t"><span class="str"> force_cross_groups (bool) : If True, force each individual to have at least one contact with a member from the other group</span> </span><span class="r"></span></p>
<p id="t637" class="pln"><span class="n"><a href="#t637">637</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t638" class="pln"><span class="n"><a href="#t638">638</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t639" class="pln"><span class="n"><a href="#t639">639</a></span><span class="t"><span class="str"> Popdict with edges added for nodes in the two groups.</span> </span><span class="r"></span></p>
<p id="t640" class="pln"><span class="n"><a href="#t640">640</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t641" class="pln"><span class="n"><a href="#t641">641</a></span><span class="t"><span class="str"> Notes:</span> </span><span class="r"></span></p>
<p id="t642" class="pln"><span class="n"><a href="#t642">642</a></span><span class="t"><span class="str"> This method uses the Stochastic Block Model algorithm to generate contacts both between nodes in different groups</span> </span><span class="r"></span></p>
<p id="t643" class="pln"><span class="n"><a href="#t643">643</a></span><span class="t"><span class="str"> and for nodes within the same group. In the current version, fixing the average degree and p_matrix, the matrix of probabilities</span> </span><span class="r"></span></p>
<p id="t644" class="pln"><span class="n"><a href="#t644">644</a></span><span class="t"><span class="str"> for edges between any two groups is not supported. Future versions may add support for this.</span> </span><span class="r"></span></p>
<p id="t645" class="pln"><span class="n"><a href="#t645">645</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t646" class="pln"><span class="n"><a href="#t646">646</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t647" class="run"><span class="n"><a href="#t647">647</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_1</span><span class="op">)</span> <span class="op">==</span> <span class="num">0</span> <span class="key">or</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_2</span><span class="op">)</span> <span class="op">==</span> <span class="num">0</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t648" class="mis show_mis"><span class="n"><a href="#t648">648</a></span><span class="t"> <span class="nam">errormsg</span> <span class="op">=</span> <span class="str">f'This method requires that both groups are populated. If one of the two groups has size 0, then consider using the synthpops.trim_contacts() method, or checking that the groups provided to this method are correct.'</span> </span><span class="r"></span></p>
<p id="t649" class="mis show_mis"><span class="n"><a href="#t649">649</a></span><span class="t"> <span class="key">raise</span> <span class="nam">ValueError</span><span class="op">(</span><span class="nam">errormsg</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t650" class="pln"><span class="n"><a href="#t650">650</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t651" class="run"><span class="n"><a href="#t651">651</a></span><span class="t"> <span class="key">if</span> <span class="nam">average_degree</span> <span class="op"><</span> <span class="num">2</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t652" class="mis show_mis"><span class="n"><a href="#t652">652</a></span><span class="t"> <span class="nam">errormsg</span> <span class="op">=</span> <span class="str">f'This method is likely to create disconnected graphs with average_degree < 2. In order to keep the group connected, use a higher average_degree for nodes across the two groups.'</span> </span><span class="r"></span></p>
<p id="t653" class="mis show_mis"><span class="n"><a href="#t653">653</a></span><span class="t"> <span class="key">raise</span> <span class="nam">ValueError</span><span class="op">(</span><span class="nam">errormsg</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t654" class="pln"><span class="n"><a href="#t654">654</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t655" class="run"><span class="n"><a href="#t655">655</a></span><span class="t"> <span class="nam">r1</span> <span class="op">=</span> <span class="op">[</span><span class="nam">int</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">group_1</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t656" class="run"><span class="n"><a href="#t656">656</a></span><span class="t"> <span class="nam">r2</span> <span class="op">=</span> <span class="op">[</span><span class="nam">int</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">group_2</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t657" class="pln"><span class="n"><a href="#t657">657</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t658" class="run"><span class="n"><a href="#t658">658</a></span><span class="t"> <span class="nam">n1</span> <span class="op">=</span> <span class="nam">list</span><span class="op">(</span><span class="nam">np</span><span class="op">.</span><span class="nam">arange</span><span class="op">(</span><span class="nam">len</span><span class="op">(</span><span class="nam">r1</span><span class="op">)</span><span class="op">)</span><span class="op">.</span><span class="nam">astype</span><span class="op">(</span><span class="nam">int</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t659" class="run"><span class="n"><a href="#t659">659</a></span><span class="t"> <span class="nam">n2</span> <span class="op">=</span> <span class="nam">list</span><span class="op">(</span><span class="nam">np</span><span class="op">.</span><span class="nam">arange</span><span class="op">(</span><span class="nam">len</span><span class="op">(</span><span class="nam">r1</span><span class="op">)</span><span class="op">,</span> <span class="nam">len</span><span class="op">(</span><span class="nam">r1</span><span class="op">)</span><span class="op">+</span><span class="nam">len</span><span class="op">(</span><span class="nam">r2</span><span class="op">)</span><span class="op">)</span><span class="op">.</span><span class="nam">astype</span><span class="op">(</span><span class="nam">int</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t660" class="pln"><span class="n"><a href="#t660">660</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t661" class="run"><span class="n"><a href="#t661">661</a></span><span class="t"> <span class="nam">group</span> <span class="op">=</span> <span class="nam">r1</span> <span class="op">+</span> <span class="nam">r2</span> </span><span class="r"></span></p>
<p id="t662" class="run"><span class="n"><a href="#t662">662</a></span><span class="t"> <span class="nam">sizes</span> <span class="op">=</span> <span class="op">[</span><span class="nam">len</span><span class="op">(</span><span class="nam">r1</span><span class="op">)</span><span class="op">,</span> <span class="nam">len</span><span class="op">(</span><span class="nam">r2</span><span class="op">)</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t663" class="pln"><span class="n"><a href="#t663">663</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t664" class="run"><span class="n"><a href="#t664">664</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">popdict</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t665" class="run"><span class="n"><a href="#t665">665</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">.</span><span class="nam">setdefault</span><span class="op">(</span><span class="nam">setting</span><span class="op">,</span> <span class="nam">set</span><span class="op">(</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t666" class="pln"><span class="n"><a href="#t666">666</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t667" class="pln"><span class="n"><a href="#t667">667</a></span><span class="t"> <span class="com"># group is less than the average degree, so return a fully connected graph instead</span> </span><span class="r"></span></p>
<p id="t668" class="run"><span class="n"><a href="#t668">668</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group</span><span class="op">)</span> <span class="op"><=</span> <span class="nam">average_degree</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t669" class="run"><span class="n"><a href="#t669">669</a></span><span class="t"> <span class="nam">G</span> <span class="op">=</span> <span class="nam">nx</span><span class="op">.</span><span class="nam">complete_graph</span><span class="op">(</span><span class="nam">len</span><span class="op">(</span><span class="nam">group</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t670" class="pln"><span class="n"><a href="#t670">670</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t671" class="pln"><span class="n"><a href="#t671">671</a></span><span class="t"> <span class="com"># group 2 is less than 2 people so everyone in group 1 must be connected to that lone group 2 individual, create a fully connected graph then remove some edges at random to preserve the degree distribution</span> </span><span class="r"></span></p>
<p id="t672" class="run"><span class="n"><a href="#t672">672</a></span><span class="t"> <span class="key">elif</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_2</span><span class="op">)</span> <span class="op"><</span> <span class="num">2</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t673" class="mis show_mis"><span class="n"><a href="#t673">673</a></span><span class="t"> <span class="nam">G</span> <span class="op">=</span> <span class="nam">nx</span><span class="op">.</span><span class="nam">complete_graph</span><span class="op">(</span><span class="nam">len</span><span class="op">(</span><span class="nam">group</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t674" class="mis show_mis"><span class="n"><a href="#t674">674</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">n1</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t675" class="mis show_mis"><span class="n"><a href="#t675">675</a></span><span class="t"> <span class="nam">group_1_neighbors</span> <span class="op">=</span> <span class="op">[</span><span class="nam">j</span> <span class="key">for</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">G</span><span class="op">.</span><span class="nam">neighbors</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">if</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">n1</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t676" class="pln"><span class="n"><a href="#t676">676</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t677" class="pln"><span class="n"><a href="#t677">677</a></span><span class="t"> <span class="com"># if the person's degree is too high, cut out some contacts</span> </span><span class="r"></span></p>
<p id="t678" class="mis show_mis"><span class="n"><a href="#t678">678</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_1_neighbors</span><span class="op">)</span> <span class="op">></span> <span class="nam">average_degree</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t679" class="mis show_mis"><span class="n"><a href="#t679">679</a></span><span class="t"> <span class="nam">ncut</span> <span class="op">=</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_1_neighbors</span><span class="op">)</span> <span class="op">-</span> <span class="nam">average_degree</span> <span class="com"># rough number to cut</span> </span><span class="r"></span></p>
<p id="t680" class="pln"><span class="n"><a href="#t680">680</a></span><span class="t"> <span class="com"># ncut = spsamp.pt(ncut) # sample from poisson that number</span> </span><span class="r"></span></p>
<p id="t681" class="pln"><span class="n"><a href="#t681">681</a></span><span class="t"> <span class="com"># ncut = min(len(group_1_neighbors), ncut) # make sure the number isn't greater than the people available to cut</span> </span><span class="r"></span></p>
<p id="t682" class="mis show_mis"><span class="n"><a href="#t682">682</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="nam">ncut</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t683" class="mis show_mis"><span class="n"><a href="#t683">683</a></span><span class="t"> <span class="nam">j</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">choice</span><span class="op">(</span><span class="nam">group_1_neighbors</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t684" class="mis show_mis"><span class="n"><a href="#t684">684</a></span><span class="t"> <span class="nam">G</span><span class="op">.</span><span class="nam">remove_edge</span><span class="op">(</span><span class="nam">i</span><span class="op">,</span> <span class="nam">j</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t685" class="mis show_mis"><span class="n"><a href="#t685">685</a></span><span class="t"> <span class="nam">group_1_neighbors</span><span class="op">.</span><span class="nam">remove</span><span class="op">(</span><span class="nam">j</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t686" class="pln"><span class="n"><a href="#t686">686</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t687" class="pln"><span class="n"><a href="#t687">687</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t688" class="run"><span class="n"><a href="#t688">688</a></span><span class="t"> <span class="nam">share_k_matrix</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">ones</span><span class="op">(</span><span class="op">(</span><span class="num">2</span><span class="op">,</span> <span class="num">2</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t689" class="run"><span class="n"><a href="#t689">689</a></span><span class="t"> <span class="nam">share_k_matrix</span> <span class="op">*=</span> <span class="nam">average_degree</span><span class="op">/</span><span class="nam">np</span><span class="op">.</span><span class="nam">sum</span><span class="op">(</span><span class="nam">sizes</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t690" class="pln"><span class="n"><a href="#t690">690</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t691" class="run"><span class="n"><a href="#t691">691</a></span><span class="t"> <span class="key">if</span> <span class="nam">p_matrix</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t692" class="run"><span class="n"><a href="#t692">692</a></span><span class="t"> <span class="nam">p_matrix</span> <span class="op">=</span> <span class="nam">share_k_matrix</span><span class="op">.</span><span class="nam">copy</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t693" class="pln"><span class="n"><a href="#t693">693</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t694" class="pln"><span class="n"><a href="#t694">694</a></span><span class="t"> <span class="com"># create a graph with edges within each groups and between members of different groups using the probability matrix</span> </span><span class="r"></span></p>
<p id="t695" class="run"><span class="n"><a href="#t695">695</a></span><span class="t"> <span class="nam">G</span> <span class="op">=</span> <span class="nam">nx</span><span class="op">.</span><span class="nam">stochastic_block_model</span><span class="op">(</span><span class="nam">sizes</span><span class="op">,</span> <span class="nam">p_matrix</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t696" class="pln"><span class="n"><a href="#t696">696</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t697" class="pln"><span class="n"><a href="#t697">697</a></span><span class="t"> <span class="com"># how many people in group 2 have connections they could cut to preserve the degree distribution</span> </span><span class="r"></span></p>
<p id="t698" class="run"><span class="n"><a href="#t698">698</a></span><span class="t"> <span class="nam">group_2_to_group_2_connections</span> <span class="op">=</span> <span class="op">[</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t699" class="run"><span class="n"><a href="#t699">699</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">n2</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t700" class="run"><span class="n"><a href="#t700">700</a></span><span class="t"> <span class="nam">group_2_neighbors</span> <span class="op">=</span> <span class="op">[</span><span class="nam">j</span> <span class="key">for</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">G</span><span class="op">.</span><span class="nam">neighbors</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">if</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">n2</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t701" class="run"><span class="n"><a href="#t701">701</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_2_neighbors</span><span class="op">)</span> <span class="op">></span> <span class="num">0</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t702" class="run"><span class="n"><a href="#t702">702</a></span><span class="t"> <span class="nam">group_2_to_group_2_connections</span><span class="op">.</span><span class="nam">append</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t703" class="pln"><span class="n"><a href="#t703">703</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t704" class="pln"><span class="n"><a href="#t704">704</a></span><span class="t"> <span class="com"># there are no people in group 2 who can remove edges to other group 2 people, so instead, just add edges</span> </span><span class="r"></span></p>
<p id="t705" class="run"><span class="n"><a href="#t705">705</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_2_to_group_2_connections</span><span class="op">)</span> <span class="op">==</span> <span class="num">0</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t706" class="run"><span class="n"><a href="#t706">706</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">n1</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t707" class="run"><span class="n"><a href="#t707">707</a></span><span class="t"> <span class="nam">group_2_neighbors</span> <span class="op">=</span> <span class="op">[</span><span class="nam">j</span> <span class="key">for</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">G</span><span class="op">.</span><span class="nam">neighbors</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">if</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">n2</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t708" class="pln"><span class="n"><a href="#t708">708</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t709" class="pln"><span class="n"><a href="#t709">709</a></span><span class="t"> <span class="com"># need to add a contact in group 2</span> </span><span class="r"></span></p>
<p id="t710" class="run"><span class="n"><a href="#t710">710</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_2_neighbors</span><span class="op">)</span> <span class="op">==</span> <span class="num">0</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t711" class="pln"><span class="n"><a href="#t711">711</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t712" class="run"><span class="n"><a href="#t712">712</a></span><span class="t"> <span class="nam">random_group_2_j</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">choice</span><span class="op">(</span><span class="nam">n2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t713" class="run"><span class="n"><a href="#t713">713</a></span><span class="t"> <span class="nam">G</span><span class="op">.</span><span class="nam">add_edge</span><span class="op">(</span><span class="nam">i</span><span class="op">,</span> <span class="nam">random_group_2_j</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t714" class="pln"><span class="n"><a href="#t714">714</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t715" class="pln"><span class="n"><a href="#t715">715</a></span><span class="t"> <span class="com"># some in group 2 have contacts to remove to preserve the degree distribution</span> </span><span class="r"></span></p>
<p id="t716" class="pln"><span class="n"><a href="#t716">716</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t717" class="run"><span class="n"><a href="#t717">717</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">n1</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t718" class="run"><span class="n"><a href="#t718">718</a></span><span class="t"> <span class="nam">group_2_neighbors</span> <span class="op">=</span> <span class="op">[</span><span class="nam">j</span> <span class="key">for</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">G</span><span class="op">.</span><span class="nam">neighbors</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">if</span> <span class="nam">j</span> <span class="key">in</span> <span class="nam">n2</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t719" class="pln"><span class="n"><a href="#t719">719</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t720" class="pln"><span class="n"><a href="#t720">720</a></span><span class="t"> <span class="com"># increase the degree of the node in group 1, while decreasing the degree of a member of group 2 at random</span> </span><span class="r"></span></p>
<p id="t721" class="run"><span class="n"><a href="#t721">721</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">group_2_neighbors</span><span class="op">)</span> <span class="op">==</span> <span class="num">0</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t722" class="pln"><span class="n"><a href="#t722">722</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t723" class="run"><span class="n"><a href="#t723">723</a></span><span class="t"> <span class="nam">random_group_2_j</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">choice</span><span class="op">(</span><span class="nam">n2</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t724" class="run"><span class="n"><a href="#t724">724</a></span><span class="t"> <span class="nam">random_group_2_neighbors</span> <span class="op">=</span> <span class="op">[</span><span class="nam">ii</span> <span class="key">for</span> <span class="nam">ii</span> <span class="key">in</span> <span class="nam">G</span><span class="op">.</span><span class="nam">neighbors</span><span class="op">(</span><span class="nam">random_group_2_j</span><span class="op">)</span> <span class="key">if</span> <span class="nam">ii</span> <span class="key">in</span> <span class="nam">n2</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t725" class="pln"><span class="n"><a href="#t725">725</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t726" class="pln"><span class="n"><a href="#t726">726</a></span><span class="t"> <span class="com"># add an edge to random_group_2_j</span> </span><span class="r"></span></p>
<p id="t727" class="run"><span class="n"><a href="#t727">727</a></span><span class="t"> <span class="nam">G</span><span class="op">.</span><span class="nam">add_edge</span><span class="op">(</span><span class="nam">i</span><span class="op">,</span> <span class="nam">random_group_2_j</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t728" class="pln"><span class="n"><a href="#t728">728</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t729" class="pln"><span class="n"><a href="#t729">729</a></span><span class="t"> <span class="com"># if the group 2 person has an edge they can cut to their own group, remove it</span> </span><span class="r"></span></p>
<p id="t730" class="run"><span class="n"><a href="#t730">730</a></span><span class="t"> <span class="key">if</span> <span class="nam">len</span><span class="op">(</span><span class="nam">random_group_2_neighbors</span><span class="op">)</span> <span class="op">></span> <span class="num">0</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t731" class="run"><span class="n"><a href="#t731">731</a></span><span class="t"> <span class="nam">random_group_2_neighbor_cut</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">choice</span><span class="op">(</span><span class="nam">random_group_2_neighbors</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t732" class="run"><span class="n"><a href="#t732">732</a></span><span class="t"> <span class="nam">G</span><span class="op">.</span><span class="nam">remove_edge</span><span class="op">(</span><span class="nam">random_group_2_j</span><span class="op">,</span> <span class="nam">random_group_2_neighbor_cut</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t733" class="pln"><span class="n"><a href="#t733">733</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t734" class="run"><span class="n"><a href="#t734">734</a></span><span class="t"> <span class="nam">E</span> <span class="op">=</span> <span class="nam">G</span><span class="op">.</span><span class="nam">edges</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t735" class="run"><span class="n"><a href="#t735">735</a></span><span class="t"> <span class="key">for</span> <span class="nam">e</span> <span class="key">in</span> <span class="nam">E</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t736" class="run"><span class="n"><a href="#t736">736</a></span><span class="t"> <span class="nam">i</span><span class="op">,</span> <span class="nam">j</span> <span class="op">=</span> <span class="nam">e</span> </span><span class="r"></span></p>
<p id="t737" class="pln"><span class="n"><a href="#t737">737</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t738" class="run"><span class="n"><a href="#t738">738</a></span><span class="t"> <span class="nam">id_i</span> <span class="op">=</span> <span class="nam">group</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t739" class="run"><span class="n"><a href="#t739">739</a></span><span class="t"> <span class="nam">id_j</span> <span class="op">=</span> <span class="nam">group</span><span class="op">[</span><span class="nam">j</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t740" class="pln"><span class="n"><a href="#t740">740</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t741" class="run"><span class="n"><a href="#t741">741</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">id_i</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">setting</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">id_j</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t742" class="run"><span class="n"><a href="#t742">742</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">id_j</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">setting</span><span class="op">]</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">id_i</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t743" class="pln"><span class="n"><a href="#t743">743</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t744" class="run"><span class="n"><a href="#t744">744</a></span><span class="t"> <span class="key">return</span> <span class="nam">popdict</span> </span><span class="r"></span></p>
<p id="t745" class="pln"><span class="n"><a href="#t745">745</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t746" class="pln"><span class="n"><a href="#t746">746</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t747" class="run"><span class="n"><a href="#t747">747</a></span><span class="t"><span class="key">def</span> <span class="nam">make_contacts_from_microstructure</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">,</span> <span class="nam">n</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t748" class="pln"><span class="n"><a href="#t748">748</a></span><span class="t"> <span class="nam">with_non_teaching_staff</span><span class="op">=</span><span class="key">True</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t749" class="pln"><span class="n"><a href="#t749">749</a></span><span class="t"> <span class="nam">with_school_types</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> <span class="nam">school_mixing_type</span><span class="op">=</span><span class="str">'random'</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t750" class="pln"><span class="n"><a href="#t750">750</a></span><span class="t"> <span class="nam">average_class_size</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">inter_grade_mixing</span><span class="op">=</span><span class="num">0.1</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t751" class="pln"><span class="n"><a href="#t751">751</a></span><span class="t"> <span class="nam">average_student_teacher_ratio</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">average_teacher_teacher_degree</span><span class="op">=</span><span class="num">3</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t752" class="pln"><span class="n"><a href="#t752">752</a></span><span class="t"> <span class="nam">average_student_all_staff_ratio</span><span class="op">=</span><span class="num">15</span><span class="op">,</span> <span class="nam">average_additional_staff_degree</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t753" class="pln"><span class="n"><a href="#t753">753</a></span><span class="t"> <span class="nam">school_type_by_age</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">with_industry_code</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> <span class="nam">verbose</span><span class="op">=</span><span class="key">False</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t754" class="pln"><span class="n"><a href="#t754">754</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t755" class="pln"><span class="n"><a href="#t755">755</a></span><span class="t"><span class="str"> Make a popdict from synthetic household, school, and workplace files with uids. If with_industry_code is True, then individuals</span> </span><span class="r"></span></p>
<p id="t756" class="pln"><span class="n"><a href="#t756">756</a></span><span class="t"><span class="str"> will have a workplace industry code as well (default value is -1 to represent that this data is unavailable). Currently, industry</span> </span><span class="r"></span></p>
<p id="t757" class="pln"><span class="n"><a href="#t757">757</a></span><span class="t"><span class="str"> codes are only available to assign to populations within the US.</span> </span><span class="r"></span></p>
<p id="t758" class="pln"><span class="n"><a href="#t758">758</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t759" class="pln"><span class="n"><a href="#t759">759</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t760" class="pln"><span class="n"><a href="#t760">760</a></span><span class="t"><span class="str"> datadir (string) : The file path to the data directory</span> </span><span class="r"></span></p>
<p id="t761" class="pln"><span class="n"><a href="#t761">761</a></span><span class="t"><span class="str"> location (string) : The name of the location</span> </span><span class="r"></span></p>
<p id="t762" class="pln"><span class="n"><a href="#t762">762</a></span><span class="t"><span class="str"> state_location (string) : The name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t763" class="pln"><span class="n"><a href="#t763">763</a></span><span class="t"><span class="str"> country_location (string) : The name of the country the location is in</span> </span><span class="r"></span></p>
<p id="t764" class="pln"><span class="n"><a href="#t764">764</a></span><span class="t"><span class="str"> n (int) : The number of people in the population</span> </span><span class="r"></span></p>
<p id="t765" class="pln"><span class="n"><a href="#t765">765</a></span><span class="t"><span class="str"> with_non_teaching_staff (bool) : If True, includes non teaching staff.</span> </span><span class="r"></span></p>
<p id="t766" class="pln"><span class="n"><a href="#t766">766</a></span><span class="t"><span class="str"> with_school_types (bool) : If True, creates explicit school types.</span> </span><span class="r"></span></p>
<p id="t767" class="pln"><span class="n"><a href="#t767">767</a></span><span class="t"><span class="str"> school_mixing_type (str or dict) : The mixing type for schools, 'random', 'age_clustered', or 'age_and_class_clustered' if string, and a dictionary of these by school type otherwise. 'random' means random graphs for each school, 'age_clustered' means random graphs but with students mostly mixing within the age/grade (inter_grade_mixing controls mixing between grades), 'age_and_grade_clustered' means students cohorted into classes with their own teachers.</span> </span><span class="r"></span></p>
<p id="t768" class="pln"><span class="n"><a href="#t768">768</a></span><span class="t"><span class="str"> average_class_size (float) : The average classroom size.</span> </span><span class="r"></span></p>
<p id="t769" class="pln"><span class="n"><a href="#t769">769</a></span><span class="t"><span class="str"> inter_grade_mixing (float) : The average fraction of mixing between grades in the same school for clustered school mixing types.</span> </span><span class="r"></span></p>
<p id="t770" class="pln"><span class="n"><a href="#t770">770</a></span><span class="t"><span class="str"> average_student_teacher_ratio (float) : The average number of students per teacher.</span> </span><span class="r"></span></p>
<p id="t771" class="pln"><span class="n"><a href="#t771">771</a></span><span class="t"><span class="str"> average_teacher_teacher_degree (float) : The average number of contacts per teacher with other teachers.</span> </span><span class="r"></span></p>
<p id="t772" class="pln"><span class="n"><a href="#t772">772</a></span><span class="t"><span class="str"> average_student_all_staff_ratio (float) : The average number of students per staff members at school (including both teachers and non teachers).</span> </span><span class="r"></span></p>
<p id="t773" class="pln"><span class="n"><a href="#t773">773</a></span><span class="t"><span class="str"> average_additional_staff_degree (float) : The average number of contacts per additional non teaching staff in schools.</span> </span><span class="r"></span></p>
<p id="t774" class="pln"><span class="n"><a href="#t774">774</a></span><span class="t"><span class="str"> with_industry_code (bool) : If True, assign workplace industry code read in from cached file</span> </span><span class="r"></span></p>
<p id="t775" class="pln"><span class="n"><a href="#t775">775</a></span><span class="t"><span class="str"> verbose (bool) : If True, print debugging statements.</span> </span><span class="r"></span></p>
<p id="t776" class="pln"><span class="n"><a href="#t776">776</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t777" class="pln"><span class="n"><a href="#t777">777</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t778" class="pln"><span class="n"><a href="#t778">778</a></span><span class="t"><span class="str"> A popdict of people with attributes. Dictionary keys are the IDs of individuals in the population and the values are a dictionary</span> </span><span class="r"></span></p>
<p id="t779" class="pln"><span class="n"><a href="#t779">779</a></span><span class="t"><span class="str"> for each individual with their attributes, such as age, household ID (hhid), school ID (scid), workplace ID (wpid), workplace</span> </span><span class="r"></span></p>
<p id="t780" class="pln"><span class="n"><a href="#t780">780</a></span><span class="t"><span class="str"> industry code (wpindcode) if available, and the IDs of their contacts in different layers. Different layers available are</span> </span><span class="r"></span></p>
<p id="t781" class="pln"><span class="n"><a href="#t781">781</a></span><span class="t"><span class="str"> households ('H'), schools ('S'), and workplaces ('W'). Contacts in these layers are clustered and thus form a network composed of</span> </span><span class="r"></span></p>
<p id="t782" class="pln"><span class="n"><a href="#t782">782</a></span><span class="t"><span class="str"> groups of people interacting with each other. For example, all household members are contacts of each other, and everyone in the</span> </span><span class="r"></span></p>
<p id="t783" class="pln"><span class="n"><a href="#t783">783</a></span><span class="t"><span class="str"> same school is considered a contact of each other.</span> </span><span class="r"></span></p>
<p id="t784" class="pln"><span class="n"><a href="#t784">784</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t785" class="pln"><span class="n"><a href="#t785">785</a></span><span class="t"><span class="str"> Notes:</span> </span><span class="r"></span></p>
<p id="t786" class="pln"><span class="n"><a href="#t786">786</a></span><span class="t"><span class="str"> Methods to trim large groups of contacts down to better approximate a sense of close contacts (such as classroom sizes or</span> </span><span class="r"></span></p>
<p id="t787" class="pln"><span class="n"><a href="#t787">787</a></span><span class="t"><span class="str"> smaller work groups are available via sp.trim_contacts() - see below).</span> </span><span class="r"></span></p>
<p id="t788" class="pln"><span class="n"><a href="#t788">788</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t789" class="run"><span class="n"><a href="#t789">789</a></span><span class="t"> <span class="nam">log</span><span class="op">.</span><span class="nam">debug</span><span class="op">(</span><span class="str">'make_contacts_from_microstructure()'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t790" class="run"><span class="n"><a href="#t790">790</a></span><span class="t"> <span class="nam">folder_name</span> <span class="op">=</span> <span class="str">'contact_networks'</span> </span><span class="r"></span></p>
<p id="t791" class="run"><span class="n"><a href="#t791">791</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="str">'demographics'</span><span class="op">,</span> <span class="str">'contact_matrices_152_countries'</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t792" class="pln"><span class="n"><a href="#t792">792</a></span><span class="t"> <span class="nam">state_location</span><span class="op">,</span> <span class="nam">folder_name</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t793" class="pln"><span class="n"><a href="#t793">793</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t794" class="run"><span class="n"><a href="#t794">794</a></span><span class="t"> <span class="nam">households_by_uid_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> <span class="op">+</span> <span class="str">'_synthetic_households_with_uids.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t795" class="pln"><span class="n"><a href="#t795">795</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t796" class="run"><span class="n"><a href="#t796">796</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_industry_code</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t797" class="mis show_mis"><span class="n"><a href="#t797">797</a></span><span class="t"> <span class="nam">workplaces_by_uid_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> <span class="op">+</span> <span class="str">'_synthetic_workplaces_by_industry_with_uids.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t798" class="mis show_mis"><span class="n"><a href="#t798">798</a></span><span class="t"> <span class="nam">workplaces_by_industry_code_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> <span class="op">+</span> <span class="str">'_synthetic_workplaces_by_industry_codes.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t799" class="pln"><span class="n"><a href="#t799">799</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t800" class="run"><span class="n"><a href="#t800">800</a></span><span class="t"> <span class="nam">workplaces_by_uid_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> <span class="op">+</span> <span class="str">'_synthetic_workplaces_with_uids.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t801" class="pln"><span class="n"><a href="#t801">801</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t802" class="run"><span class="n"><a href="#t802">802</a></span><span class="t"> <span class="nam">schools_by_uid_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> <span class="op">+</span> <span class="str">'_synthetic_schools_with_uids.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t803" class="run"><span class="n"><a href="#t803">803</a></span><span class="t"> <span class="nam">teachers_by_uid_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> <span class="op">+</span> <span class="str">'_synthetic_teachers_with_uids.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t804" class="pln"><span class="n"><a href="#t804">804</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t805" class="run"><span class="n"><a href="#t805">805</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_non_teaching_staff</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t806" class="run"><span class="n"><a href="#t806">806</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t807" class="run"><span class="n"><a href="#t807">807</a></span><span class="t"> <span class="nam">non_teaching_staff_by_uid_path</span> <span class="op">=</span> <span class="nam">os</span><span class="op">.</span><span class="nam">path</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_'</span> <span class="op">+</span> <span class="nam">str</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> <span class="op">+</span> <span class="str">'_synthetic_non_teaching_staff_with_uids.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t808" class="run"><span class="n"><a href="#t808">808</a></span><span class="t"> <span class="nam">fnt</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">non_teaching_staff_by_uid_path</span><span class="op">,</span> <span class="str">'r'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t809" class="run"><span class="n"><a href="#t809">809</a></span><span class="t"> <span class="nam">fnt</span><span class="op">.</span><span class="nam">close</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t810" class="mis show_mis"><span class="n"><a href="#t810">810</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t811" class="mis show_mis"><span class="n"><a href="#t811">811</a></span><span class="t"> <span class="nam">errormsg</span> <span class="op">=</span> <span class="str">f'Non teaching staff do not exist and so will not be created.'</span> </span><span class="r"></span></p>
<p id="t812" class="mis show_mis"><span class="n"><a href="#t812">812</a></span><span class="t"> <span class="nam">print</span><span class="op">(</span><span class="nam">errormsg</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t813" class="mis show_mis"><span class="n"><a href="#t813">813</a></span><span class="t"> <span class="nam">with_non_teaching_staff</span> <span class="op">=</span> <span class="key">False</span> </span><span class="r"></span></p>
<p id="t814" class="pln"><span class="n"><a href="#t814">814</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t815" class="run"><span class="n"><a href="#t815">815</a></span><span class="t"> <span class="nam">age_by_uid_dic</span> <span class="op">=</span> <span class="nam">sprw</span><span class="op">.</span><span class="nam">read_in_age_by_uid</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">,</span> <span class="nam">country_location</span><span class="op">,</span> <span class="nam">folder_name</span><span class="op">,</span> <span class="nam">n</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t816" class="pln"><span class="n"><a href="#t816">816</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t817" class="run"><span class="n"><a href="#t817">817</a></span><span class="t"> <span class="nam">uids</span> <span class="op">=</span> <span class="nam">age_by_uid_dic</span><span class="op">.</span><span class="nam">keys</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t818" class="run"><span class="n"><a href="#t818">818</a></span><span class="t"> <span class="nam">uids</span> <span class="op">=</span> <span class="op">[</span><span class="nam">uid</span> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">uids</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t819" class="pln"><span class="n"><a href="#t819">819</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t820" class="pln"><span class="n"><a href="#t820">820</a></span><span class="t"> <span class="com"># check school mixing type</span> </span><span class="r"></span></p>
<p id="t821" class="run"><span class="n"><a href="#t821">821</a></span><span class="t"> <span class="key">if</span> <span class="nam">isinstance</span><span class="op">(</span><span class="nam">school_mixing_type</span><span class="op">,</span> <span class="nam">str</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t822" class="run"><span class="n"><a href="#t822">822</a></span><span class="t"> <span class="nam">school_mixing_type_dic</span> <span class="op">=</span> <span class="nam">dict</span><span class="op">.</span><span class="nam">fromkeys</span><span class="op">(</span><span class="op">[</span><span class="str">'pk'</span><span class="op">,</span> <span class="str">'es'</span><span class="op">,</span> <span class="str">'ms'</span><span class="op">,</span> <span class="str">'hs'</span><span class="op">,</span> <span class="str">'uv'</span><span class="op">]</span><span class="op">,</span> <span class="nam">school_mixing_type</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t823" class="mis show_mis"><span class="n"><a href="#t823">823</a></span><span class="t"> <span class="key">elif</span> <span class="nam">isinstance</span><span class="op">(</span><span class="nam">school_mixing_type</span><span class="op">,</span> <span class="nam">dict</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t824" class="mis show_mis"><span class="n"><a href="#t824">824</a></span><span class="t"> <span class="nam">school_mixing_type_dic</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">dcp</span><span class="op">(</span><span class="nam">school_mixing_type</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t825" class="pln"><span class="n"><a href="#t825">825</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t826" class="pln"><span class="n"><a href="#t826">826</a></span><span class="t"> <span class="com"># school type age ranges by default</span> </span><span class="r"></span></p>
<p id="t827" class="run"><span class="n"><a href="#t827">827</a></span><span class="t"> <span class="nam">school_type_by_age</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">mergedicts</span><span class="op">(</span><span class="nam">spsm</span><span class="op">.</span><span class="nam">get_default_school_types_by_age_single</span><span class="op">(</span><span class="op">)</span><span class="op">,</span> <span class="nam">school_type_by_age</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t828" class="pln"><span class="n"><a href="#t828">828</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t829" class="run"><span class="n"><a href="#t829">829</a></span><span class="t"> <span class="nam">grade_age_mapping</span> <span class="op">=</span> <span class="op">{</span><span class="nam">i</span><span class="op">:</span> <span class="nam">i</span><span class="op">+</span><span class="num">5</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="num">13</span><span class="op">)</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t830" class="run"><span class="n"><a href="#t830">830</a></span><span class="t"> <span class="nam">age_grade_mapping</span> <span class="op">=</span> <span class="op">{</span><span class="nam">i</span><span class="op">+</span><span class="num">5</span><span class="op">:</span> <span class="nam">i</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="num">13</span><span class="op">)</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t831" class="run"><span class="n"><a href="#t831">831</a></span><span class="t"> <span class="nam">age_grade_mapping</span><span class="op">[</span><span class="num">3</span><span class="op">]</span> <span class="op">=</span> <span class="num">0</span> </span><span class="r"></span></p>
<p id="t832" class="run"><span class="n"><a href="#t832">832</a></span><span class="t"> <span class="nam">age_grade_mapping</span><span class="op">[</span><span class="num">4</span><span class="op">]</span> <span class="op">=</span> <span class="num">0</span> </span><span class="r"></span></p>
<p id="t833" class="pln"><span class="n"><a href="#t833">833</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t834" class="pln"><span class="n"><a href="#t834">834</a></span><span class="t"> <span class="com"># you have ages but not sexes so we'll just populate that for you at random</span> </span><span class="r"></span></p>
<p id="t835" class="run"><span class="n"><a href="#t835">835</a></span><span class="t"> <span class="nam">popdict</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t836" class="run"><span class="n"><a href="#t836">836</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span><span class="op">,</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">uids</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t837" class="run"><span class="n"><a href="#t837">837</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t838" class="run"><span class="n"><a href="#t838">838</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'age'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">age_by_uid_dic</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t839" class="run"><span class="n"><a href="#t839">839</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sex'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">random</span><span class="op">.</span><span class="nam">binomial</span><span class="op">(</span><span class="num">1</span><span class="op">,</span> <span class="nam">p</span><span class="op">=</span><span class="num">0.5</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t840" class="run"><span class="n"><a href="#t840">840</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'loc'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t841" class="run"><span class="n"><a href="#t841">841</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t842" class="run"><span class="n"><a href="#t842">842</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'hhid'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t843" class="run"><span class="n"><a href="#t843">843</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'scid'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t844" class="run"><span class="n"><a href="#t844">844</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_student'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t845" class="run"><span class="n"><a href="#t845">845</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_teacher'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t846" class="run"><span class="n"><a href="#t846">846</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_staff'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t847" class="run"><span class="n"><a href="#t847">847</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_type'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t848" class="run"><span class="n"><a href="#t848">848</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_mixing_type'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t849" class="run"><span class="n"><a href="#t849">849</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'wpid'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t850" class="run"><span class="n"><a href="#t850">850</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'wpindcode'</span><span class="op">]</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t851" class="run"><span class="n"><a href="#t851">851</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="op">[</span><span class="str">'H'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">,</span> <span class="str">'W'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">]</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t852" class="run"><span class="n"><a href="#t852">852</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span> <span class="op">=</span> <span class="nam">set</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t853" class="pln"><span class="n"><a href="#t853">853</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t854" class="run"><span class="n"><a href="#t854">854</a></span><span class="t"> <span class="nam">fh</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">households_by_uid_path</span><span class="op">,</span> <span class="str">'r'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t855" class="run"><span class="n"><a href="#t855">855</a></span><span class="t"> <span class="key">for</span> <span class="nam">nh</span><span class="op">,</span> <span class="nam">line</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">fh</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t856" class="run"><span class="n"><a href="#t856">856</a></span><span class="t"> <span class="nam">r</span> <span class="op">=</span> <span class="nam">line</span><span class="op">.</span><span class="nam">strip</span><span class="op">(</span><span class="op">)</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">' '</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t857" class="run"><span class="n"><a href="#t857">857</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t858" class="run"><span class="n"><a href="#t858">858</a></span><span class="t"> <span class="nam">r</span> <span class="op">=</span> <span class="op">[</span><span class="nam">int</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t859" class="mis show_mis"><span class="n"><a href="#t859">859</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t860" class="mis show_mis"><span class="n"><a href="#t860">860</a></span><span class="t"> <span class="nam">r</span> <span class="op">=</span> <span class="op">[</span><span class="nam">i</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t861" class="run"><span class="n"><a href="#t861">861</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">r</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t862" class="run"><span class="n"><a href="#t862">862</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="str">'H'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">set</span><span class="op">(</span><span class="nam">r</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t863" class="run"><span class="n"><a href="#t863">863</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="str">'H'</span><span class="op">]</span><span class="op">.</span><span class="nam">remove</span><span class="op">(</span><span class="nam">uid</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t864" class="run"><span class="n"><a href="#t864">864</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'hhid'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">nh</span> </span><span class="r"></span></p>
<p id="t865" class="run"><span class="n"><a href="#t865">865</a></span><span class="t"> <span class="nam">fh</span><span class="op">.</span><span class="nam">close</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t866" class="pln"><span class="n"><a href="#t866">866</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t867" class="run"><span class="n"><a href="#t867">867</a></span><span class="t"> <span class="nam">fs</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">schools_by_uid_path</span><span class="op">,</span> <span class="str">'r'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t868" class="run"><span class="n"><a href="#t868">868</a></span><span class="t"> <span class="nam">ft</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">teachers_by_uid_path</span><span class="op">,</span> <span class="str">'r'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t869" class="pln"><span class="n"><a href="#t869">869</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t870" class="pln"><span class="n"><a href="#t870">870</a></span><span class="t"> <span class="com"># sometimes you may not create populations with other staff</span> </span><span class="r"></span></p>
<p id="t871" class="run"><span class="n"><a href="#t871">871</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_non_teaching_staff</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t872" class="run"><span class="n"><a href="#t872">872</a></span><span class="t"> <span class="nam">line3_list</span> <span class="op">=</span> <span class="op">[</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t873" class="run"><span class="n"><a href="#t873">873</a></span><span class="t"> <span class="nam">fnt</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">non_teaching_staff_by_uid_path</span><span class="op">,</span> <span class="str">'r'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t874" class="run"><span class="n"><a href="#t874">874</a></span><span class="t"> <span class="key">for</span> <span class="nam">i</span><span class="op">,</span> <span class="nam">line</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">fnt</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t875" class="run"><span class="n"><a href="#t875">875</a></span><span class="t"> <span class="nam">line3_list</span><span class="op">.</span><span class="nam">append</span><span class="op">(</span><span class="nam">line</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t876" class="run"><span class="n"><a href="#t876">876</a></span><span class="t"> <span class="nam">fnt</span><span class="op">.</span><span class="nam">close</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t877" class="pln"><span class="n"><a href="#t877">877</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t878" class="run"><span class="n"><a href="#t878">878</a></span><span class="t"> <span class="key">for</span> <span class="nam">ns</span><span class="op">,</span> <span class="op">(</span><span class="nam">line1</span><span class="op">,</span> <span class="nam">line2</span><span class="op">)</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">zip</span><span class="op">(</span><span class="nam">fs</span><span class="op">,</span> <span class="nam">ft</span><span class="op">)</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t879" class="run"><span class="n"><a href="#t879">879</a></span><span class="t"> <span class="nam">r1</span> <span class="op">=</span> <span class="nam">line1</span><span class="op">.</span><span class="nam">strip</span><span class="op">(</span><span class="op">)</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">' '</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t880" class="run"><span class="n"><a href="#t880">880</a></span><span class="t"> <span class="nam">r2</span> <span class="op">=</span> <span class="nam">line2</span><span class="op">.</span><span class="nam">strip</span><span class="op">(</span><span class="op">)</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">' '</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t881" class="run"><span class="n"><a href="#t881">881</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_non_teaching_staff</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t882" class="run"><span class="n"><a href="#t882">882</a></span><span class="t"> <span class="nam">line3</span> <span class="op">=</span> <span class="nam">line3_list</span><span class="op">[</span><span class="nam">ns</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t883" class="run"><span class="n"><a href="#t883">883</a></span><span class="t"> <span class="key">if</span> <span class="nam">line3</span> <span class="op">==</span> <span class="str">'\n'</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t884" class="mis show_mis"><span class="n"><a href="#t884">884</a></span><span class="t"> <span class="nam">r3</span> <span class="op">=</span> <span class="op">[</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t885" class="pln"><span class="n"><a href="#t885">885</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t886" class="run"><span class="n"><a href="#t886">886</a></span><span class="t"> <span class="nam">r3</span> <span class="op">=</span> <span class="nam">line3</span><span class="op">.</span><span class="nam">strip</span><span class="op">(</span><span class="op">)</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">' '</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t887" class="run"><span class="n"><a href="#t887">887</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t888" class="run"><span class="n"><a href="#t888">888</a></span><span class="t"> <span class="nam">non_teaching_staff</span> <span class="op">=</span> <span class="op">[</span><span class="nam">int</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r3</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t889" class="mis show_mis"><span class="n"><a href="#t889">889</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t890" class="mis show_mis"><span class="n"><a href="#t890">890</a></span><span class="t"> <span class="nam">non_teaching_staff</span> <span class="op">=</span> <span class="op">[</span><span class="nam">i</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r3</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t891" class="pln"><span class="n"><a href="#t891">891</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t892" class="run"><span class="n"><a href="#t892">892</a></span><span class="t"> <span class="nam">r3</span> <span class="op">=</span> <span class="op">[</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t893" class="run"><span class="n"><a href="#t893">893</a></span><span class="t"> <span class="nam">non_teaching_staff</span> <span class="op">=</span> <span class="op">[</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t894" class="pln"><span class="n"><a href="#t894">894</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t895" class="run"><span class="n"><a href="#t895">895</a></span><span class="t"> <span class="nam">this_school_type</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t896" class="run"><span class="n"><a href="#t896">896</a></span><span class="t"> <span class="nam">this_school_mixing_type</span> <span class="op">=</span> <span class="key">None</span> </span><span class="r"></span></p>
<p id="t897" class="pln"><span class="n"><a href="#t897">897</a></span><span class="t"> <span class="com"># this_school_mixing_type = 'random'</span> </span><span class="r"></span></p>
<p id="t898" class="pln"><span class="n"><a href="#t898">898</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t899" class="run"><span class="n"><a href="#t899">899</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t900" class="run"><span class="n"><a href="#t900">900</a></span><span class="t"> <span class="nam">students</span> <span class="op">=</span> <span class="op">[</span><span class="nam">int</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r1</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t901" class="run"><span class="n"><a href="#t901">901</a></span><span class="t"> <span class="nam">teachers</span> <span class="op">=</span> <span class="op">[</span><span class="nam">int</span><span class="op">(</span><span class="nam">i</span><span class="op">)</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r2</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t902" class="pln"><span class="n"><a href="#t902">902</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t903" class="mis show_mis"><span class="n"><a href="#t903">903</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t904" class="mis show_mis"><span class="n"><a href="#t904">904</a></span><span class="t"> <span class="nam">students</span> <span class="op">=</span> <span class="op">[</span><span class="nam">i</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r1</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t905" class="mis show_mis"><span class="n"><a href="#t905">905</a></span><span class="t"> <span class="nam">teachers</span> <span class="op">=</span> <span class="op">[</span><span class="nam">i</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">r2</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t906" class="pln"><span class="n"><a href="#t906">906</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t907" class="run"><span class="n"><a href="#t907">907</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_school_types</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t908" class="mis show_mis"><span class="n"><a href="#t908">908</a></span><span class="t"> <span class="nam">student_ages</span> <span class="op">=</span> <span class="op">[</span><span class="nam">age_by_uid_dic</span><span class="op">[</span><span class="nam">i</span><span class="op">]</span> <span class="key">for</span> <span class="nam">i</span> <span class="key">in</span> <span class="nam">students</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t909" class="mis show_mis"><span class="n"><a href="#t909">909</a></span><span class="t"> <span class="nam">min_age</span> <span class="op">=</span> <span class="nam">min</span><span class="op">(</span><span class="nam">student_ages</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t910" class="pln"><span class="n"><a href="#t910">910</a></span><span class="t"> <span class="com"># max_ages = max(student_ages)</span> </span><span class="r"></span></p>
<p id="t911" class="mis show_mis"><span class="n"><a href="#t911">911</a></span><span class="t"> <span class="nam">this_school_type</span> <span class="op">=</span> <span class="nam">school_type_by_age</span><span class="op">[</span><span class="nam">min_age</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t912" class="mis show_mis"><span class="n"><a href="#t912">912</a></span><span class="t"> <span class="nam">this_school_mixing_type</span> <span class="op">=</span> <span class="nam">school_mixing_type_dic</span><span class="op">[</span><span class="nam">this_school_type</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t913" class="mis show_mis"><span class="n"><a href="#t913">913</a></span><span class="t"> <span class="nam">spsm</span><span class="op">.</span><span class="nam">add_school_edges</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">students</span><span class="op">,</span> <span class="nam">student_ages</span><span class="op">,</span> <span class="nam">teachers</span><span class="op">,</span> <span class="nam">non_teaching_staff</span><span class="op">,</span> <span class="nam">age_by_uid_dic</span><span class="op">,</span> <span class="nam">grade_age_mapping</span><span class="op">,</span> <span class="nam">age_grade_mapping</span><span class="op">,</span> <span class="nam">average_class_size</span><span class="op">,</span> <span class="nam">inter_grade_mixing</span><span class="op">,</span> <span class="nam">average_student_teacher_ratio</span><span class="op">,</span> <span class="nam">average_teacher_teacher_degree</span><span class="op">,</span> <span class="nam">average_additional_staff_degree</span><span class="op">,</span> <span class="nam">this_school_mixing_type</span><span class="op">,</span> <span class="nam">verbose</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t914" class="pln"><span class="n"><a href="#t914">914</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t915" class="pln"><span class="n"><a href="#t915">915</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t916" class="run"><span class="n"><a href="#t916">916</a></span><span class="t"> <span class="nam">school</span> <span class="op">=</span> <span class="nam">students</span><span class="op">.</span><span class="nam">copy</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span> <span class="nam">teachers</span><span class="op">.</span><span class="nam">copy</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span> <span class="nam">non_teaching_staff</span><span class="op">.</span><span class="nam">copy</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t917" class="run"><span class="n"><a href="#t917">917</a></span><span class="t"> <span class="nam">school_edges</span> <span class="op">=</span> <span class="nam">spsm</span><span class="op">.</span><span class="nam">generate_random_contacts_across_school</span><span class="op">(</span><span class="nam">school</span><span class="op">,</span> <span class="nam">average_class_size</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t918" class="run"><span class="n"><a href="#t918">918</a></span><span class="t"> <span class="nam">spsm</span><span class="op">.</span><span class="nam">add_contacts_from_edgelist</span><span class="op">(</span><span class="nam">popdict</span><span class="op">,</span> <span class="nam">school_edges</span><span class="op">,</span> <span class="str">'S'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t919" class="pln"><span class="n"><a href="#t919">919</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t920" class="run"><span class="n"><a href="#t920">920</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">students</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t921" class="run"><span class="n"><a href="#t921">921</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'scid'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">ns</span> </span><span class="r"></span></p>
<p id="t922" class="run"><span class="n"><a href="#t922">922</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_student'</span><span class="op">]</span> <span class="op">=</span> <span class="num">1</span> </span><span class="r"></span></p>
<p id="t923" class="run"><span class="n"><a href="#t923">923</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_type'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">this_school_type</span> </span><span class="r"></span></p>
<p id="t924" class="run"><span class="n"><a href="#t924">924</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_mixing_type'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">this_school_mixing_type</span> </span><span class="r"></span></p>
<p id="t925" class="pln"><span class="n"><a href="#t925">925</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t926" class="run"><span class="n"><a href="#t926">926</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">teachers</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t927" class="run"><span class="n"><a href="#t927">927</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'scid'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">ns</span> </span><span class="r"></span></p>
<p id="t928" class="run"><span class="n"><a href="#t928">928</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_teacher'</span><span class="op">]</span> <span class="op">=</span> <span class="num">1</span> </span><span class="r"></span></p>
<p id="t929" class="run"><span class="n"><a href="#t929">929</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_type'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">this_school_type</span> </span><span class="r"></span></p>
<p id="t930" class="run"><span class="n"><a href="#t930">930</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_mixing_type'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">this_school_mixing_type</span> </span><span class="r"></span></p>
<p id="t931" class="pln"><span class="n"><a href="#t931">931</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t932" class="run"><span class="n"><a href="#t932">932</a></span><span class="t"> <span class="key">for</span> <span class="nam">uid</span> <span class="key">in</span> <span class="nam">non_teaching_staff</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t933" class="run"><span class="n"><a href="#t933">933</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'scid'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">ns</span> </span><span class="r"></span></p>
<p id="t934" class="run"><span class="n"><a href="#t934">934</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_staff'</span><span class="op">]</span> <span class="op">=</span> <span class="num">1</span> </span><span class="r"></span></p>
<p id="t935" class="run"><span class="n"><a href="#t935">935</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_type'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">this_school_type</span> </span><span class="r"></span></p>
<p id="t936" class="run"><span class="n"><a href="#t936">936</a></span><span class="t"> <span class="nam">popdict</span><span class="op">[</span><span class="nam">uid</span><span class="op">]</span><span class="op">[</span><span class="str">'sc_mixing_type'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">this_school_mixing_type</span> </span><span class="r"></span></p>
<p id="t937" class="pln"><span class="n"><a href="#t937">937</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t938" class="run"><span class="n"><a href="#t938">938</a></span><span class="t"> <span class="nam">fs</span><span class="op">.</span><span class="nam">close</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t939" class="run"><span class="n"><a href="#t939">939</a></span><span class="t"> <span class="nam">ft</span><span class="op">.</span><span class="nam">close</span><span class="op">(</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t940" class="pln"><span class="n"><a href="#t940">940</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t941" class="run"><span class="n"><a href="#t941">941</a></span><span class="t"> <span class="nam">fw</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">workplaces_by_uid_path</span><span class="op">,</span> <span class="str">'r'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t942" class="run"><span class="n"><a href="#t942">942</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_industry_code</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t943" class="mis show_mis"><span class="n"><a href="#t943">943</a></span><span class="t"> <span class="nam">fi</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">workplaces_by_industry_code_path</span><span class="op">,</span> <span class="str">'r'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t944" class="mis show_mis"><span class="n"><a href="#t944">944</a></span><span class="t"> <span class="nam">workplaces_by_industry_codes</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">loadtxt</span><span class="op">(</span><span class="nam">fi</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t945" class="run"><span class="n"><a href="#t945">945</a></span><span class="t"> <span class="key">for</span> <span class="nam">nw</span><span class="op">,</span> <span class="nam">line</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">fw</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t946" class="run"><span class="n"><a href="#t946">946</a></span><span class="t"> <span class="nam">r</span> <span class="op">=</span> <span class="nam">line</span><span class="op">.</span><span class="nam">strip</span><span class="op">(</span><span class="op">)</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">' '</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t947" class="run"><span class="n"><a href="#t947">947</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>