-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mnt_d_Github_synthpops_synthpops_data_distributions_py.html
1418 lines (1418 loc) · 402 KB
/
_mnt_d_Github_synthpops_synthpops_data_distributions_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/data_distributions.py: 58%</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/data_distributions.py</b> :
<span class="pc_cov">58%</span>
</h1>
<img id="keyboard_icon" src="keybd_closed.png" alt="Show keyboard shortcuts" />
<h2 class="stats">
556 statements
<button type="button" class="run shortkey_r button_toggle_run" title="Toggle lines run">320 run</button>
<button type="button" class="mis show_mis shortkey_m button_toggle_mis" title="Toggle lines missing">236 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">Read in data distributions.</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">sciris</span> <span class="key">as</span> <span class="nam">sc</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">from</span> <span class="nam">collections</span> <span class="key">import</span> <span class="nam">Counter</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">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="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">config</span> <span class="key">as</span> <span class="nam">cfg</span> </span><span class="r"></span></p>
<p id="t12" class="pln"><span class="n"><a href="#t12">12</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t13" class="pln"><span class="n"><a href="#t13">13</a></span><span class="t"> </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">def</span> <span class="nam">get_age_brackets_from_df</span><span class="op">(</span><span class="nam">ab_file_path</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t15" class="pln"><span class="n"><a href="#t15">15</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t16" class="pln"><span class="n"><a href="#t16">16</a></span><span class="t"><span class="str"> Create a dict of age bracket ranges from ab_file_path.</span> </span><span class="r"></span></p>
<p id="t17" class="pln"><span class="n"><a href="#t17">17</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t18" class="pln"><span class="n"><a href="#t18">18</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t19" class="pln"><span class="n"><a href="#t19">19</a></span><span class="t"><span class="str"> ab_file_path (string): file path to get the ends of different age brackets from</span> </span><span class="r"></span></p>
<p id="t20" class="pln"><span class="n"><a href="#t20">20</a></span><span class="t"> </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"> Returns:</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"> A dictionary with a np.ndarray of the age range that maps to each age bracket key.</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"> **Examples**::</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><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"> get_age_brackets_from_df(ab_file_path) returns a dictionary age_brackets, where age_brackets[0] is the age range for the first age bracket, age_brackets[1] is the age range for the second age bracket, etc.</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><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"> """</span> </span><span class="r"></span></p>
<p id="t29" class="run"><span class="n"><a href="#t29">29</a></span><span class="t"> <span class="nam">ab_df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">ab_file_path</span><span class="op">,</span> <span class="nam">header</span><span class="op">=</span><span class="key">None</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t30" class="run"><span class="n"><a href="#t30">30</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t31" class="run"><span class="n"><a href="#t31">31</a></span><span class="t"> <span class="key">for</span> <span class="nam">index</span><span class="op">,</span> <span class="nam">row</span> <span class="key">in</span> <span class="nam">enumerate</span><span class="op">(</span><span class="nam">ab_df</span><span class="op">.</span><span class="nam">iterrows</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="t32" class="run"><span class="n"><a href="#t32">32</a></span><span class="t"> <span class="nam">age_min</span> <span class="op">=</span> <span class="nam">row</span><span class="op">[</span><span class="num">1</span><span class="op">]</span><span class="op">.</span><span class="nam">values</span><span class="op">[</span><span class="num">0</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t33" class="run"><span class="n"><a href="#t33">33</a></span><span class="t"> <span class="nam">age_max</span> <span class="op">=</span> <span class="nam">row</span><span class="op">[</span><span class="num">1</span><span class="op">]</span><span class="op">.</span><span class="nam">values</span><span class="op">[</span><span class="num">1</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t34" class="run"><span class="n"><a href="#t34">34</a></span><span class="t"> <span class="nam">age_brackets</span><span class="op">[</span><span class="nam">index</span><span class="op">]</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">age_min</span><span class="op">,</span> <span class="nam">age_max</span><span class="op">+</span><span class="num">1</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t35" class="run"><span class="n"><a href="#t35">35</a></span><span class="t"> <span class="key">return</span> <span class="nam">age_brackets</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><span class="r"></span></p>
<p id="t37" class="pln"><span class="n"><a href="#t37">37</a></span><span class="t"> </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="key">def</span> <span class="nam">get_gender_fraction_by_age_path</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="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="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 class="str">"""</span> </span><span class="r"></span></p>
<p id="t40" class="pln"><span class="n"><a href="#t40">40</a></span><span class="t"><span class="str"> Get file_path for gender fractions by age bracket. This should only be used if the data is available.</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="pln"><span class="n"><a href="#t42">42</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t43" class="pln"><span class="n"><a href="#t43">43</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="t44" class="pln"><span class="n"><a href="#t44">44</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </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="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t46" class="pln"><span class="n"><a href="#t46">46</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="t47" class="pln"><span class="n"><a href="#t47">47</a></span><span class="t"> </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="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t49" class="pln"><span class="n"><a href="#t49">49</a></span><span class="t"><span class="str"> A file path to the gender fraction by age bracket data.</span> </span><span class="r"></span></p>
<p id="t50" class="pln"><span class="n"><a href="#t50">50</a></span><span class="t"> </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="str"> """</span> </span><span class="r"></span></p>
<p id="t52" class="run"><span class="n"><a href="#t52">52</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t53" class="run"><span class="n"><a href="#t53">53</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t54" class="mis show_mis"><span class="n"><a href="#t54">54</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing inputs. Please check that you have supplied the correct location, state_location, and country_location strings."</span><span class="op">)</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="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t56" class="mis show_mis"><span class="n"><a href="#t56">56</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</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="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t58" class="run"><span class="n"><a href="#t58">58</a></span><span class="t"> <span class="key">return</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 class="str">'age_distributions'</span><span class="op">,</span> <span class="nam">country_location</span> <span class="op">+</span> <span class="str">f'_gender_fraction_by_age_bracket_{cfg.nbrackets}.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t59" class="run"><span class="n"><a href="#t59">59</a></span><span class="t"> <span class="key">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</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">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'age_distributions'</span><span class="op">,</span> <span class="nam">state_location</span> <span class="op">+</span> <span class="str">f'_gender_fraction_by_age_bracket_{cfg.nbrackets}.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t61" class="pln"><span class="n"><a href="#t61">61</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t62" class="run"><span class="n"><a href="#t62">62</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'age_distributions'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">f'_gender_fraction_by_age_bracket_{cfg.nbrackets}.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t63" class="pln"><span class="n"><a href="#t63">63</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t64" class="pln"><span class="n"><a href="#t64">64</a></span><span class="t"> </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">def</span> <span class="nam">read_gender_fraction_by_age_bracket</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t66" class="pln"><span class="n"><a href="#t66">66</a></span><span class="t"> <span class="str">"""</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="str"> A dict of gender fractions by age bracket, either by location, state_location, country_location strings, or by the file_path if that's given.</span> </span><span class="r"></span></p>
<p id="t68" class="pln"><span class="n"><a href="#t68">68</a></span><span class="t"><span class="str"> If use_default, then we'll first try to look for location specific data and if that's not available we'll use default data from Seattle, WA. This</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="str"> may not be appropriate for the population under study so it's best to provide as much data as you can for the specific population.</span> </span><span class="r"></span></p>
<p id="t70" class="pln"><span class="n"><a href="#t70">70</a></span><span class="t"> </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="str"> Args:</span> </span><span class="r"></span></p>
<p id="t72" class="pln"><span class="n"><a href="#t72">72</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="t73" class="pln"><span class="n"><a href="#t73">73</a></span><span class="t"><span class="str"> location (string) : name of the location</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="str"> state_location (string) : name of the state the location is in</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="str"> country_location (string) : name of the country the location is in</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="str"> file_path (string) : file path to user specified gender by age bracket distribution data</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="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</span> </span><span class="r"></span></p>
<p id="t78" class="pln"><span class="n"><a href="#t78">78</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t79" class="pln"><span class="n"><a href="#t79">79</a></span><span class="t"><span class="str"> Returns:</span> </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="str"> A dictionary of the fractions for two genders by age bracket.</span> </span><span class="r"></span></p>
<p id="t81" class="pln"><span class="n"><a href="#t81">81</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t82" class="pln"><span class="n"><a href="#t82">82</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t83" class="run"><span class="n"><a href="#t83">83</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t84" class="run"><span class="n"><a href="#t84">84</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_gender_fraction_by_age_path</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><span class="r"></span></p>
<p id="t85" class="run"><span class="n"><a href="#t85">85</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t86" class="run"><span class="n"><a href="#t86">86</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t87" class="mis show_mis"><span class="n"><a href="#t87">87</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t88" class="mis show_mis"><span class="n"><a href="#t88">88</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t89" class="mis show_mis"><span class="n"><a href="#t89">89</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_gender_fraction_by_age_path</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">'seattle_metro'</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="str">'Washington'</span><span class="op">,</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="t90" class="mis show_mis"><span class="n"><a href="#t90">90</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t92" class="mis show_mis"><span class="n"><a href="#t92">92</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t93" class="run"><span class="n"><a href="#t93">93</a></span><span class="t"> <span class="nam">dic</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t94" class="run"><span class="n"><a href="#t94">94</a></span><span class="t"> <span class="nam">dic</span><span class="op">[</span><span class="str">'male'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">dict</span><span class="op">(</span><span class="nam">zip</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">df</span><span class="op">)</span><span class="op">)</span><span class="op">,</span> <span class="nam">df</span><span class="op">.</span><span class="nam">fraction_male</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t95" class="run"><span class="n"><a href="#t95">95</a></span><span class="t"> <span class="nam">dic</span><span class="op">[</span><span class="str">'female'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">dict</span><span class="op">(</span><span class="nam">zip</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">df</span><span class="op">)</span><span class="op">)</span><span class="op">,</span> <span class="nam">df</span><span class="op">.</span><span class="nam">fraction_female</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t96" class="run"><span class="n"><a href="#t96">96</a></span><span class="t"> <span class="key">return</span> <span class="nam">dic</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><span class="r"></span></p>
<p id="t98" class="pln"><span class="n"><a href="#t98">98</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t99" class="run"><span class="n"><a href="#t99">99</a></span><span class="t"><span class="key">def</span> <span class="nam">get_age_bracket_distr_path</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="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="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 class="str">"""</span> </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="str"> Get file_path for age distribution by age brackets.</span> </span><span class="r"></span></p>
<p id="t102" class="pln"><span class="n"><a href="#t102">102</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t103" class="pln"><span class="n"><a href="#t103">103</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t104" class="pln"><span class="n"><a href="#t104">104</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="t105" class="pln"><span class="n"><a href="#t105">105</a></span><span class="t"><span class="str"> location (string) : name of the location</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 class="str"> state_location (string) : name of the state the location is in</span> </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="str"> country_location (string) : name of the country the location is in</span> </span><span class="r"></span></p>
<p id="t108" class="pln"><span class="n"><a href="#t108">108</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t109" class="pln"><span class="n"><a href="#t109">109</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t110" class="pln"><span class="n"><a href="#t110">110</a></span><span class="t"><span class="str"> A file path to the age distribution by age bracket data.</span> </span><span class="r"></span></p>
<p id="t111" class="pln"><span class="n"><a href="#t111">111</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t112" class="pln"><span class="n"><a href="#t112">112</a></span><span class="t"><span class="str"> """</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">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t114" class="run"><span class="n"><a href="#t114">114</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t115" class="mis show_mis"><span class="n"><a href="#t115">115</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing inputs. Please check that you have supplied the correct location and state_location strings."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t116" class="run"><span class="n"><a href="#t116">116</a></span><span class="t"> <span class="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t117" class="mis show_mis"><span class="n"><a href="#t117">117</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t118" class="run"><span class="n"><a href="#t118">118</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t119" class="mis show_mis"><span class="n"><a href="#t119">119</a></span><span class="t"> <span class="key">return</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 class="str">'age_distributions'</span><span class="op">,</span> <span class="nam">country_location</span> <span class="op">+</span> <span class="str">f'_age_bracket_distr_{cfg.nbrackets}.dat'</span><span class="op">)</span> </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">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t121" class="mis show_mis"><span class="n"><a href="#t121">121</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'age_distributions'</span><span class="op">,</span> <span class="nam">state_location</span> <span class="op">+</span> <span class="str">f'_age_bracket_distr_{cfg.nbrackets}.dat'</span><span class="op">)</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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t123" class="run"><span class="n"><a href="#t123">123</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'age_distributions'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">f'_age_bracket_distr_{cfg.nbrackets}.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t124" class="pln"><span class="n"><a href="#t124">124</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t125" class="pln"><span class="n"><a href="#t125">125</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t126" class="run"><span class="n"><a href="#t126">126</a></span><span class="t"><span class="key">def</span> <span class="nam">read_age_bracket_distr</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t127" class="pln"><span class="n"><a href="#t127">127</a></span><span class="t"> <span class="str">"""</span> </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"> A dict of age distribution by age brackets. If use_default, then we'll first try to look for location specific data and if that's not available we'll use default data from Seattle, WA. This</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"> may not be appropriate for the population under study so it's best to provide as much data as you can for the specific population.</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><span class="r"></span></p>
<p id="t131" class="pln"><span class="n"><a href="#t131">131</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t132" class="pln"><span class="n"><a href="#t132">132</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="t133" class="pln"><span class="n"><a href="#t133">133</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t134" class="pln"><span class="n"><a href="#t134">134</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="t135" class="pln"><span class="n"><a href="#t135">135</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="t136" class="pln"><span class="n"><a href="#t136">136</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t137" class="pln"><span class="n"><a href="#t137">137</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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="pln"><span class="n"><a href="#t139">139</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t140" class="pln"><span class="n"><a href="#t140">140</a></span><span class="t"><span class="str"> A dictionary of the age distribution by age bracket. Keys map to a range of ages in that age bracket.</span> </span><span class="r"></span></p>
<p id="t141" class="pln"><span class="n"><a href="#t141">141</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t142" class="pln"><span class="n"><a href="#t142">142</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t143" class="run"><span class="n"><a href="#t143">143</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </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="nam">file_path</span> <span class="op">=</span> <span class="nam">get_age_bracket_distr_path</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><span class="r"></span></p>
<p id="t145" class="run"><span class="n"><a href="#t145">145</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t146" class="run"><span class="n"><a href="#t146">146</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t147" class="mis show_mis"><span class="n"><a href="#t147">147</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t148" class="mis show_mis"><span class="n"><a href="#t148">148</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t149" class="mis show_mis"><span class="n"><a href="#t149">149</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_age_bracket_distr_path</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">'seattle_metro'</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="str">'Washington'</span><span class="op">,</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="t150" class="mis show_mis"><span class="n"><a href="#t150">150</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t151" class="pln"><span class="n"><a href="#t151">151</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t152" class="mis show_mis"><span class="n"><a href="#t152">152</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</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="key">return</span> <span class="nam">dict</span><span class="op">(</span><span class="nam">zip</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">df</span><span class="op">)</span><span class="op">)</span><span class="op">,</span> <span class="nam">df</span><span class="op">.</span><span class="nam">percent</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t154" class="pln"><span class="n"><a href="#t154">154</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t155" class="pln"><span class="n"><a href="#t155">155</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t156" class="run"><span class="n"><a href="#t156">156</a></span><span class="t"><span class="key">def</span> <span class="nam">get_household_size_distr_path</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="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="op">:</span> </span><span class="r"></span></p>
<p id="t157" class="pln"><span class="n"><a href="#t157">157</a></span><span class="t"> <span class="str">"""</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 class="str"> Get file_path for household size distribution.</span> </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="pln"><span class="n"><a href="#t160">160</a></span><span class="t"><span class="str"> Args:</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"> datadir (string) : file path to the data directory</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"> location (string) : name of the location</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"> state_location (string) : name of the state the location is in</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"> country_location (string) : name of the country the location is in</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><span class="r"></span></p>
<p id="t166" class="pln"><span class="n"><a href="#t166">166</a></span><span class="t"><span class="str"> Returns:</span> </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"> A file path to the household size distribution data.</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><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"> """</span> </span><span class="r"></span></p>
<p id="t170" class="run"><span class="n"><a href="#t170">170</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t171" class="run"><span class="n"><a href="#t171">171</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t172" class="mis show_mis"><span class="n"><a href="#t172">172</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing inputs. Please check that you have supplied the correct location and state_location strings."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t173" class="run"><span class="n"><a href="#t173">173</a></span><span class="t"> <span class="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t174" class="mis show_mis"><span class="n"><a href="#t174">174</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Mssing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t175" class="run"><span class="n"><a href="#t175">175</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t176" class="mis show_mis"><span class="n"><a href="#t176">176</a></span><span class="t"> <span class="key">return</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 class="str">'household size distributions'</span><span class="op">,</span> <span class="nam">country_location</span> <span class="op">+</span> <span class="str">'_household_size_distr.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t177" class="run"><span class="n"><a href="#t177">177</a></span><span class="t"> <span class="key">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t178" class="mis show_mis"><span class="n"><a href="#t178">178</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'household size distributions'</span><span class="op">,</span> <span class="nam">state_location</span> <span class="op">+</span> <span class="str">'_household_size_distr.dat'</span><span class="op">)</span> </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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t180" class="run"><span class="n"><a href="#t180">180</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'household size distributions'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_household_size_distr.dat'</span><span class="op">)</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><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="run"><span class="n"><a href="#t183">183</a></span><span class="t"><span class="key">def</span> <span class="nam">get_household_size_distr</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t184" class="pln"><span class="n"><a href="#t184">184</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t185" class="pln"><span class="n"><a href="#t185">185</a></span><span class="t"><span class="str"> A dictionary of the distributions of household sizes. If you don't give the file_path, then supply the location and state_location strings.</span> </span><span class="r"></span></p>
<p id="t186" class="pln"><span class="n"><a href="#t186">186</a></span><span class="t"><span class="str"> If use_default, then we'll first try to look for location specific data and if that's not available we'll use default data from Seattle, WA. This</span> </span><span class="r"></span></p>
<p id="t187" class="pln"><span class="n"><a href="#t187">187</a></span><span class="t"><span class="str"> may not be appropriate for the population under study so it's best to provide as much data as you can for the specific population.</span> </span><span class="r"></span></p>
<p id="t188" class="pln"><span class="n"><a href="#t188">188</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t189" class="pln"><span class="n"><a href="#t189">189</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t190" class="pln"><span class="n"><a href="#t190">190</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="t191" class="pln"><span class="n"><a href="#t191">191</a></span><span class="t"><span class="str"> location (string) : name of the location</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 class="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t193" class="pln"><span class="n"><a href="#t193">193</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="t194" class="pln"><span class="n"><a href="#t194">194</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t195" class="pln"><span class="n"><a href="#t195">195</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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="pln"><span class="n"><a href="#t197">197</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t198" class="pln"><span class="n"><a href="#t198">198</a></span><span class="t"><span class="str"> A dictionary of the household size distribution data. Keys map to the household size as an integer, values are the percent of households of that size.</span> </span><span class="r"></span></p>
<p id="t199" class="pln"><span class="n"><a href="#t199">199</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t200" class="pln"><span class="n"><a href="#t200">200</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t201" class="run"><span class="n"><a href="#t201">201</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t202" class="run"><span class="n"><a href="#t202">202</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_household_size_distr_path</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><span class="r"></span></p>
<p id="t203" class="run"><span class="n"><a href="#t203">203</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t204" class="run"><span class="n"><a href="#t204">204</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t205" class="mis show_mis"><span class="n"><a href="#t205">205</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t206" class="mis show_mis"><span class="n"><a href="#t206">206</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t207" class="mis show_mis"><span class="n"><a href="#t207">207</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_household_size_distr_path</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">'seattle_metro'</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="str">'Washington'</span><span class="op">,</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="t208" class="mis show_mis"><span class="n"><a href="#t208">208</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t209" class="pln"><span class="n"><a href="#t209">209</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t210" class="mis show_mis"><span class="n"><a href="#t210">210</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</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">return</span> <span class="nam">dict</span><span class="op">(</span><span class="nam">zip</span><span class="op">(</span><span class="nam">df</span><span class="op">.</span><span class="nam">household_size</span><span class="op">,</span> <span class="nam">df</span><span class="op">.</span><span class="nam">percent</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t212" class="pln"><span class="n"><a href="#t212">212</a></span><span class="t"> </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">def</span> <span class="nam">get_head_age_brackets_path</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="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="op">:</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 class="str">"""</span> </span><span class="r"></span></p>
<p id="t216" class="pln"><span class="n"><a href="#t216">216</a></span><span class="t"><span class="str"> Get file_path for head of household age brackets. If data doesn't exist at the state level, only give the country_location.</span> </span><span class="r"></span></p>
<p id="t217" class="pln"><span class="n"><a href="#t217">217</a></span><span class="t"> </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"> Args:</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"> datadir (string) : file path to the data directory</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"> state_location (string) : name of the state</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"> country_location (string) : name of the country the state_location is 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><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"> Returns:</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"> A file path to the age brackets for head of household distribution data.</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"> """</span> </span><span class="r"></span></p>
<p id="t227" class="run"><span class="n"><a href="#t227">227</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t228" class="run"><span class="n"><a href="#t228">228</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t229" class="mis show_mis"><span class="n"><a href="#t229">229</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t230" class="run"><span class="n"><a href="#t230">230</a></span><span class="t"> <span class="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t231" class="mis show_mis"><span class="n"><a href="#t231">231</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t232" class="run"><span class="n"><a href="#t232">232</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t233" class="run"><span class="n"><a href="#t233">233</a></span><span class="t"> <span class="key">return</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 class="str">'household living arrangements'</span><span class="op">,</span> <span class="str">'head_age_brackets.dat'</span><span class="op">)</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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t235" class="run"><span class="n"><a href="#t235">235</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'household living arrangements'</span><span class="op">,</span> <span class="str">'head_age_brackets.dat'</span><span class="op">)</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><span class="r"></span></p>
<p id="t237" class="pln"><span class="n"><a href="#t237">237</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t238" class="run"><span class="n"><a href="#t238">238</a></span><span class="t"><span class="key">def</span> <span class="nam">get_head_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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t239" class="pln"><span class="n"><a href="#t239">239</a></span><span class="t"> <span class="str">"""</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 class="str"> Get a dictionary of head age brackets either from the file_path directly, or using the other parameters to figure out what the file_path should be.</span> </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"> If use_default, then we'll first try to look for location specific data and if that's not available we'll use default data from Seattle, WA. This</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"> may not be appropriate for the population under study so it's best to provide as much data as you can for the specific population.</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><span class="r"></span></p>
<p id="t244" class="pln"><span class="n"><a href="#t244">244</a></span><span class="t"><span class="str"> Args:</span> </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"> datadir (string) : file path to the data directory</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 class="str"> state_location (string) : name of the state</span> </span><span class="r"></span></p>
<p id="t247" class="pln"><span class="n"><a href="#t247">247</a></span><span class="t"><span class="str"> country_location (string) : name of the country the state_location is in</span> </span><span class="r"></span></p>
<p id="t248" class="pln"><span class="n"><a href="#t248">248</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t249" class="pln"><span class="n"><a href="#t249">249</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</span> </span><span class="r"></span></p>
<p id="t250" class="pln"><span class="n"><a href="#t250">250</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t251" class="pln"><span class="n"><a href="#t251">251</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t252" class="pln"><span class="n"><a href="#t252">252</a></span><span class="t"><span class="str"> A dictionary of the age brackets for head of household distribution data. Keys map to the age bracket as an integer, values are the percent of households which head of household in that age bracket.</span> </span><span class="r"></span></p>
<p id="t253" class="pln"><span class="n"><a href="#t253">253</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t254" class="pln"><span class="n"><a href="#t254">254</a></span><span class="t"><span class="str"> """</span> </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="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</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">file_path</span> <span class="op">=</span> <span class="nam">get_head_age_brackets_path</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">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t257" class="run"><span class="n"><a href="#t257">257</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t258" class="run"><span class="n"><a href="#t258">258</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">get_age_brackets_from_df</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t259" class="mis show_mis"><span class="n"><a href="#t259">259</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t260" class="mis show_mis"><span class="n"><a href="#t260">260</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t261" class="mis show_mis"><span class="n"><a href="#t261">261</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_head_age_brackets_path</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="str">'Washington'</span><span class="op">,</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="t262" class="mis show_mis"><span class="n"><a href="#t262">262</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">get_age_brackets_from_df</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t263" class="pln"><span class="n"><a href="#t263">263</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t264" class="mis show_mis"><span class="n"><a href="#t264">264</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</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="key">return</span> <span class="nam">age_brackets</span> </span><span class="r"></span></p>
<p id="t266" class="pln"><span class="n"><a href="#t266">266</a></span><span class="t"> </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="key">def</span> <span class="nam">get_household_head_age_by_size_path</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="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="op">:</span> </span><span class="r"></span></p>
<p id="t269" class="pln"><span class="n"><a href="#t269">269</a></span><span class="t"> <span class="str">"""</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="str"> Get file_path for head of household age by size counts or distribution. If the data doesn't exist at the state level, only give the country_location.</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><span class="r"></span></p>
<p id="t272" class="pln"><span class="n"><a href="#t272">272</a></span><span class="t"><span class="str"> Args:</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="str"> datadir (string) : file path to the data directory</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="str"> state_location (string) : name of the state</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="str"> country_location (string) : name of the country the state_location is in</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="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t278" class="pln"><span class="n"><a href="#t278">278</a></span><span class="t"><span class="str"> A file path to the head of household age by household size count or distribution data.</span> </span><span class="r"></span></p>
<p id="t279" class="pln"><span class="n"><a href="#t279">279</a></span><span class="t"><span class="str"> """</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">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t281" class="run"><span class="n"><a href="#t281">281</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t282" class="mis show_mis"><span class="n"><a href="#t282">282</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t283" class="run"><span class="n"><a href="#t283">283</a></span><span class="t"> <span class="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </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">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t285" class="run"><span class="n"><a href="#t285">285</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t286" class="run"><span class="n"><a href="#t286">286</a></span><span class="t"> <span class="key">return</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 class="str">'household living arrangements'</span><span class="op">,</span> <span class="str">'household_head_age_and_size_count.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t287" class="pln"><span class="n"><a href="#t287">287</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t288" class="run"><span class="n"><a href="#t288">288</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'household living arrangements'</span><span class="op">,</span> <span class="str">'household_head_age_and_size_count.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t289" class="pln"><span class="n"><a href="#t289">289</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t290" class="pln"><span class="n"><a href="#t290">290</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t291" class="run"><span class="n"><a href="#t291">291</a></span><span class="t"><span class="key">def</span> <span class="nam">get_household_head_age_by_size_df</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t292" class="pln"><span class="n"><a href="#t292">292</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t293" class="pln"><span class="n"><a href="#t293">293</a></span><span class="t"><span class="str"> Return a pandas df of head of household age by the size of the household. If the file_path is given return from there first.</span> </span><span class="r"></span></p>
<p id="t294" class="pln"><span class="n"><a href="#t294">294</a></span><span class="t"><span class="str"> If use_default, then we'll first try to look for location specific data and if that's not available we'll use default data from Seattle, WA. This</span> </span><span class="r"></span></p>
<p id="t295" class="pln"><span class="n"><a href="#t295">295</a></span><span class="t"><span class="str"> may not be appropriate for the population under study so it's best to provide as much data as you can for the specific population.</span> </span><span class="r"></span></p>
<p id="t296" class="pln"><span class="n"><a href="#t296">296</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t297" class="pln"><span class="n"><a href="#t297">297</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t298" class="pln"><span class="n"><a href="#t298">298</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="t299" class="pln"><span class="n"><a href="#t299">299</a></span><span class="t"><span class="str"> state_location (string) : name of the state</span> </span><span class="r"></span></p>
<p id="t300" class="pln"><span class="n"><a href="#t300">300</a></span><span class="t"><span class="str"> country_location (string) : name of the country the state_location is in</span> </span><span class="r"></span></p>
<p id="t301" class="pln"><span class="n"><a href="#t301">301</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t302" class="pln"><span class="n"><a href="#t302">302</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</span> </span><span class="r"></span></p>
<p id="t303" class="pln"><span class="n"><a href="#t303">303</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t304" class="pln"><span class="n"><a href="#t304">304</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t305" class="pln"><span class="n"><a href="#t305">305</a></span><span class="t"><span class="str"> A file path to the head of household age by household size count or distribution data.</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 class="str"> """</span> </span><span class="r"></span></p>
<p id="t307" class="run"><span class="n"><a href="#t307">307</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t308" class="run"><span class="n"><a href="#t308">308</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_household_head_age_by_size_path</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">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t309" class="run"><span class="n"><a href="#t309">309</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t310" class="run"><span class="n"><a href="#t310">310</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</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="key">except</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="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t313" class="mis show_mis"><span class="n"><a href="#t313">313</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_household_head_age_by_size_path</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="str">'Washington'</span><span class="op">,</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="t314" class="mis show_mis"><span class="n"><a href="#t314">314</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t315" class="pln"><span class="n"><a href="#t315">315</a></span><span class="t"> <span class="key">else</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">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t317" class="run"><span class="n"><a href="#t317">317</a></span><span class="t"> <span class="key">return</span> <span class="nam">df</span> </span><span class="r"></span></p>
<p id="t318" class="pln"><span class="n"><a href="#t318">318</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t319" class="pln"><span class="n"><a href="#t319">319</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t320" class="run"><span class="n"><a href="#t320">320</a></span><span class="t"><span class="key">def</span> <span class="nam">get_head_age_by_size_distr</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">household_size_1_included</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> <span class="nam">use_default</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="t321" class="pln"><span class="n"><a href="#t321">321</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t322" class="pln"><span class="n"><a href="#t322">322</a></span><span class="t"><span class="str"> Create an array of head of household age bracket counts (col) given by size (row). If use_default, then we'll first try to look for location</span> </span><span class="r"></span></p>
<p id="t323" class="pln"><span class="n"><a href="#t323">323</a></span><span class="t"><span class="str"> specific data and if that's not available we'll use default data from Seattle, WA. This may not be appropriate for the population under study</span> </span><span class="r"></span></p>
<p id="t324" class="pln"><span class="n"><a href="#t324">324</a></span><span class="t"><span class="str"> so it's best to provide as much data as you can for the specific population.</span> </span><span class="r"></span></p>
<p id="t325" class="pln"><span class="n"><a href="#t325">325</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t326" class="pln"><span class="n"><a href="#t326">326</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t327" class="pln"><span class="n"><a href="#t327">327</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="t328" class="pln"><span class="n"><a href="#t328">328</a></span><span class="t"><span class="str"> state_location (string) : name of the state</span> </span><span class="r"></span></p>
<p id="t329" class="pln"><span class="n"><a href="#t329">329</a></span><span class="t"><span class="str"> country_location (string) : name of the country the state_location is in</span> </span><span class="r"></span></p>
<p id="t330" class="pln"><span class="n"><a href="#t330">330</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t331" class="pln"><span class="n"><a href="#t331">331</a></span><span class="t"><span class="str"> household_size_1_included : if True, age distribution for who lives alone is included in the head of household age by household size dataframe, so it will be used. Else, assume a uniform distribution for this among all ages of adults.</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 class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</span> </span><span class="r"></span></p>
<p id="t333" class="pln"><span class="n"><a href="#t333">333</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t334" class="pln"><span class="n"><a href="#t334">334</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t335" class="pln"><span class="n"><a href="#t335">335</a></span><span class="t"><span class="str"> An array where each row s represents the age distribution of the head of households for households of size s-1.</span> </span><span class="r"></span></p>
<p id="t336" class="pln"><span class="n"><a href="#t336">336</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t337" class="pln"><span class="n"><a href="#t337">337</a></span><span class="t"><span class="str"> """</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">hha_df</span> <span class="op">=</span> <span class="nam">get_household_head_age_by_size_df</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">country_location</span><span class="op">,</span> <span class="nam">file_path</span><span class="op">,</span> <span class="nam">use_default</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="nam">hha_by_size</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">zeros</span><span class="op">(</span><span class="op">(</span><span class="num">2</span> <span class="op">+</span> <span class="nam">len</span><span class="op">(</span><span class="nam">hha_df</span><span class="op">)</span><span class="op">,</span> <span class="nam">len</span><span class="op">(</span><span class="nam">hha_df</span><span class="op">.</span><span class="nam">columns</span><span class="op">)</span><span class="op">-</span><span class="num">1</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="key">if</span> <span class="nam">household_size_1_included</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t341" class="mis show_mis"><span class="n"><a href="#t341">341</a></span><span class="t"> <span class="key">for</span> <span class="nam">s</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="num">1</span><span class="op">,</span> <span class="nam">len</span><span class="op">(</span><span class="nam">hha_df</span><span class="op">)</span><span class="op">+</span><span class="num">1</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t342" class="mis show_mis"><span class="n"><a href="#t342">342</a></span><span class="t"> <span class="nam">d</span> <span class="op">=</span> <span class="nam">hha_df</span><span class="op">[</span><span class="nam">hha_df</span><span class="op">[</span><span class="str">'family_size'</span><span class="op">]</span> <span class="op">==</span> <span class="nam">s</span><span class="op">]</span><span class="op">.</span><span class="nam">values</span><span class="op">[</span><span class="num">0</span><span class="op">]</span><span class="op">[</span><span class="num">1</span><span class="op">:</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t343" class="mis show_mis"><span class="n"><a href="#t343">343</a></span><span class="t"> <span class="nam">hha_by_size</span><span class="op">[</span><span class="nam">s</span><span class="op">-</span><span class="num">1</span><span class="op">]</span> <span class="op">=</span> <span class="nam">d</span> </span><span class="r"></span></p>
<p id="t344" class="pln"><span class="n"><a href="#t344">344</a></span><span class="t"> <span class="key">else</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">hha_by_size</span><span class="op">[</span><span class="num">0</span><span class="op">,</span> <span class="op">:</span><span class="op">]</span> <span class="op">+=</span> <span class="num">1</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="key">for</span> <span class="nam">s</span> <span class="key">in</span> <span class="nam">range</span><span class="op">(</span><span class="num">2</span><span class="op">,</span> <span class="nam">len</span><span class="op">(</span><span class="nam">hha_df</span><span class="op">)</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="t347" class="run"><span class="n"><a href="#t347">347</a></span><span class="t"> <span class="nam">d</span> <span class="op">=</span> <span class="nam">hha_df</span><span class="op">[</span><span class="nam">hha_df</span><span class="op">[</span><span class="str">'family_size'</span><span class="op">]</span> <span class="op">==</span> <span class="nam">s</span><span class="op">]</span><span class="op">.</span><span class="nam">values</span><span class="op">[</span><span class="num">0</span><span class="op">]</span><span class="op">[</span><span class="num">1</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="nam">hha_by_size</span><span class="op">[</span><span class="nam">s</span><span class="op">-</span><span class="num">1</span><span class="op">]</span> <span class="op">=</span> <span class="nam">d</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="key">return</span> <span class="nam">hha_by_size</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="pln"><span class="n"><a href="#t351">351</a></span><span class="t"> </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">def</span> <span class="nam">get_census_age_brackets_path</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="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="op">:</span> </span><span class="r"></span></p>
<p id="t353" class="pln"><span class="n"><a href="#t353">353</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t354" class="pln"><span class="n"><a href="#t354">354</a></span><span class="t"><span class="str"> Get file_path for census age brackets: depends on the state or country of the source data on contact patterns.</span> </span><span class="r"></span></p>
<p id="t355" class="pln"><span class="n"><a href="#t355">355</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t356" class="pln"><span class="n"><a href="#t356">356</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t357" class="pln"><span class="n"><a href="#t357">357</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="t358" class="pln"><span class="n"><a href="#t358">358</a></span><span class="t"><span class="str"> state_location (string) : name of the state</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 class="str"> country_location (string) : name of the country the state_location is in</span> </span><span class="r"></span></p>
<p id="t360" class="pln"><span class="n"><a href="#t360">360</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t361" class="pln"><span class="n"><a href="#t361">361</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t362" class="pln"><span class="n"><a href="#t362">362</a></span><span class="t"><span class="str"> A file path to the age brackets to be used with census age data in combination with the contact matrix data.</span> </span><span class="r"></span></p>
<p id="t363" class="pln"><span class="n"><a href="#t363">363</a></span><span class="t"><span class="str"> """</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">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t365" class="run"><span class="n"><a href="#t365">365</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t366" class="mis show_mis"><span class="n"><a href="#t366">366</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</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="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t368" class="mis show_mis"><span class="n"><a href="#t368">368</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </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">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t370" class="mis show_mis"><span class="n"><a href="#t370">370</a></span><span class="t"> <span class="key">return</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 class="str">f'census_age_brackets_{cfg.nbrackets}.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t371" class="pln"><span class="n"><a href="#t371">371</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </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">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">f'census_age_brackets_{cfg.nbrackets}.dat'</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><span class="r"></span></p>
<p id="t374" class="pln"><span class="n"><a href="#t374">374</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t375" class="run"><span class="n"><a href="#t375">375</a></span><span class="t"><span class="key">def</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t376" class="pln"><span class="n"><a href="#t376">376</a></span><span class="t"> <span class="str">"""</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"> Get census age brackets: depends on the country or source of contact pattern data. If use_default, then we'll</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 class="str"> first try to look for location specific data and if that's not available we'll use default data from Seattle, WA.</span> </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"> This may not be appropriate for the population under study so it's best to provide as much data as you can for the</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"> specific population.</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><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"> Args:</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"> datadir (string) : file path to the data directory</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"> state_location (string) : name of the state</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"> country_location (string) : name of the country the state_location is in</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"> file_path (string) : file path to user specified gender by age bracket distribution data</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"> household_size_1_included : if True, age distribution for who lives alone is included in the head of household age by household size dataframe, so it will be used. Else, assume a uniform distribution for this among all ages of adults.</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"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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><span class="r"></span></p>
<p id="t390" class="pln"><span class="n"><a href="#t390">390</a></span><span class="t"><span class="str"> Returns:</span> </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"> A dictionary of the range of ages that map to each age bracket.</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><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"> """</span> </span><span class="r"></span></p>
<p id="t394" class="run"><span class="n"><a href="#t394">394</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t395" class="run"><span class="n"><a href="#t395">395</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_census_age_brackets_path</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">country_location</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t396" class="run"><span class="n"><a href="#t396">396</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t397" class="run"><span class="n"><a href="#t397">397</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">get_age_brackets_from_df</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</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="key">except</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="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t400" class="mis show_mis"><span class="n"><a href="#t400">400</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_census_age_brackets_path</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="str">'Washington'</span><span class="op">,</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="t401" class="mis show_mis"><span class="n"><a href="#t401">401</a></span><span class="t"> <span class="nam">age_brackets</span> <span class="op">=</span> <span class="nam">get_age_brackets_from_df</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t402" class="pln"><span class="n"><a href="#t402">402</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t403" class="mis show_mis"><span class="n"><a href="#t403">403</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t404" class="run"><span class="n"><a href="#t404">404</a></span><span class="t"> <span class="key">return</span> <span class="nam">age_brackets</span> </span><span class="r"></span></p>
<p id="t405" class="pln"><span class="n"><a href="#t405">405</a></span><span class="t"> </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="run"><span class="n"><a href="#t407">407</a></span><span class="t"><span class="key">def</span> <span class="nam">get_contact_matrix</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">setting_code</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">delimiter</span><span class="op">=</span><span class="str">' '</span><span class="op">,</span> <span class="nam">header</span><span class="op">=</span><span class="key">None</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t408" class="pln"><span class="n"><a href="#t408">408</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t409" class="pln"><span class="n"><a href="#t409">409</a></span><span class="t"><span class="str"> Get setting specific contact matrix given sheet name to use. If file_path is given, then delimiter and header should also be specified.</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="pln"><span class="n"><a href="#t411">411</a></span><span class="t"><span class="str"> Args:</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 class="str"> datadir (string) : file path to the data directory</span> </span><span class="r"></span></p>
<p id="t413" class="pln"><span class="n"><a href="#t413">413</a></span><span class="t"><span class="str"> setting_code (string) : name of the physial contact setting: H for households, S for schools, W for workplaces, C for community or other</span> </span><span class="r"></span></p>
<p id="t414" class="pln"><span class="n"><a href="#t414">414</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="t415" class="pln"><span class="n"><a href="#t415">415</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t416" class="pln"><span class="n"><a href="#t416">416</a></span><span class="t"><span class="str"> delimiter (string) : delimter for the contact matrix file</span> </span><span class="r"></span></p>
<p id="t417" class="pln"><span class="n"><a href="#t417">417</a></span><span class="t"><span class="str"> header (int) : row number for the header of the file</span> </span><span class="r"></span></p>
<p id="t418" class="pln"><span class="n"><a href="#t418">418</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t419" class="pln"><span class="n"><a href="#t419">419</a></span><span class="t"><span class="str"> Returns:</span> </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="str"> Matrix of contact patterns where each row i is the average contact patterns for an individual in age bracket i and the columns represent the age brackets of their contacts. The matrix element i,j is then the contact rate, number, or frequency for the average individual in age bracket i with all of their contacts in age bracket j in that physical contact setting.</span> </span><span class="r"></span></p>
<p id="t421" class="pln"><span class="n"><a href="#t421">421</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t422" class="run"><span class="n"><a href="#t422">422</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t423" class="run"><span class="n"><a href="#t423">423</a></span><span class="t"> <span class="nam">setting_names</span> <span class="op">=</span> <span class="op">{</span><span class="str">'H'</span><span class="op">:</span> <span class="str">'home'</span><span class="op">,</span> <span class="str">'S'</span><span class="op">:</span> <span class="str">'school'</span><span class="op">,</span> <span class="str">'W'</span><span class="op">:</span> <span class="str">'work'</span><span class="op">,</span> <span class="str">'C'</span><span class="op">:</span> <span class="str">'other_locations'</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t424" class="run"><span class="n"><a href="#t424">424</a></span><span class="t"> <span class="key">if</span> <span class="nam">setting_code</span> <span class="key">in</span> <span class="nam">setting_names</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t425" class="run"><span class="n"><a href="#t425">425</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="str">'MUestimates_'</span> <span class="op">+</span> <span class="nam">setting_names</span><span class="op">[</span><span class="nam">setting_code</span><span class="op">]</span> <span class="op">+</span> <span class="str">'_1.xlsx'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t426" class="run"><span class="n"><a href="#t426">426</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> <span class="com"># Shortcut: use pre-processed data</span> </span><span class="r"></span></p>
<p id="t427" class="run"><span class="n"><a href="#t427">427</a></span><span class="t"> <span class="nam">obj_path</span> <span class="op">=</span> <span class="nam">file_path</span><span class="op">.</span><span class="nam">replace</span><span class="op">(</span><span class="str">'_1.xlsx'</span><span class="op">,</span> <span class="str">'.obj'</span><span class="op">)</span><span class="op">.</span><span class="nam">replace</span><span class="op">(</span><span class="str">'_2.xlsx'</span><span class="op">,</span> <span class="str">'.obj'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t428" class="run"><span class="n"><a href="#t428">428</a></span><span class="t"> <span class="nam">data</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">loadobj</span><span class="op">(</span><span class="nam">obj_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t429" class="run"><span class="n"><a href="#t429">429</a></span><span class="t"> <span class="nam">arr</span> <span class="op">=</span> <span class="nam">data</span><span class="op">[</span><span class="nam">sheet_name</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t430" class="run"><span class="n"><a href="#t430">430</a></span><span class="t"> <span class="key">return</span> <span class="nam">arr</span> </span><span class="r"></span></p>
<p id="t431" class="mis show_mis"><span class="n"><a href="#t431">431</a></span><span class="t"> <span class="key">except</span> <span class="nam">Exception</span> <span class="key">as</span> <span class="nam">E</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t432" class="mis show_mis"><span class="n"><a href="#t432">432</a></span><span class="t"> <span class="nam">errormsg</span> <span class="op">=</span> <span class="str">f'Warning: could not load pickled data ({str(E)}), defaulting to Excel...'</span> </span><span class="r"></span></p>
<p id="t433" class="mis show_mis"><span class="n"><a href="#t433">433</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="t434" class="mis show_mis"><span class="n"><a href="#t434">434</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t435" class="mis show_mis"><span class="n"><a href="#t435">435</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_excel</span><span class="op">(</span><span class="nam">file_path</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 class="nam">header</span><span class="op">=</span><span class="num">0</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t436" class="mis show_mis"><span class="n"><a href="#t436">436</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t437" class="mis show_mis"><span class="n"><a href="#t437">437</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">file_path</span><span class="op">.</span><span class="nam">replace</span><span class="op">(</span><span class="str">'_1.xlsx'</span><span class="op">,</span> <span class="str">'_2.xlsx'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t438" class="mis show_mis"><span class="n"><a href="#t438">438</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_excel</span><span class="op">(</span><span class="nam">file_path</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 class="nam">header</span><span class="op">=</span><span class="key">None</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t439" class="mis show_mis"><span class="n"><a href="#t439">439</a></span><span class="t"> <span class="key">return</span> <span class="nam">np</span><span class="op">.</span><span class="nam">array</span><span class="op">(</span><span class="nam">df</span><span class="op">)</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 class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t441" class="mis show_mis"><span class="n"><a href="#t441">441</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Invalid setting code. Try again."</span><span class="op">)</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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t443" class="mis show_mis"><span class="n"><a href="#t443">443</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t444" class="mis show_mis"><span class="n"><a href="#t444">444</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">delimiter</span><span class="op">=</span><span class="nam">delimiter</span><span class="op">,</span> <span class="nam">header</span><span class="op">=</span><span class="nam">header</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t445" class="mis show_mis"><span class="n"><a href="#t445">445</a></span><span class="t"> <span class="key">return</span> <span class="nam">np</span><span class="op">.</span><span class="nam">array</span><span class="op">(</span><span class="nam">df</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t446" class="mis show_mis"><span class="n"><a href="#t446">446</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t447" class="mis show_mis"><span class="n"><a href="#t447">447</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Contact matrix did not open. Check inputs."</span><span class="op">)</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><span class="r"></span></p>
<p id="t449" class="pln"><span class="n"><a href="#t449">449</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t450" class="run"><span class="n"><a href="#t450">450</a></span><span class="t"><span class="key">def</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="key">None</span><span class="op">,</span> <span class="nam">file_path_dic</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">delimiter</span><span class="op">=</span><span class="str">' '</span><span class="op">,</span> <span class="nam">header</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t451" class="pln"><span class="n"><a href="#t451">451</a></span><span class="t"> <span class="str">"""</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"> Create a dict of setting specific age mixing matrices. If use_default, then we'll first try to look for location specific</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"> data and if that's not available we'll use default data from Seattle, WA. This may not be appropriate for the population</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"> under study so it's best to provide as much data as you can for the specific population.</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><span class="r"></span></p>
<p id="t456" class="pln"><span class="n"><a href="#t456">456</a></span><span class="t"><span class="str"> Args:</span> </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"> datadir (string) : file path to the data directory</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 class="str"> setting_code (string) : name of the physial contact setting: H for households, S for schools, W for workplaces, C for community or other</span> </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="str"> sheet_name (string) : name of the sheet in the excel file with contact patterns</span> </span><span class="r"></span></p>
<p id="t460" class="pln"><span class="n"><a href="#t460">460</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</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 class="str"> delimiter (string) : delimter for the contact matrix file</span> </span><span class="r"></span></p>
<p id="t462" class="pln"><span class="n"><a href="#t462">462</a></span><span class="t"><span class="str"> header (int) : row number for the header of the file</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><span class="r"></span></p>
<p id="t464" class="pln"><span class="n"><a href="#t464">464</a></span><span class="t"><span class="str"> Returns:</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 class="str"> A dictionary of the different contact matrices for each population, given by the sheet name. Keys map to the different possible physical contact settings for which data are available.</span> </span><span class="r"></span></p>
<p id="t466" class="pln"><span class="n"><a href="#t466">466</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t467" class="pln"><span class="n"><a href="#t467">467</a></span><span class="t"><span class="str"> """</span> </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">matrix_dic</span> <span class="op">=</span> <span class="op">{</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="key">if</span> <span class="nam">file_path_dic</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t470" class="run"><span class="n"><a href="#t470">470</a></span><span class="t"> <span class="nam">file_path_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">'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 class="key">None</span><span class="op">)</span> </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="key">try</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="key">for</span> <span class="nam">setting_code</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="t473" class="run"><span class="n"><a href="#t473">473</a></span><span class="t"> <span class="nam">matrix_dic</span><span class="op">[</span><span class="nam">setting_code</span><span class="op">]</span> <span class="op">=</span> <span class="nam">get_contact_matrix</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">setting_code</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">,</span> <span class="nam">file_path_dic</span><span class="op">[</span><span class="nam">setting_code</span><span class="op">]</span><span class="op">,</span> <span class="nam">delimiter</span><span class="op">,</span> <span class="nam">header</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t474" class="mis show_mis"><span class="n"><a href="#t474">474</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t475" class="mis show_mis"><span class="n"><a href="#t475">475</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t476" class="mis show_mis"><span class="n"><a href="#t476">476</a></span><span class="t"> <span class="key">for</span> <span class="nam">setting_code</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="t477" class="mis show_mis"><span class="n"><a href="#t477">477</a></span><span class="t"> <span class="nam">matrix_dic</span><span class="op">[</span><span class="nam">setting_code</span><span class="op">]</span> <span class="op">=</span> <span class="nam">get_contact_matrix</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">setting_code</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">=</span><span class="str">'United States of America'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t478" class="pln"><span class="n"><a href="#t478">478</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t479" class="mis show_mis"><span class="n"><a href="#t479">479</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</span> </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="key">return</span> <span class="nam">matrix_dic</span> </span><span class="r"></span></p>
<p id="t481" class="pln"><span class="n"><a href="#t481">481</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t482" class="pln"><span class="n"><a href="#t482">482</a></span><span class="t"> </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"># School enrollment data specific for Seattle / United States of America. Change name to reflect that</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><span class="r"></span></p>
<p id="t485" class="run"><span class="n"><a href="#t485">485</a></span><span class="t"><span class="key">def</span> <span class="nam">get_usa_school_enrollment_rates_df</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">locations</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">level</span><span class="op">)</span><span class="op">:</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="str">"""</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="str"> Filters a dataframe on school enrollment rates in the US at the scale of county or PUMA down to relevant locations in the state. Specifying locations as a list allow the selection of</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 class="str"> multiple counties in the same state, in whatever combination desired.</span> </span><span class="r"></span></p>
<p id="t489" class="pln"><span class="n"><a href="#t489">489</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t490" class="pln"><span class="n"><a href="#t490">490</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t491" class="pln"><span class="n"><a href="#t491">491</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="t492" class="pln"><span class="n"><a href="#t492">492</a></span><span class="t"><span class="str"> locations (string or list): name of locations to filter for, either as a string or a list of multiple locations</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 class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t494" class="pln"><span class="n"><a href="#t494">494</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="t495" class="pln"><span class="n"><a href="#t495">495</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in, which here should always be 'usa'</span> </span><span class="r"></span></p>
<p id="t496" class="pln"><span class="n"><a href="#t496">496</a></span><span class="t"><span class="str"> level (string) : name of the level at which the data are aggregated, in general 'county' but could also be 'PUMA'</span> </span><span class="r"></span></p>
<p id="t497" class="pln"><span class="n"><a href="#t497">497</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t498" class="pln"><span class="n"><a href="#t498">498</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t499" class="pln"><span class="n"><a href="#t499">499</a></span><span class="t"><span class="str"> Pandas dataframe with school enrollment data in the US for at the scale of county of PUMA for specified locations within the same state.</span> </span><span class="r"></span></p>
<p id="t500" class="pln"><span class="n"><a href="#t500">500</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t501" class="pln"><span class="n"><a href="#t501">501</a></span><span class="t"><span class="str"> Example usage:</span> </span><span class="r"></span></p>
<p id="t502" class="pln"><span class="n"><a href="#t502">502</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t503" class="pln"><span class="n"><a href="#t503">503</a></span><span class="t"><span class="str"> locations = 'King County, Washington' for a single county</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="pln"><span class="n"><a href="#t505">505</a></span><span class="t"><span class="str"> locations = ['King County, Washington', 'Pierce County, Washington'] for multiple counties</span> </span><span class="r"></span></p>
<p id="t506" class="pln"><span class="n"><a href="#t506">506</a></span><span class="t"><span class="str"> """</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="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 class="nam">state_location</span><span class="op">,</span> <span class="nam">location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="nam">level</span> <span class="op">+</span> <span class="str">'_school_enrollment_by_age'</span><span class="op">,</span><span class="str">'ACSST5Y2018.S1401_data_with_overlays_2020-03-06T233142.csv'</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">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">header</span><span class="op">=</span><span class="num">1</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="key">if</span> <span class="nam">type</span><span class="op">(</span><span class="nam">locations</span><span class="op">)</span> <span class="op">==</span> <span class="nam">list</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">d</span> <span class="op">=</span> <span class="nam">df</span><span class="op">[</span><span class="nam">df</span><span class="op">[</span><span class="str">'Geographic Area Name'</span><span class="op">]</span><span class="op">.</span><span class="nam">isin</span><span class="op">(</span><span class="nam">locations</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 class="key">else</span><span class="op">:</span> </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="nam">d</span> <span class="op">=</span> <span class="nam">df</span><span class="op">[</span><span class="nam">df</span><span class="op">[</span><span class="str">'Geographic Area Name'</span><span class="op">]</span> <span class="op">==</span> <span class="nam">locations</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">return</span> <span class="nam">d</span> </span><span class="r"></span></p>
<p id="t514" class="pln"><span class="n"><a href="#t514">514</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t515" class="pln"><span class="n"><a href="#t515">515</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t516" class="run"><span class="n"><a href="#t516">516</a></span><span class="t"><span class="key">def</span> <span class="nam">process_usa_school_enrollment_rates</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">locations</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">level</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t517" class="pln"><span class="n"><a href="#t517">517</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t518" class="pln"><span class="n"><a href="#t518">518</a></span><span class="t"><span class="str"> Process US school enrollment rates at the county level for age groups and create a dictionary of rates for single year ages.</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="pln"><span class="n"><a href="#t520">520</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t521" class="pln"><span class="n"><a href="#t521">521</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="t522" class="pln"><span class="n"><a href="#t522">522</a></span><span class="t"><span class="str"> locations (string or list): name of locations to filter for, either as a string or a list of multiple locations</span> </span><span class="r"></span></p>
<p id="t523" class="pln"><span class="n"><a href="#t523">523</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t524" class="pln"><span class="n"><a href="#t524">524</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="t525" class="pln"><span class="n"><a href="#t525">525</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in, which here should always be 'usa'</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 class="str"> level (string) : name of the level at which the data are aggregated, in general 'county' but could also be 'PUMA'</span> </span><span class="r"></span></p>
<p id="t527" class="pln"><span class="n"><a href="#t527">527</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t528" class="pln"><span class="n"><a href="#t528">528</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t529" class="pln"><span class="n"><a href="#t529">529</a></span><span class="t"><span class="str"> A dictionary of enrollment rates by single year ages from 0 to 100.</span> </span><span class="r"></span></p>
<p id="t530" class="pln"><span class="n"><a href="#t530">530</a></span><span class="t"><span class="str"> """</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">df</span> <span class="op">=</span> <span class="nam">get_usa_school_enrollment_rates_df</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">locations</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">level</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">skip_labels</span> <span class="op">=</span> <span class="op">[</span><span class="str">'Error'</span><span class="op">,</span> <span class="str">'public'</span><span class="op">,</span> <span class="str">'private'</span><span class="op">,</span> <span class="str">'X'</span><span class="op">,</span> <span class="str">'Total'</span><span class="op">,</span> <span class="str">'Male'</span><span class="op">,</span> <span class="str">'Female'</span><span class="op">,</span> <span class="str">'3 years and over'</span><span class="op">,</span> <span class="str">'18 to 24'</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t533" class="mis show_mis"><span class="n"><a href="#t533">533</a></span><span class="t"> <span class="nam">columns</span> <span class="op">=</span> <span class="nam">df</span><span class="op">.</span><span class="nam">columns</span> </span><span class="r"></span></p>
<p id="t534" class="mis show_mis"><span class="n"><a href="#t534">534</a></span><span class="t"> <span class="nam">columns</span> <span class="op">=</span> <span class="op">[</span><span class="nam">col</span> <span class="key">for</span> <span class="nam">col</span> <span class="key">in</span> <span class="nam">columns</span> <span class="key">if</span> <span class="key">not</span> <span class="nam">any</span><span class="op">(</span><span class="nam">l</span> <span class="key">in</span> <span class="nam">col</span> <span class="key">for</span> <span class="nam">l</span> <span class="key">in</span> <span class="nam">skip_labels</span><span class="op">)</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t535" class="pln"><span class="n"><a href="#t535">535</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t536" class="mis show_mis"><span class="n"><a href="#t536">536</a></span><span class="t"> <span class="nam">rates</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="nam">np</span><span class="op">.</span><span class="nam">arange</span><span class="op">(</span><span class="num">101</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="t537" class="pln"><span class="n"><a href="#t537">537</a></span><span class="t"> <span class="com"># process into enrollment rates by age</span> </span><span class="r"></span></p>
<p id="t538" class="mis show_mis"><span class="n"><a href="#t538">538</a></span><span class="t"> <span class="key">for</span> <span class="nam">col</span> <span class="key">in</span> <span class="nam">columns</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t539" class="mis show_mis"><span class="n"><a href="#t539">539</a></span><span class="t"> <span class="key">if</span> <span class="str">'enrolled in school'</span> <span class="key">in</span> <span class="nam">col</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t540" class="pln"><span class="n"><a href="#t540">540</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t541" class="mis show_mis"><span class="n"><a href="#t541">541</a></span><span class="t"> <span class="nam">age_bracket</span> <span class="op">=</span> <span class="nam">col</span><span class="op">.</span><span class="nam">replace</span><span class="op">(</span><span class="str">' year olds enrolled in school'</span><span class="op">,</span> <span class="str">''</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t542" class="mis show_mis"><span class="n"><a href="#t542">542</a></span><span class="t"> <span class="nam">age_bracket</span> <span class="op">=</span> <span class="nam">age_bracket</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">'!!'</span><span class="op">)</span><span class="op">[</span><span class="op">-</span><span class="num">1</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t543" class="pln"><span class="n"><a href="#t543">543</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t544" class="mis show_mis"><span class="n"><a href="#t544">544</a></span><span class="t"> <span class="key">if</span> <span class="str">' to '</span> <span class="key">in</span> <span class="nam">age_bracket</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t545" class="mis show_mis"><span class="n"><a href="#t545">545</a></span><span class="t"> <span class="nam">age_bracket</span> <span class="op">=</span> <span class="nam">age_bracket</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">' to '</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t546" class="mis show_mis"><span class="n"><a href="#t546">546</a></span><span class="t"> <span class="key">elif</span> <span class="str">' and '</span> <span class="key">in</span> <span class="nam">age_bracket</span> <span class="key">and</span> <span class="str">'over'</span> <span class="key">not</span> <span class="key">in</span> <span class="nam">age_bracket</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t547" class="mis show_mis"><span class="n"><a href="#t547">547</a></span><span class="t"> <span class="nam">age_bracket</span> <span class="op">=</span> <span class="nam">age_bracket</span><span class="op">.</span><span class="nam">split</span><span class="op">(</span><span class="str">' and '</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t548" class="mis show_mis"><span class="n"><a href="#t548">548</a></span><span class="t"> <span class="key">elif</span> <span class="str">'over'</span> <span class="key">in</span> <span class="nam">age_bracket</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t549" class="mis show_mis"><span class="n"><a href="#t549">549</a></span><span class="t"> <span class="nam">age_bracket</span> <span class="op">=</span> <span class="nam">age_bracket</span><span class="op">.</span><span class="nam">replace</span><span class="op">(</span><span class="str">' years and over enrolled in school'</span><span class="op">,</span> <span class="str">''</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t550" class="pln"><span class="n"><a href="#t550">550</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t551" class="mis show_mis"><span class="n"><a href="#t551">551</a></span><span class="t"> <span class="key">if</span> <span class="nam">type</span><span class="op">(</span><span class="nam">age_bracket</span><span class="op">)</span> <span class="op">==</span> <span class="nam">list</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t552" class="mis show_mis"><span class="n"><a href="#t552">552</a></span><span class="t"> <span class="nam">sa</span><span class="op">,</span> <span class="nam">ea</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">age_bracket</span><span class="op">[</span><span class="num">0</span><span class="op">]</span><span class="op">)</span><span class="op">,</span> <span class="nam">int</span><span class="op">(</span><span class="nam">age_bracket</span><span class="op">[</span><span class="num">1</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t553" class="pln"><span class="n"><a href="#t553">553</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t554" class="mis show_mis"><span class="n"><a href="#t554">554</a></span><span class="t"> <span class="nam">sa</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">age_bracket</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t555" class="mis show_mis"><span class="n"><a href="#t555">555</a></span><span class="t"> <span class="nam">ea</span> <span class="op">=</span> <span class="nam">sa</span> <span class="op">+</span> <span class="num">15</span> <span class="com"># estimate of when the last age bracket ends, this makes the last age bracket cover ages 35-50 inclusively</span> </span><span class="r"></span></p>
<p id="t556" class="pln"><span class="n"><a href="#t556">556</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t557" class="mis show_mis"><span class="n"><a href="#t557">557</a></span><span class="t"> <span class="key">for</span> <span class="nam">a</span> <span class="key">in</span> <span class="nam">np</span><span class="op">.</span><span class="nam">arange</span><span class="op">(</span><span class="nam">sa</span><span class="op">,</span> <span class="nam">ea</span><span class="op">+</span><span class="num">1</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t558" class="mis show_mis"><span class="n"><a href="#t558">558</a></span><span class="t"> <span class="nam">rates</span><span class="op">[</span><span class="nam">a</span><span class="op">]</span> <span class="op">=</span> <span class="nam">np</span><span class="op">.</span><span class="nam">round</span><span class="op">(</span><span class="nam">df</span><span class="op">[</span><span class="nam">col</span><span class="op">]</span><span class="op">.</span><span class="nam">values</span><span class="op">[</span><span class="num">0</span><span class="op">]</span><span class="op">/</span><span class="num">100</span><span class="op">,</span> <span class="num">8</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t559" class="mis show_mis"><span class="n"><a href="#t559">559</a></span><span class="t"> <span class="key">return</span> <span class="nam">rates</span> </span><span class="r"></span></p>
<p id="t560" class="pln"><span class="n"><a href="#t560">560</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t561" class="pln"><span class="n"><a href="#t561">561</a></span><span class="t"> </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="key">def</span> <span class="nam">write_school_enrollment_rates</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">locations</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">level</span><span class="op">)</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 class="str">"""</span> </span><span class="r"></span></p>
<p id="t564" class="pln"><span class="n"><a href="#t564">564</a></span><span class="t"><span class="str"> Write enrollment rates from age brackets into a file for single year ages.</span> </span><span class="r"></span></p>
<p id="t565" class="pln"><span class="n"><a href="#t565">565</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t566" class="pln"><span class="n"><a href="#t566">566</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t567" class="pln"><span class="n"><a href="#t567">567</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="t568" class="pln"><span class="n"><a href="#t568">568</a></span><span class="t"><span class="str"> locations (string or list): name of locations to filter for, either as a string or a list of multiple locations</span> </span><span class="r"></span></p>
<p id="t569" class="pln"><span class="n"><a href="#t569">569</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t570" class="pln"><span class="n"><a href="#t570">570</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="t571" class="pln"><span class="n"><a href="#t571">571</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in, which here should always be 'usa'</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 class="str"> level (string) : name of the level at which the data are aggregated, in general 'county' but could also be 'PUMA'</span> </span><span class="r"></span></p>
<p id="t573" class="pln"><span class="n"><a href="#t573">573</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t574" class="pln"><span class="n"><a href="#t574">574</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t575" class="pln"><span class="n"><a href="#t575">575</a></span><span class="t"><span class="str"> None</span> </span><span class="r"></span></p>
<p id="t576" class="pln"><span class="n"><a href="#t576">576</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t577" class="mis show_mis"><span class="n"><a href="#t577">577</a></span><span class="t"> <span class="nam">rates</span> <span class="op">=</span> <span class="nam">process_usa_school_enrollment_rates</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">locations</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">level</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t578" class="mis show_mis"><span class="n"><a href="#t578">578</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'enrollment'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t579" class="mis show_mis"><span class="n"><a href="#t579">579</a></span><span class="t"> <span class="nam">os</span><span class="op">.</span><span class="nam">makedirs</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="nam">exist_ok</span><span class="op">=</span><span class="key">True</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t580" class="mis show_mis"><span class="n"><a href="#t580">580</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">file_path</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_school_enrollment_by_age.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t581" class="mis show_mis"><span class="n"><a href="#t581">581</a></span><span class="t"> <span class="nam">f</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="str">'w'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t582" class="mis show_mis"><span class="n"><a href="#t582">582</a></span><span class="t"> <span class="nam">f</span><span class="op">.</span><span class="nam">write</span><span class="op">(</span><span class="str">'Age,Percent\n'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t583" class="mis show_mis"><span class="n"><a href="#t583">583</a></span><span class="t"> <span class="key">for</span> <span class="nam">a</span> <span class="key">in</span> <span class="nam">rates</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t584" class="mis show_mis"><span class="n"><a href="#t584">584</a></span><span class="t"> <span class="nam">f</span><span class="op">.</span><span class="nam">write</span><span class="op">(</span><span class="nam">str</span><span class="op">(</span><span class="nam">a</span><span class="op">)</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">rates</span><span class="op">[</span><span class="nam">a</span><span class="op">]</span><span class="op">)</span> <span class="op">+</span> <span class="str">'\n'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t585" class="mis show_mis"><span class="n"><a href="#t585">585</a></span><span class="t"> <span class="nam">f</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="t586" class="pln"><span class="n"><a href="#t586">586</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t587" class="pln"><span class="n"><a href="#t587">587</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t588" class="run"><span class="n"><a href="#t588">588</a></span><span class="t"><span class="key">def</span> <span class="nam">get_school_enrollment_rates_path</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="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="op">:</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 class="str">"""</span> </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"> Get a file_path for enrollment rates by age.</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><span class="r"></span></p>
<p id="t592" class="pln"><span class="n"><a href="#t592">592</a></span><span class="t"><span class="str"> Args:</span> </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"> datadir (string) : file path to the data directory</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"> location (string) : name of the location</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"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t596" class="pln"><span class="n"><a href="#t596">596</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="t597" class="pln"><span class="n"><a href="#t597">597</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t598" class="pln"><span class="n"><a href="#t598">598</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t599" class="pln"><span class="n"><a href="#t599">599</a></span><span class="t"><span class="str"> A file path to the school enrollment rates.</span> </span><span class="r"></span></p>
<p id="t600" class="pln"><span class="n"><a href="#t600">600</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t601" class="run"><span class="n"><a href="#t601">601</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t602" class="run"><span class="n"><a href="#t602">602</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t603" class="mis show_mis"><span class="n"><a href="#t603">603</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t604" class="run"><span class="n"><a href="#t604">604</a></span><span class="t"> <span class="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t605" class="mis show_mis"><span class="n"><a href="#t605">605</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t606" class="run"><span class="n"><a href="#t606">606</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t607" class="mis show_mis"><span class="n"><a href="#t607">607</a></span><span class="t"> <span class="key">return</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 class="str">'enrollment'</span><span class="op">,</span> <span class="nam">country_location</span> <span class="op">+</span> <span class="str">'_school_enrollment_by_age.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t608" class="run"><span class="n"><a href="#t608">608</a></span><span class="t"> <span class="key">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t609" class="mis show_mis"><span class="n"><a href="#t609">609</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'enrollment'</span><span class="op">,</span> <span class="nam">state_location</span> <span class="op">+</span> <span class="str">'_school_enrollment_by_age.dat'</span><span class="op">)</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 class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t611" class="run"><span class="n"><a href="#t611">611</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'enrollment'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_school_enrollment_by_age.dat'</span><span class="op">)</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><span class="r"></span></p>
<p id="t613" class="pln"><span class="n"><a href="#t613">613</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t614" class="run"><span class="n"><a href="#t614">614</a></span><span class="t"><span class="key">def</span> <span class="nam">get_school_enrollment_rates</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t615" class="pln"><span class="n"><a href="#t615">615</a></span><span class="t"> <span class="str">"""</span> </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"> Get dictionary of enrollment rates by age. If use_default, then we'll first try to look for location specific</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"> data and if that's not available we'll use default data from Seattle, WA. This may not be appropriate for the population</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"> under study so it's best to provide as much data as you can for the specific population.</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="pln"><span class="n"><a href="#t620">620</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t621" class="pln"><span class="n"><a href="#t621">621</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="t622" class="pln"><span class="n"><a href="#t622">622</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t623" class="pln"><span class="n"><a href="#t623">623</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="t624" class="pln"><span class="n"><a href="#t624">624</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="t625" class="pln"><span class="n"><a href="#t625">625</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</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"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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><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"> Returns:</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"> A dictionary of school enrollment rates by age.</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 class="str"> """</span> </span><span class="r"></span></p>
<p id="t631" class="run"><span class="n"><a href="#t631">631</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t632" class="run"><span class="n"><a href="#t632">632</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_school_enrollment_rates_path</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><span class="r"></span></p>
<p id="t633" class="run"><span class="n"><a href="#t633">633</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t634" class="run"><span class="n"><a href="#t634">634</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t635" class="run"><span class="n"><a href="#t635">635</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t636" class="run"><span class="n"><a href="#t636">636</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t637" class="run"><span class="n"><a href="#t637">637</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_school_enrollment_rates_path</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">'seattle_metro'</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="str">'Washington'</span><span class="op">,</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="t638" class="run"><span class="n"><a href="#t638">638</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t640" class="mis show_mis"><span class="n"><a href="#t640">640</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t641" class="run"><span class="n"><a href="#t641">641</a></span><span class="t"> <span class="key">return</span> <span class="nam">dict</span><span class="op">(</span><span class="nam">zip</span><span class="op">(</span><span class="nam">df</span><span class="op">.</span><span class="nam">Age</span><span class="op">,</span> <span class="nam">df</span><span class="op">.</span><span class="nam">Percent</span><span class="op">)</span><span class="op">)</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><span class="r"></span></p>
<p id="t643" class="pln"><span class="n"><a href="#t643">643</a></span><span class="t"> </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="com"># Generalized function for any location that has enrollment sizes</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><span class="r"></span></p>
<p id="t646" class="run"><span class="n"><a href="#t646">646</a></span><span class="t"><span class="key">def</span> <span class="nam">get_school_size_brackets_path</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="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="op">:</span> </span><span class="r"></span></p>
<p id="t647" class="pln"><span class="n"><a href="#t647">647</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t648" class="pln"><span class="n"><a href="#t648">648</a></span><span class="t"><span class="str"> Get file_path for school size brackets specific to the location under study.</span> </span><span class="r"></span></p>
<p id="t649" class="pln"><span class="n"><a href="#t649">649</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t650" class="pln"><span class="n"><a href="#t650">650</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t651" class="pln"><span class="n"><a href="#t651">651</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="t652" class="pln"><span class="n"><a href="#t652">652</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t653" class="pln"><span class="n"><a href="#t653">653</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="t654" class="pln"><span class="n"><a href="#t654">654</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="t655" class="pln"><span class="n"><a href="#t655">655</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t656" class="pln"><span class="n"><a href="#t656">656</a></span><span class="t"><span class="str"> Returns:</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 class="str"> A file path to school size brackets.</span> </span><span class="r"></span></p>
<p id="t658" class="pln"><span class="n"><a href="#t658">658</a></span><span class="t"><span class="str"> """</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">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t660" class="run"><span class="n"><a href="#t660">660</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t661" class="mis show_mis"><span class="n"><a href="#t661">661</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</span><span class="op">)</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="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t663" class="mis show_mis"><span class="n"><a href="#t663">663</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </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">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</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="key">return</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 class="str">'schools'</span><span class="op">,</span> <span class="str">'school_size_brackets.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t666" class="run"><span class="n"><a href="#t666">666</a></span><span class="t"> <span class="key">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t667" class="mis show_mis"><span class="n"><a href="#t667">667</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="str">'school_size_brackets.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t668" class="pln"><span class="n"><a href="#t668">668</a></span><span class="t"> <span class="key">else</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="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_school_size_brackets.dat'</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><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">def</span> <span class="nam">get_school_size_brackets</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t673" class="pln"><span class="n"><a href="#t673">673</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t674" class="pln"><span class="n"><a href="#t674">674</a></span><span class="t"><span class="str"> Get school size brackets: depends on the source/location of the data. If use_default, then we'll</span> </span><span class="r"></span></p>
<p id="t675" class="pln"><span class="n"><a href="#t675">675</a></span><span class="t"><span class="str"> first try to look for location specific data and if that's not available we'll use default data from Seattle, WA.</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 class="str"> This may not be appropriate for the population under study so it's best to provide as much data as you can for the</span> </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="str"> specific population.</span> </span><span class="r"></span></p>
<p id="t678" class="pln"><span class="n"><a href="#t678">678</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t679" class="pln"><span class="n"><a href="#t679">679</a></span><span class="t"><span class="str"> Args:</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="str"> datadir (string) : file path to the data directory</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="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t682" class="pln"><span class="n"><a href="#t682">682</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="t683" class="pln"><span class="n"><a href="#t683">683</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="t684" class="pln"><span class="n"><a href="#t684">684</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t685" class="pln"><span class="n"><a href="#t685">685</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t688" class="pln"><span class="n"><a href="#t688">688</a></span><span class="t"><span class="str"> A dictionary of school size brackets.</span> </span><span class="r"></span></p>
<p id="t689" class="pln"><span class="n"><a href="#t689">689</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t690" class="run"><span class="n"><a href="#t690">690</a></span><span class="t"> <span class="key">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </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="nam">file_path</span> <span class="op">=</span> <span class="nam">get_school_size_brackets_path</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><span class="r"></span></p>
<p id="t692" class="run"><span class="n"><a href="#t692">692</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t693" class="run"><span class="n"><a href="#t693">693</a></span><span class="t"> <span class="nam">school_size_brackets</span> <span class="op">=</span> <span class="nam">get_age_brackets_from_df</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t694" class="run"><span class="n"><a href="#t694">694</a></span><span class="t"> <span class="key">except</span><span class="op">:</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="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t696" class="run"><span class="n"><a href="#t696">696</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_school_size_brackets_path</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">'seattle_metro'</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="str">'Washington'</span><span class="op">,</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="t697" class="run"><span class="n"><a href="#t697">697</a></span><span class="t"> <span class="nam">school_size_brackets</span> <span class="op">=</span> <span class="nam">get_age_brackets_from_df</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t698" class="pln"><span class="n"><a href="#t698">698</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t699" class="mis show_mis"><span class="n"><a href="#t699">699</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</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="key">return</span> <span class="nam">school_size_brackets</span> </span><span class="r"></span></p>
<p id="t701" class="pln"><span class="n"><a href="#t701">701</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t702" class="pln"><span class="n"><a href="#t702">702</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t703" class="run"><span class="n"><a href="#t703">703</a></span><span class="t"><span class="key">def</span> <span class="nam">get_school_sizes_path</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="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="op">:</span> </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="str">"""</span> </span><span class="r"></span></p>
<p id="t705" class="pln"><span class="n"><a href="#t705">705</a></span><span class="t"><span class="str"> Get file_path for school sizes specific to the location under study.</span> </span><span class="r"></span></p>
<p id="t706" class="pln"><span class="n"><a href="#t706">706</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t707" class="pln"><span class="n"><a href="#t707">707</a></span><span class="t"><span class="str"> Args:</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 class="str"> datadir (string) : file path to the data directory</span> </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="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t710" class="pln"><span class="n"><a href="#t710">710</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="t711" class="pln"><span class="n"><a href="#t711">711</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="t712" class="pln"><span class="n"><a href="#t712">712</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t713" class="pln"><span class="n"><a href="#t713">713</a></span><span class="t"><span class="str"> Returns:</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 class="str"> A file path to school sizes.</span> </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="str"> """</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><span class="r"></span></p>
<p id="t717" class="run"><span class="n"><a href="#t717">717</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t718" class="run"><span class="n"><a href="#t718">718</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t719" class="mis show_mis"><span class="n"><a href="#t719">719</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t720" class="run"><span class="n"><a href="#t720">720</a></span><span class="t"> <span class="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t721" class="mis show_mis"><span class="n"><a href="#t721">721</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t722" class="run"><span class="n"><a href="#t722">722</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t723" class="mis show_mis"><span class="n"><a href="#t723">723</a></span><span class="t"> <span class="key">return</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 class="str">'schools'</span><span class="op">,</span> <span class="str">'school_sizes.dat'</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="key">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t725" class="mis show_mis"><span class="n"><a href="#t725">725</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="str">'school_sizes.dat'</span><span class="op">)</span> </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="key">else</span><span class="op">:</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="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_school_sizes.dat'</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><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">def</span> <span class="nam">get_school_sizes_df</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="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">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="t731" class="pln"><span class="n"><a href="#t731">731</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t732" class="pln"><span class="n"><a href="#t732">732</a></span><span class="t"><span class="str"> Get pandas dataframe with school enrollment sizes: depends on the country or source of contact pattern data. If use_default, then we'll first</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 class="str"> try to look for location specific data and if that's not available we'll use default data from Seattle, WA. This may not</span> </span><span class="r"></span></p>
<p id="t734" class="pln"><span class="n"><a href="#t734">734</a></span><span class="t"><span class="str"> be appropriate for the population under study so it's best to provide as much data as you can for the specific population.</span> </span><span class="r"></span></p>
<p id="t735" class="pln"><span class="n"><a href="#t735">735</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t736" class="pln"><span class="n"><a href="#t736">736</a></span><span class="t"><span class="str"> Args:</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 class="str"> datadir (string) : file path to the data directory</span> </span><span class="r"></span></p>
<p id="t738" class="pln"><span class="n"><a href="#t738">738</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t739" class="pln"><span class="n"><a href="#t739">739</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="t740" class="pln"><span class="n"><a href="#t740">740</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="t741" class="pln"><span class="n"><a href="#t741">741</a></span><span class="t"><span class="str"> file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t742" class="pln"><span class="n"><a href="#t742">742</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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="pln"><span class="n"><a href="#t744">744</a></span><span class="t"><span class="str"> Returns:</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 class="str"> A pandas dataframe with school sizes.</span> </span><span class="r"></span></p>
<p id="t746" class="pln"><span class="n"><a href="#t746">746</a></span><span class="t"><span class="str"> """</span> </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">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t748" class="run"><span class="n"><a href="#t748">748</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_school_sizes_path</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><span class="r"></span></p>
<p id="t749" class="run"><span class="n"><a href="#t749">749</a></span><span class="t"> <span class="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t750" class="run"><span class="n"><a href="#t750">750</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t751" class="mis show_mis"><span class="n"><a href="#t751">751</a></span><span class="t"> <span class="key">except</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t752" class="mis show_mis"><span class="n"><a href="#t752">752</a></span><span class="t"> <span class="key">if</span> <span class="nam">use_default</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t753" class="mis show_mis"><span class="n"><a href="#t753">753</a></span><span class="t"> <span class="nam">file_path</span> <span class="op">=</span> <span class="nam">get_school_sizes_path</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">'seattle_metro'</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="str">'Washington'</span><span class="op">,</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="t754" class="mis show_mis"><span class="n"><a href="#t754">754</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t756" class="mis show_mis"><span class="n"><a href="#t756">756</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t757" class="run"><span class="n"><a href="#t757">757</a></span><span class="t"> <span class="key">return</span> <span class="nam">df</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><span class="r"></span></p>
<p id="t760" class="run"><span class="n"><a href="#t760">760</a></span><span class="t"><span class="key">def</span> <span class="nam">get_school_size_distr_by_brackets_path</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="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="op">:</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">"""</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"> Get file_path for the distribution of school size by brackets.</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><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"> Args:</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"> datadir (string) : file path to the data directory</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"> location (string) : name of the location</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"> state_location (string) : name of the state the location is in</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"> country_location (string) : name of the country the location is in</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><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"> Returns:</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"> A file path to the distribution of school sizes by bracket.</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"> """</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><span class="r"></span></p>
<p id="t774" class="run"><span class="n"><a href="#t774">774</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t775" class="run"><span class="n"><a href="#t775">775</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t776" class="mis show_mis"><span class="n"><a href="#t776">776</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t777" class="run"><span class="n"><a href="#t777">777</a></span><span class="t"> <span class="key">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t778" class="mis show_mis"><span class="n"><a href="#t778">778</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t779" class="run"><span class="n"><a href="#t779">779</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t780" class="run"><span class="n"><a href="#t780">780</a></span><span class="t"> <span class="key">return</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 class="str">'schools'</span><span class="op">,</span> <span class="str">'school_size_distr.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t781" class="run"><span class="n"><a href="#t781">781</a></span><span class="t"> <span class="key">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t782" class="mis show_mis"><span class="n"><a href="#t782">782</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="str">'school_size_distr.dat'</span><span class="op">)</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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t784" class="run"><span class="n"><a href="#t784">784</a></span><span class="t"> <span class="key">return</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_school_size_distr.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t785" class="pln"><span class="n"><a href="#t785">785</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t786" class="pln"><span class="n"><a href="#t786">786</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t787" class="run"><span class="n"><a href="#t787">787</a></span><span class="t"><span class="key">def</span> <span class="nam">get_school_size_distr_by_brackets</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="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">counts_available</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> <span class="nam">file_path</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">use_default</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="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="pln"><span class="n"><a href="#t789">789</a></span><span class="t"><span class="str"> Get distribution of school sizes by bracket. Either you have enrollments by individual school or you have school size distribution that is binned. Either way, you want to get a school size distribution.</span> </span><span class="r"></span></p>
<p id="t790" class="pln"><span class="n"><a href="#t790">790</a></span><span class="t"><span class="str"> If use_default, then we'll first try to look for location specific data and if that's not available we'll use default data from Seattle, WA. This may not</span> </span><span class="r"></span></p>
<p id="t791" class="pln"><span class="n"><a href="#t791">791</a></span><span class="t"><span class="str"> be appropriate for the population under study so it's best to provide as much data as you can for the specific population.</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><span class="r"></span></p>
<p id="t793" class="pln"><span class="n"><a href="#t793">793</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t794" class="pln"><span class="n"><a href="#t794">794</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="t795" class="pln"><span class="n"><a href="#t795">795</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t796" class="pln"><span class="n"><a href="#t796">796</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="t797" class="pln"><span class="n"><a href="#t797">797</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="t798" class="pln"><span class="n"><a href="#t798">798</a></span><span class="t"><span class="str"> counts_available (bool) : if True, a list of school sizes is available and a count of the sizes can be constructed</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="str"> file_path (string) : file path to user specified distribution data</span> </span><span class="r"></span></p>
<p id="t800" class="pln"><span class="n"><a href="#t800">800</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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="pln"><span class="n"><a href="#t802">802</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t803" class="pln"><span class="n"><a href="#t803">803</a></span><span class="t"><span class="str"> A dictionary of the distribution of school sizes by bracket.</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 class="str"> """</span> </span><span class="r"></span></p>
<p id="t805" class="pln"><span class="n"><a href="#t805">805</a></span><span class="t"> <span class="com"># create size distribution from enrollment counts</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">if</span> <span class="nam">counts_available</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="key">try</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">df</span> <span class="op">=</span> <span class="nam">get_school_sizes_df</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><span class="r"></span></p>
<p id="t809" class="mis show_mis"><span class="n"><a href="#t809">809</a></span><span class="t"> <span class="key">except</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">if</span> <span class="nam">use_default</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">df</span> <span class="op">=</span> <span class="nam">get_school_sizes_df</span><span class="op">(</span><span class="nam">datadir</span><span class="op">,</span> <span class="nam">use_default</span><span class="op">=</span><span class="nam">use_default</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t812" class="pln"><span class="n"><a href="#t812">812</a></span><span class="t"> <span class="key">else</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="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t814" class="run"><span class="n"><a href="#t814">814</a></span><span class="t"> <span class="nam">sizes</span> <span class="op">=</span> <span class="nam">df</span><span class="op">.</span><span class="nam">iloc</span><span class="op">[</span><span class="op">:</span><span class="op">,</span> <span class="num">0</span><span class="op">]</span><span class="op">.</span><span class="nam">values</span> </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">size_count</span> <span class="op">=</span> <span class="nam">Counter</span><span class="op">(</span><span class="nam">sizes</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 class="com"># drop school sizes under 2</span> </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="key">for</span> <span class="nam">s</span> <span class="key">in</span> <span class="nam">range</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="t818" class="run"><span class="n"><a href="#t818">818</a></span><span class="t"> <span class="nam">size_count</span><span class="op">.</span><span class="nam">pop</span><span class="op">(</span><span class="nam">s</span><span class="op">,</span> <span class="key">None</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="run"><span class="n"><a href="#t820">820</a></span><span class="t"> <span class="nam">size_brackets</span> <span class="op">=</span> <span class="nam">get_school_size_brackets</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="com"># add option to give input filenames!</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="nam">size_by_bracket_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">size_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t822" class="pln"><span class="n"><a href="#t822">822</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t823" class="run"><span class="n"><a href="#t823">823</a></span><span class="t"> <span class="nam">bracket_count</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="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">size_brackets</span><span class="op">)</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="t824" class="pln"><span class="n"><a href="#t824">824</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t825" class="pln"><span class="n"><a href="#t825">825</a></span><span class="t"> <span class="com"># aggregate the counts by bracket or bins</span> </span><span class="r"></span></p>
<p id="t826" class="run"><span class="n"><a href="#t826">826</a></span><span class="t"> <span class="key">for</span> <span class="nam">s</span> <span class="key">in</span> <span class="nam">size_count</span><span class="op">:</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="key">try</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t828" class="run"><span class="n"><a href="#t828">828</a></span><span class="t"> <span class="nam">b</span> <span class="op">=</span> <span class="nam">size_by_bracket_dic</span><span class="op">[</span><span class="nam">s</span><span class="op">]</span> </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">bracket_count</span><span class="op">[</span><span class="nam">b</span><span class="op">]</span> <span class="op">+=</span> <span class="nam">size_count</span><span class="op">[</span><span class="nam">s</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="key">except</span> <span class="nam">KeyError</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="key">continue</span> </span><span class="r"></span></p>
<p id="t832" class="pln"><span class="n"><a href="#t832">832</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t833" class="run"><span class="n"><a href="#t833">833</a></span><span class="t"> <span class="nam">size_distr</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">norm_dic</span><span class="op">(</span><span class="nam">bracket_count</span><span class="op">)</span> </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"># read in size distribution from data file</span> </span><span class="r"></span></p>
<p id="t835" class="pln"><span class="n"><a href="#t835">835</a></span><span class="t"> <span class="key">else</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">if</span> <span class="nam">file_path</span> <span class="key">is</span> <span class="key">None</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">file_path</span> <span class="op">=</span> <span class="nam">get_school_size_distr_by_brackets_path</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><span class="r"></span></p>
<p id="t838" class="run"><span class="n"><a href="#t838">838</a></span><span class="t"> <span class="key">try</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">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</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="key">except</span><span class="op">:</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="key">if</span> <span class="nam">use_default</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">file_path</span> <span class="op">=</span> <span class="nam">get_school_size_distr_by_brackets_path</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">'seattle_metro'</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="str">'Washington'</span><span class="op">,</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="t843" class="run"><span class="n"><a href="#t843">843</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">pd</span><span class="op">.</span><span class="nam">read_csv</span><span class="op">(</span><span class="nam">file_path</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t844" class="pln"><span class="n"><a href="#t844">844</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t845" class="mis show_mis"><span class="n"><a href="#t845">845</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Data unavailable for the location specified. Please check input strings or set use_default to True to use default values from Seattle, Washington."</span><span class="op">)</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">size_distr</span> <span class="op">=</span> <span class="nam">dict</span><span class="op">(</span><span class="nam">zip</span><span class="op">(</span><span class="nam">df</span><span class="op">.</span><span class="nam">size_bracket</span><span class="op">,</span> <span class="nam">df</span><span class="op">.</span><span class="nam">percent</span><span class="op">)</span><span class="op">)</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">size_distr</span> <span class="op">=</span> <span class="nam">spb</span><span class="op">.</span><span class="nam">norm_dic</span><span class="op">(</span><span class="nam">size_distr</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t848" class="pln"><span class="n"><a href="#t848">848</a></span><span class="t"> </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="key">return</span> <span class="nam">size_distr</span> </span><span class="r"></span></p>
<p id="t850" class="pln"><span class="n"><a href="#t850">850</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t851" class="pln"><span class="n"><a href="#t851">851</a></span><span class="t"> </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="key">def</span> <span class="nam">write_school_size_distr_by_brackets</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="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">counts_available</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="t853" class="pln"><span class="n"><a href="#t853">853</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t854" class="pln"><span class="n"><a href="#t854">854</a></span><span class="t"><span class="str"> Write school size distribution by brackets to file.</span> </span><span class="r"></span></p>
<p id="t855" class="pln"><span class="n"><a href="#t855">855</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t856" class="pln"><span class="n"><a href="#t856">856</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t857" class="pln"><span class="n"><a href="#t857">857</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="t858" class="pln"><span class="n"><a href="#t858">858</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t859" class="pln"><span class="n"><a href="#t859">859</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="t860" class="pln"><span class="n"><a href="#t860">860</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="t861" class="pln"><span class="n"><a href="#t861">861</a></span><span class="t"><span class="str"> counts_available (bool) : if True, a list of school sizes is available and a count of the sizes can be constructed</span> </span><span class="r"></span></p>
<p id="t862" class="pln"><span class="n"><a href="#t862">862</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</span> </span><span class="r"></span></p>
<p id="t863" class="pln"><span class="n"><a href="#t863">863</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t864" class="pln"><span class="n"><a href="#t864">864</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t865" class="pln"><span class="n"><a href="#t865">865</a></span><span class="t"><span class="str"> A dictionary of the distribution of school sizes by bracket.</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 class="str"> """</span> </span><span class="r"></span></p>
<p id="t867" class="pln"><span class="n"><a href="#t867">867</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t868" class="mis show_mis"><span class="n"><a href="#t868">868</a></span><span class="t"> <span class="nam">size_distr</span> <span class="op">=</span> <span class="nam">get_school_size_distr_by_brackets</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 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 class="nam">counts_available</span><span class="op">=</span><span class="nam">counts_available</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t869" class="mis show_mis"><span class="n"><a href="#t869">869</a></span><span class="t"> <span class="nam">sorted_keys</span> <span class="op">=</span> <span class="nam">sorted</span><span class="op">(</span><span class="nam">size_distr</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="t870" class="pln"><span class="n"><a href="#t870">870</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t871" class="mis show_mis"><span class="n"><a href="#t871">871</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><span class="r"></span></p>
<p id="t872" class="mis show_mis"><span class="n"><a href="#t872">872</a></span><span class="t"> <span class="key">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t873" class="mis show_mis"><span class="n"><a href="#t873">873</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t874" class="mis show_mis"><span class="n"><a href="#t874">874</a></span><span class="t"> <span class="key">if</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t875" class="mis show_mis"><span class="n"><a href="#t875">875</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing country_location string. Please check that you have supplied this string."</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t876" class="mis show_mis"><span class="n"><a href="#t876">876</a></span><span class="t"> <span class="key">elif</span> <span class="nam">state_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t877" class="mis show_mis"><span class="n"><a href="#t877">877</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 class="str">'schools'</span><span class="op">,</span> <span class="str">'school_size_distr.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t878" class="mis show_mis"><span class="n"><a href="#t878">878</a></span><span class="t"> <span class="key">elif</span> <span class="nam">location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t879" class="mis show_mis"><span class="n"><a href="#t879">879</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="str">'school_size_distr.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t880" class="pln"><span class="n"><a href="#t880">880</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t881" class="mis show_mis"><span class="n"><a href="#t881">881</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 class="nam">state_location</span><span class="op">,</span> <span class="str">'schools'</span><span class="op">,</span> <span class="nam">location</span> <span class="op">+</span> <span class="str">'_school_size_distr.dat'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t882" class="pln"><span class="n"><a href="#t882">882</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t883" class="mis show_mis"><span class="n"><a href="#t883">883</a></span><span class="t"> <span class="nam">f</span> <span class="op">=</span> <span class="nam">open</span><span class="op">(</span><span class="nam">file_path</span><span class="op">,</span> <span class="str">'w'</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">f</span><span class="op">.</span><span class="nam">write</span><span class="op">(</span><span class="str">'size_bracket,percent\n'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t885" class="mis show_mis"><span class="n"><a href="#t885">885</a></span><span class="t"> <span class="key">for</span> <span class="nam">k</span> <span class="key">in</span> <span class="nam">sorted_keys</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t886" class="mis show_mis"><span class="n"><a href="#t886">886</a></span><span class="t"> <span class="nam">f</span><span class="op">.</span><span class="nam">write</span><span class="op">(</span><span class="nam">str</span><span class="op">(</span><span class="nam">k</span><span class="op">)</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">size_distr</span><span class="op">[</span><span class="nam">k</span><span class="op">]</span><span class="op">)</span> <span class="op">+</span> <span class="str">'\n'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t887" class="mis show_mis"><span class="n"><a href="#t887">887</a></span><span class="t"> <span class="nam">f</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="t888" class="pln"><span class="n"><a href="#t888">888</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t889" class="pln"><span class="n"><a href="#t889">889</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t890" class="pln"><span class="n"><a href="#t890">890</a></span><span class="t"><span class="com"># binning school sizes for Seattle</span> </span><span class="r"></span></p>
<p id="t891" class="run"><span class="n"><a href="#t891">891</a></span><span class="t"><span class="key">def</span> <span class="nam">get_usa_school_sizes_by_bracket</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="op">:</span> </span><span class="r"></span></p>
<p id="t892" class="pln"><span class="n"><a href="#t892">892</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t893" class="pln"><span class="n"><a href="#t893">893</a></span><span class="t"><span class="str"> Get distribution of school sizes by bracket specifically for the US.</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="pln"><span class="n"><a href="#t895">895</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t896" class="pln"><span class="n"><a href="#t896">896</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="t897" class="pln"><span class="n"><a href="#t897">897</a></span><span class="t"><span class="str"> location (string) : name of the location</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 class="str"> state_location (string) : name of the state the location is in</span> </span><span class="r"></span></p>
<p id="t899" class="pln"><span class="n"><a href="#t899">899</a></span><span class="t"><span class="str"> country_location (string) : name of the country the location is in, which should be the 'usa'</span> </span><span class="r"></span></p>
<p id="t900" class="pln"><span class="n"><a href="#t900">900</a></span><span class="t"><span class="str"> size_distr_file_path (string) : file path to user specified gender by age bracket distribution data</span> </span><span class="r"></span></p>
<p id="t901" class="pln"><span class="n"><a href="#t901">901</a></span><span class="t"><span class="str"> use_default (bool) : if True, try to first use the other parameters to find data specific to the location under study, otherwise returns default data drawing from Seattle, Washington.</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="pln"><span class="n"><a href="#t903">903</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t904" class="pln"><span class="n"><a href="#t904">904</a></span><span class="t"><span class="str"> A dictionary of the distribution of school sizes by bracket.</span> </span><span class="r"></span></p>
<p id="t905" class="pln"><span class="n"><a href="#t905">905</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t906" class="mis show_mis"><span class="n"><a href="#t906">906</a></span><span class="t"> <span class="nam">df</span> <span class="op">=</span> <span class="nam">get_school_sizes_df</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><span class="r"></span></p>
<p id="t907" class="mis show_mis"><span class="n"><a href="#t907">907</a></span><span class="t"> <span class="nam">sizes</span> <span class="op">=</span> <span class="nam">df</span><span class="op">.</span><span class="nam">iloc</span><span class="op">[</span><span class="op">:</span><span class="op">,</span> <span class="num">0</span><span class="op">]</span><span class="op">.</span><span class="nam">values</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">size_count</span> <span class="op">=</span> <span class="nam">Counter</span><span class="op">(</span><span class="nam">sizes</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t909" class="pln"><span class="n"><a href="#t909">909</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t910" class="mis show_mis"><span class="n"><a href="#t910">910</a></span><span class="t"> <span class="nam">size_brackets</span> <span class="op">=</span> <span class="nam">get_school_size_brackets</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><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">size_by_bracket_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">size_brackets</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t912" class="pln"><span class="n"><a href="#t912">912</a></span><span class="t"> </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">bracket_count</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="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">size_brackets</span><span class="op">)</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="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="mis show_mis"><span class="n"><a href="#t915">915</a></span><span class="t"> <span class="key">for</span> <span class="nam">s</span> <span class="key">in</span> <span class="nam">size_count</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t916" class="pln"><span class="n"><a href="#t916">916</a></span><span class="t"> <span class="com">#handling small schools below the brackets threshold</span> </span><span class="r"></span></p>
<p id="t917" class="mis show_mis"><span class="n"><a href="#t917">917</a></span><span class="t"> <span class="key">if</span> <span class="nam">s</span> <span class="op"><</span> <span class="nam">min</span><span class="op">(</span><span class="nam">size_by_bracket_dic</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t918" class="mis show_mis"><span class="n"><a href="#t918">918</a></span><span class="t"> <span class="nam">bracket_count</span><span class="op">[</span><span class="nam">size_by_bracket_dic</span><span class="op">[</span><span class="nam">min</span><span class="op">(</span><span class="nam">size_by_bracket_dic</span><span class="op">)</span><span class="op">]</span><span class="op">]</span> <span class="op">+=</span> <span class="nam">size_count</span><span class="op">[</span><span class="nam">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 class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t920" class="mis show_mis"><span class="n"><a href="#t920">920</a></span><span class="t"> <span class="nam">bracket_count</span><span class="op">[</span><span class="nam">size_by_bracket_dic</span><span class="op">[</span><span class="nam">s</span><span class="op">]</span><span class="op">]</span> <span class="op">+=</span> <span class="nam">size_count</span><span class="op">[</span><span class="nam">s</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t921" class="pln"><span class="n"><a href="#t921">921</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t922" class="mis show_mis"><span class="n"><a href="#t922">922</a></span><span class="t"> <span class="nam">count_by_mean</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t923" class="pln"><span class="n"><a href="#t923">923</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t924" class="mis show_mis"><span class="n"><a href="#t924">924</a></span><span class="t"> <span class="key">for</span> <span class="nam">b</span> <span class="key">in</span> <span class="nam">bracket_count</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t925" class="mis show_mis"><span class="n"><a href="#t925">925</a></span><span class="t"> <span class="nam">size</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">np</span><span class="op">.</span><span class="nam">mean</span><span class="op">(</span><span class="nam">size_brackets</span><span class="op">[</span><span class="nam">b</span><span class="op">]</span><span class="op">)</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t926" class="mis show_mis"><span class="n"><a href="#t926">926</a></span><span class="t"> <span class="nam">count_by_mean</span><span class="op">[</span><span class="nam">size</span><span class="op">]</span> <span class="op">=</span> <span class="nam">bracket_count</span><span class="op">[</span><span class="nam">b</span><span class="op">]</span> </span><span class="r"></span></p>
<p id="t927" class="pln"><span class="n"><a href="#t927">927</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t928" class="mis show_mis"><span class="n"><a href="#t928">928</a></span><span class="t"> <span class="key">return</span> <span class="nam">count_by_mean</span> </span><span class="r"></span></p>
<p id="t929" class="pln"><span class="n"><a href="#t929">929</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t930" class="pln"><span class="n"><a href="#t930">930</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t931" class="run"><span class="n"><a href="#t931">931</a></span><span class="t"><span class="key">def</span> <span class="nam">get_employment_rates_path</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="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="op">:</span> </span><span class="r"></span></p>
<p id="t932" class="pln"><span class="n"><a href="#t932">932</a></span><span class="t"> <span class="str">"""</span> </span><span class="r"></span></p>
<p id="t933" class="pln"><span class="n"><a href="#t933">933</a></span><span class="t"><span class="str"> Get file_path for employment rates by age.</span> </span><span class="r"></span></p>
<p id="t934" class="pln"><span class="n"><a href="#t934">934</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t935" class="pln"><span class="n"><a href="#t935">935</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t936" class="pln"><span class="n"><a href="#t936">936</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="t937" class="pln"><span class="n"><a href="#t937">937</a></span><span class="t"><span class="str"> location (string) : name of the location</span> </span><span class="r"></span></p>
<p id="t938" class="pln"><span class="n"><a href="#t938">938</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="t939" class="pln"><span class="n"><a href="#t939">939</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="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="pln"><span class="n"><a href="#t941">941</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t942" class="pln"><span class="n"><a href="#t942">942</a></span><span class="t"><span class="str"> A file path to employment rates by age.</span> </span><span class="r"></span></p>
<p id="t943" class="pln"><span class="n"><a href="#t943">943</a></span><span class="t"><span class="str"> """</span> </span><span class="r"></span></p>
<p id="t944" class="run"><span class="n"><a href="#t944">944</a></span><span class="t"> <span class="nam">levels</span> <span class="op">=</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><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">if</span> <span class="nam">all</span><span class="op">(</span><span class="nam">level</span> <span class="key">is</span> <span class="key">None</span> <span class="key">for</span> <span class="nam">level</span> <span class="key">in</span> <span class="nam">levels</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t946" class="mis show_mis"><span class="n"><a href="#t946">946</a></span><span class="t"> <span class="key">raise</span> <span class="nam">NotImplementedError</span><span class="op">(</span><span class="str">"Missing input strings. Try again."</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">elif</span> <span class="nam">country_location</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>