-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mnt_d_Github_synthpops_synthpops_api_py.html
212 lines (212 loc) · 47.7 KB
/
_mnt_d_Github_synthpops_synthpops_api_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
<!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/api.py: 90%</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/api.py</b> :
<span class="pc_cov">90%</span>
</h1>
<img id="keyboard_icon" src="keybd_closed.png" alt="Show keyboard shortcuts" />
<h2 class="stats">
61 statements
<button type="button" class="run shortkey_r button_toggle_run" title="Toggle lines run">55 run</button>
<button type="button" class="mis show_mis shortkey_m button_toggle_mis" title="Toggle lines missing">6 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">This module provides the layer for communicating with the agent-based model Covasim.</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">sciris</span> <span class="key">as</span> <span class="nam">sc</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">from</span> <span class="op">.</span><span class="nam">config</span> <span class="key">import</span> <span class="nam">logger</span> <span class="key">as</span> <span class="nam">log</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">synthpops</span> <span class="key">as</span> <span class="nam">sp</span> </span><span class="r"></span></p>
<p id="t8" class="pln"><span class="n"><a href="#t8">8</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t9" class="pln"><span class="n"><a href="#t9">9</a></span><span class="t"><span class="com"># Put this here so it's accessible as sp.api.popsize_choices</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="nam">popsize_choices</span> <span class="op">=</span> <span class="op">[</span><span class="num">5000</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t11" class="pln"><span class="n"><a href="#t11">11</a></span><span class="t"> <span class="num">10000</span><span class="op">,</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 class="num">20000</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t13" class="pln"><span class="n"><a href="#t13">13</a></span><span class="t"> <span class="num">50000</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t14" class="pln"><span class="n"><a href="#t14">14</a></span><span class="t"> <span class="num">100000</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="num">120000</span><span class="op">,</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="op">]</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><span class="r"></span></p>
<p id="t19" class="run"><span class="n"><a href="#t19">19</a></span><span class="t"><span class="key">def</span> <span class="nam">make_population</span><span class="op">(</span><span class="nam">n</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">max_contacts</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">generate</span><span class="op">=</span><span class="key">None</span><span class="op">,</span> <span class="nam">with_industry_code</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> <span class="nam">with_facilities</span><span class="op">=</span><span class="key">False</span><span class="op">,</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 class="nam">use_two_group_reduction</span><span class="op">=</span><span class="key">True</span><span class="op">,</span> <span class="nam">average_LTCF_degree</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">ltcf_staff_age_min</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">ltcf_staff_age_max</span><span class="op">=</span><span class="num">60</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t21" class="pln"><span class="n"><a href="#t21">21</a></span><span class="t"> <span class="nam">with_school_types</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> <span class="nam">school_mixing_type</span><span class="op">=</span><span class="str">'random'</span><span class="op">,</span> <span class="nam">average_class_size</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">inter_grade_mixing</span><span class="op">=</span><span class="num">0.1</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t22" class="pln"><span class="n"><a href="#t22">22</a></span><span class="t"> <span class="nam">average_student_teacher_ratio</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">average_teacher_teacher_degree</span><span class="op">=</span><span class="num">3</span><span class="op">,</span> <span class="nam">teacher_age_min</span><span class="op">=</span><span class="num">25</span><span class="op">,</span> <span class="nam">teacher_age_max</span><span class="op">=</span><span class="num">75</span><span class="op">,</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 class="nam">with_non_teaching_staff</span><span class="op">=</span><span class="key">False</span><span class="op">,</span> </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="nam">average_student_all_staff_ratio</span><span class="op">=</span><span class="num">15</span><span class="op">,</span> <span class="nam">average_additional_staff_degree</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">staff_age_min</span><span class="op">=</span><span class="num">20</span><span class="op">,</span> <span class="nam">staff_age_max</span><span class="op">=</span><span class="num">75</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t25" class="pln"><span class="n"><a href="#t25">25</a></span><span class="t"> <span class="nam">rand_seed</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="t26" class="pln"><span class="n"><a href="#t26">26</a></span><span class="t"> <span class="str">'''</span> </span><span class="r"></span></p>
<p id="t27" class="pln"><span class="n"><a href="#t27">27</a></span><span class="t"><span class="str"> Make a full population network including both people (ages, sexes) and contacts using Seattle, Washington cached data.</span> </span><span class="r"></span></p>
<p id="t28" class="pln"><span class="n"><a href="#t28">28</a></span><span class="t"><span class="str"> Args:</span> </span><span class="r"></span></p>
<p id="t29" class="pln"><span class="n"><a href="#t29">29</a></span><span class="t"><span class="str"> n (int) : The number of people to create.</span> </span><span class="r"></span></p>
<p id="t30" class="pln"><span class="n"><a href="#t30">30</a></span><span class="t"><span class="str"> max_contacts (dict) : A dictionary for maximum number of contacts per layer: keys must be "W" (work).</span> </span><span class="r"></span></p>
<p id="t31" class="pln"><span class="n"><a href="#t31">31</a></span><span class="t"><span class="str"> generate (bool) : If True, generate a new population. Else, look for cached population and if those are not available, generate a new population.</span> </span><span class="r"></span></p>
<p id="t32" class="pln"><span class="n"><a href="#t32">32</a></span><span class="t"><span class="str"> with_industry_code (bool) : If True, assign industry codes for workplaces, currently only possible for cached files of populations in the US.</span> </span><span class="r"></span></p>
<p id="t33" class="pln"><span class="n"><a href="#t33">33</a></span><span class="t"><span class="str"> with_facilities (bool) : If True, create long term care facilities, currently only available for locations in the US.</span> </span><span class="r"></span></p>
<p id="t34" class="pln"><span class="n"><a href="#t34">34</a></span><span class="t"><span class="str"> use_two_group_reduction (bool) : If True, create long term care facilities with reduced contacts across both groups.</span> </span><span class="r"></span></p>
<p id="t35" class="pln"><span class="n"><a href="#t35">35</a></span><span class="t"><span class="str"> average_LTCF_degree (float) : default average degree in long term care facilities.</span> </span><span class="r"></span></p>
<p id="t36" class="pln"><span class="n"><a href="#t36">36</a></span><span class="t"><span class="str"> ltcf_staff_age_min (int) : Long term care facility staff minimum age.</span> </span><span class="r"></span></p>
<p id="t37" class="pln"><span class="n"><a href="#t37">37</a></span><span class="t"><span class="str"> ltcf_staff_age_max (int) : Long term care facility staff maximum age.</span> </span><span class="r"></span></p>
<p id="t38" class="pln"><span class="n"><a href="#t38">38</a></span><span class="t"><span class="str"> with_school_types (bool) : If True, creates explicit school types.</span> </span><span class="r"></span></p>
<p id="t39" class="pln"><span class="n"><a href="#t39">39</a></span><span class="t"><span class="str"> school_mixing_type (str or dict) : The mixing type for schools, 'random', 'age_clustered', or 'age_and_class_clustered' if string, and a dictionary of these by school type otherwise.</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"> average_class_size (float) : The average classroom size.</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 class="str"> inter_grade_mixing (float) : The average fraction of mixing between grades in the same school for clustered school mixing types.</span> </span><span class="r"></span></p>
<p id="t42" class="pln"><span class="n"><a href="#t42">42</a></span><span class="t"><span class="str"> average_student_teacher_ratio (float) : The average number of students per teacher.</span> </span><span class="r"></span></p>
<p id="t43" class="pln"><span class="n"><a href="#t43">43</a></span><span class="t"><span class="str"> average_teacher_teacher_degree (float) : The average number of contacts per teacher with other teachers.</span> </span><span class="r"></span></p>
<p id="t44" class="pln"><span class="n"><a href="#t44">44</a></span><span class="t"><span class="str"> teacher_age_min (int) : The minimum age for teachers.</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"> teacher_age_max (int) : The maximum age for teachers.</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"> with_non_teaching_staff (bool) : If True, includes non teaching staff.</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 class="str"> average_student_all_staff_ratio (float) : The average number of students per staff members at school (including both teachers and non teachers).</span> </span><span class="r"></span></p>
<p id="t48" class="pln"><span class="n"><a href="#t48">48</a></span><span class="t"><span class="str"> average_additional_staff_degree (float) : The average number of contacts per additional non teaching staff in schools.</span> </span><span class="r"></span></p>
<p id="t49" class="pln"><span class="n"><a href="#t49">49</a></span><span class="t"><span class="str"> staff_age_min (int) : The minimum age for non teaching staff.</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 class="str"> staff_age_max (int) : The maximum age for non teaching staff.</span> </span><span class="r"></span></p>
<p id="t51" class="pln"><span class="n"><a href="#t51">51</a></span><span class="t"><span class="str"> rand_seed (int) : Start point random sequence is generated from.</span> </span><span class="r"></span></p>
<p id="t52" class="pln"><span class="n"><a href="#t52">52</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t53" class="pln"><span class="n"><a href="#t53">53</a></span><span class="t"><span class="str"> Returns:</span> </span><span class="r"></span></p>
<p id="t54" class="pln"><span class="n"><a href="#t54">54</a></span><span class="t"><span class="str"> network (dict): A dictionary of the full population with ages and connections.</span> </span><span class="r"></span></p>
<p id="t55" class="pln"><span class="n"><a href="#t55">55</a></span><span class="t"><span class="str"> '''</span> </span><span class="r"></span></p>
<p id="t56" class="run"><span class="n"><a href="#t56">56</a></span><span class="t"> <span class="nam">log</span><span class="op">.</span><span class="nam">debug</span><span class="op">(</span><span class="str">'make_population()'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t57" class="pln"><span class="n"><a href="#t57">57</a></span><span class="t"> </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">if</span> <span class="nam">rand_seed</span> <span class="key">is</span> <span class="key">not</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t59" class="run"><span class="n"><a href="#t59">59</a></span><span class="t"> <span class="nam">sp</span><span class="op">.</span><span class="nam">set_seed</span><span class="op">(</span><span class="nam">rand_seed</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t60" class="pln"><span class="n"><a href="#t60">60</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t61" class="run"><span class="n"><a href="#t61">61</a></span><span class="t"> <span class="nam">default_n</span> <span class="op">=</span> <span class="num">10000</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="nam">default_max_contacts</span> <span class="op">=</span> <span class="op">{</span><span class="str">'W'</span><span class="op">:</span> <span class="num">20</span><span class="op">}</span> <span class="com"># this can be anything but should be based on relevant average number of contacts for the population under study</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="run"><span class="n"><a href="#t64">64</a></span><span class="t"> <span class="key">if</span> <span class="nam">n</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t65" class="mis show_mis"><span class="n"><a href="#t65">65</a></span><span class="t"> <span class="nam">n</span> <span class="op">=</span> <span class="nam">default_n</span> </span><span class="r"></span></p>
<p id="t66" class="run"><span class="n"><a href="#t66">66</a></span><span class="t"> <span class="nam">n</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t67" class="pln"><span class="n"><a href="#t67">67</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t68" class="run"><span class="n"><a href="#t68">68</a></span><span class="t"> <span class="key">if</span> <span class="nam">n</span> <span class="key">not</span> <span class="key">in</span> <span class="nam">popsize_choices</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t69" class="run"><span class="n"><a href="#t69">69</a></span><span class="t"> <span class="key">if</span> <span class="nam">generate</span> <span class="key">is</span> <span class="key">False</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t70" class="run"><span class="n"><a href="#t70">70</a></span><span class="t"> <span class="nam">choicestr</span> <span class="op">=</span> <span class="str">', '</span><span class="op">.</span><span class="nam">join</span><span class="op">(</span><span class="op">[</span><span class="nam">str</span><span class="op">(</span><span class="nam">choice</span><span class="op">)</span> <span class="key">for</span> <span class="nam">choice</span> <span class="key">in</span> <span class="nam">popsize_choices</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t71" class="run"><span class="n"><a href="#t71">71</a></span><span class="t"> <span class="nam">errormsg</span> <span class="op">=</span> <span class="str">f'If generate=False, number of people must be one of {choicestr}, not {n}'</span> </span><span class="r"></span></p>
<p id="t72" class="run"><span class="n"><a href="#t72">72</a></span><span class="t"> <span class="key">raise</span> <span class="nam">ValueError</span><span class="op">(</span><span class="nam">errormsg</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t73" class="pln"><span class="n"><a href="#t73">73</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t74" class="run"><span class="n"><a href="#t74">74</a></span><span class="t"> <span class="nam">generate</span> <span class="op">=</span> <span class="key">True</span> <span class="com"># If n not found in popsize_choices and generate was not False, generate a new population.</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><span class="r"></span></p>
<p id="t76" class="pln"><span class="n"><a href="#t76">76</a></span><span class="t"> <span class="com"># Default to False, unless LTCF are requested</span> </span><span class="r"></span></p>
<p id="t77" class="run"><span class="n"><a href="#t77">77</a></span><span class="t"> <span class="key">if</span> <span class="nam">generate</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t78" class="mis show_mis"><span class="n"><a href="#t78">78</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_facilities</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t79" class="mis show_mis"><span class="n"><a href="#t79">79</a></span><span class="t"> <span class="nam">generate</span> <span class="op">=</span> <span class="key">True</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="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t81" class="mis show_mis"><span class="n"><a href="#t81">81</a></span><span class="t"> <span class="nam">generate</span> <span class="op">=</span> <span class="key">False</span> </span><span class="r"></span></p>
<p id="t82" class="pln"><span class="n"><a href="#t82">82</a></span><span class="t"> </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="nam">max_contacts</span> <span class="op">=</span> <span class="nam">sc</span><span class="op">.</span><span class="nam">mergedicts</span><span class="op">(</span><span class="nam">default_max_contacts</span><span class="op">,</span> <span class="nam">max_contacts</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t84" class="pln"><span class="n"><a href="#t84">84</a></span><span class="t"> </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="nam">country_location</span> <span class="op">=</span> <span class="str">'usa'</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">state_location</span> <span class="op">=</span> <span class="str">'Washington'</span> </span><span class="r"></span></p>
<p id="t87" class="run"><span class="n"><a href="#t87">87</a></span><span class="t"> <span class="nam">location</span> <span class="op">=</span> <span class="str">'seattle_metro'</span> </span><span class="r"></span></p>
<p id="t88" class="run"><span class="n"><a href="#t88">88</a></span><span class="t"> <span class="nam">sheet_name</span> <span class="op">=</span> <span class="str">'United States of America'</span> </span><span class="r"></span></p>
<p id="t89" class="pln"><span class="n"><a href="#t89">89</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t90" class="run"><span class="n"><a href="#t90">90</a></span><span class="t"> <span class="nam">options_args</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </span><span class="r"></span></p>
<p id="t91" class="run"><span class="n"><a href="#t91">91</a></span><span class="t"> <span class="nam">options_args</span><span class="op">[</span><span class="str">'use_microstructure'</span><span class="op">]</span> <span class="op">=</span> <span class="key">True</span> </span><span class="r"></span></p>
<p id="t92" class="run"><span class="n"><a href="#t92">92</a></span><span class="t"> <span class="nam">options_args</span><span class="op">[</span><span class="str">'use_industry_code'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">with_industry_code</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">options_args</span><span class="op">[</span><span class="str">'use_long_term_care_facilities'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">with_facilities</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">options_args</span><span class="op">[</span><span class="str">'use_two_group_reduction'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">use_two_group_reduction</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">options_args</span><span class="op">[</span><span class="str">'with_school_types'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">with_school_types</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="nam">options_args</span><span class="op">[</span><span class="str">'with_non_teaching_staff'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">with_non_teaching_staff</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="run"><span class="n"><a href="#t98">98</a></span><span class="t"> <span class="nam">network_distr_args</span> <span class="op">=</span> <span class="op">{</span><span class="op">}</span> </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="nam">network_distr_args</span><span class="op">[</span><span class="str">'Npop'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">int</span><span class="op">(</span><span class="nam">n</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t100" class="pln"><span class="n"><a href="#t100">100</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t101" class="run"><span class="n"><a href="#t101">101</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_LTCF_degree'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">average_LTCF_degree</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="run"><span class="n"><a href="#t103">103</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_class_size'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">average_class_size</span> </span><span class="r"></span></p>
<p id="t104" class="run"><span class="n"><a href="#t104">104</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_student_teacher_ratio'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">average_student_teacher_ratio</span> </span><span class="r"></span></p>
<p id="t105" class="run"><span class="n"><a href="#t105">105</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_teacher_teacher_degree'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">average_teacher_teacher_degree</span> </span><span class="r"></span></p>
<p id="t106" class="run"><span class="n"><a href="#t106">106</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'inter_grade_mixing'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">inter_grade_mixing</span> </span><span class="r"></span></p>
<p id="t107" class="run"><span class="n"><a href="#t107">107</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_student_all_staff_ratio'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">average_student_all_staff_ratio</span> </span><span class="r"></span></p>
<p id="t108" class="run"><span class="n"><a href="#t108">108</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'average_additional_staff_degree'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">average_additional_staff_degree</span> </span><span class="r"></span></p>
<p id="t109" class="run"><span class="n"><a href="#t109">109</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">[</span><span class="str">'school_mixing_type'</span><span class="op">]</span> <span class="op">=</span> <span class="nam">school_mixing_type</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><span class="r"></span></p>
<p id="t111" class="pln"><span class="n"><a href="#t111">111</a></span><span class="t"> <span class="com"># Heavy lift 1: make the contacts and their connections</span> </span><span class="r"></span></p>
<p id="t112" class="run"><span class="n"><a href="#t112">112</a></span><span class="t"> <span class="key">if</span> <span class="key">not</span> <span class="nam">generate</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t113" class="mis show_mis"><span class="n"><a href="#t113">113</a></span><span class="t"> <span class="nam">log</span><span class="op">.</span><span class="nam">debug</span><span class="op">(</span><span class="str">'Not generating a new population'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t114" class="pln"><span class="n"><a href="#t114">114</a></span><span class="t"> <span class="com"># must read in from file, will fail if the data has not yet been generated</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="nam">population</span> <span class="op">=</span> <span class="nam">sp</span><span class="op">.</span><span class="nam">make_contacts</span><span class="op">(</span><span class="nam">location</span><span class="op">=</span><span class="nam">location</span><span class="op">,</span> <span class="nam">state_location</span><span class="op">=</span><span class="nam">state_location</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t116" class="pln"><span class="n"><a href="#t116">116</a></span><span class="t"> <span class="nam">country_location</span><span class="op">=</span><span class="nam">country_location</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">=</span><span class="nam">sheet_name</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t117" class="pln"><span class="n"><a href="#t117">117</a></span><span class="t"> <span class="nam">options_args</span><span class="op">=</span><span class="nam">options_args</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t118" class="pln"><span class="n"><a href="#t118">118</a></span><span class="t"> <span class="nam">network_distr_args</span><span class="op">=</span><span class="nam">network_distr_args</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t119" class="pln"><span class="n"><a href="#t119">119</a></span><span class="t"> <span class="key">else</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="nam">log</span><span class="op">.</span><span class="nam">debug</span><span class="op">(</span><span class="str">'Generating a new population...'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t121" class="run"><span class="n"><a href="#t121">121</a></span><span class="t"> <span class="key">if</span> <span class="nam">with_facilities</span> <span class="key">and</span> <span class="nam">with_industry_code</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t122" class="run"><span class="n"><a href="#t122">122</a></span><span class="t"> <span class="nam">errormsg</span> <span class="op">=</span> <span class="str">f'Requesting both long term care facilities and industries by code is not supported yet.'</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">raise</span> <span class="nam">ValueError</span><span class="op">(</span><span class="nam">errormsg</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t124" class="run"><span class="n"><a href="#t124">124</a></span><span class="t"> <span class="key">elif</span> <span class="nam">with_facilities</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t125" class="run"><span class="n"><a href="#t125">125</a></span><span class="t"> <span class="nam">population</span> <span class="op">=</span> <span class="nam">sp</span><span class="op">.</span><span class="nam">generate_microstructure_with_facilities</span><span class="op">(</span><span class="nam">sp</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">n</span><span class="op">=</span><span class="nam">n</span><span class="op">,</span> <span class="nam">sheet_name</span><span class="op">=</span><span class="nam">sheet_name</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t126" class="pln"><span class="n"><a href="#t126">126</a></span><span class="t"> <span class="nam">use_two_group_reduction</span><span class="op">=</span><span class="nam">use_two_group_reduction</span><span class="op">,</span> <span class="nam">average_LTCF_degree</span><span class="op">=</span><span class="nam">average_LTCF_degree</span><span class="op">,</span> <span class="nam">ltcf_staff_age_min</span><span class="op">=</span><span class="nam">ltcf_staff_age_min</span><span class="op">,</span> <span class="nam">ltcf_staff_age_max</span><span class="op">=</span><span class="nam">ltcf_staff_age_max</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="nam">with_school_types</span><span class="op">=</span><span class="nam">with_school_types</span><span class="op">,</span> <span class="nam">school_mixing_type</span><span class="op">=</span><span class="nam">school_mixing_type</span><span class="op">,</span> <span class="nam">average_class_size</span><span class="op">=</span><span class="nam">average_class_size</span><span class="op">,</span> <span class="nam">inter_grade_mixing</span><span class="op">=</span><span class="nam">inter_grade_mixing</span><span class="op">,</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="nam">average_student_teacher_ratio</span><span class="op">=</span><span class="nam">average_student_teacher_ratio</span><span class="op">,</span> <span class="nam">average_teacher_teacher_degree</span><span class="op">=</span><span class="nam">average_teacher_teacher_degree</span><span class="op">,</span> <span class="nam">teacher_age_min</span><span class="op">=</span><span class="nam">teacher_age_min</span><span class="op">,</span> <span class="nam">teacher_age_max</span><span class="op">=</span><span class="nam">teacher_age_max</span><span class="op">,</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="nam">average_student_all_staff_ratio</span><span class="op">=</span><span class="nam">average_student_all_staff_ratio</span><span class="op">,</span> <span class="nam">average_additional_staff_degree</span><span class="op">=</span><span class="nam">average_additional_staff_degree</span><span class="op">,</span> <span class="nam">staff_age_min</span><span class="op">=</span><span class="nam">staff_age_min</span><span class="op">,</span> <span class="nam">staff_age_max</span><span class="op">=</span><span class="nam">staff_age_max</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t130" class="pln"><span class="n"><a href="#t130">130</a></span><span class="t"> <span class="nam">return_popdict</span><span class="op">=</span><span class="key">True</span> <span class="op">)</span> </span><span class="r"></span></p>
<p id="t131" class="pln"><span class="n"><a href="#t131">131</a></span><span class="t"> <span class="key">else</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t132" class="run"><span class="n"><a href="#t132">132</a></span><span class="t"> <span class="nam">population</span> <span class="op">=</span> <span class="nam">sp</span><span class="op">.</span><span class="nam">generate_synthetic_population</span><span class="op">(</span><span class="nam">n</span><span class="op">,</span> <span class="nam">sp</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">sheet_name</span><span class="op">=</span><span class="nam">sheet_name</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t133" class="pln"><span class="n"><a href="#t133">133</a></span><span class="t"> <span class="nam">with_school_types</span><span class="op">=</span><span class="nam">with_school_types</span><span class="op">,</span> <span class="nam">school_mixing_type</span><span class="op">=</span><span class="nam">school_mixing_type</span><span class="op">,</span> <span class="nam">average_class_size</span><span class="op">=</span><span class="nam">average_class_size</span><span class="op">,</span> <span class="nam">inter_grade_mixing</span><span class="op">=</span><span class="nam">inter_grade_mixing</span><span class="op">,</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="nam">average_student_teacher_ratio</span><span class="op">=</span><span class="nam">average_student_teacher_ratio</span><span class="op">,</span> <span class="nam">average_teacher_teacher_degree</span><span class="op">=</span><span class="nam">average_teacher_teacher_degree</span><span class="op">,</span> <span class="nam">teacher_age_min</span><span class="op">=</span><span class="nam">teacher_age_min</span><span class="op">,</span> <span class="nam">teacher_age_max</span><span class="op">=</span><span class="nam">teacher_age_max</span><span class="op">,</span> </span><span class="r"></span></p>
<p id="t135" class="pln"><span class="n"><a href="#t135">135</a></span><span class="t"> <span class="nam">average_student_all_staff_ratio</span><span class="op">=</span><span class="nam">average_student_all_staff_ratio</span><span class="op">,</span> <span class="nam">average_additional_staff_degree</span><span class="op">=</span><span class="nam">average_additional_staff_degree</span><span class="op">,</span> <span class="nam">staff_age_min</span><span class="op">=</span><span class="nam">staff_age_min</span><span class="op">,</span> <span class="nam">staff_age_max</span><span class="op">=</span><span class="nam">staff_age_max</span><span class="op">,</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="nam">return_popdict</span><span class="op">=</span><span class="key">True</span><span class="op">,</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="op">)</span> </span><span class="r"></span></p>
<p id="t138" class="pln"><span class="n"><a href="#t138">138</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t139" class="pln"><span class="n"><a href="#t139">139</a></span><span class="t"> <span class="com"># Semi-heavy-lift 2: trim them to the desired numbers</span> </span><span class="r"></span></p>
<p id="t140" class="run"><span class="n"><a href="#t140">140</a></span><span class="t"> <span class="nam">population</span> <span class="op">=</span> <span class="nam">sp</span><span class="op">.</span><span class="nam">trim_contacts</span><span class="op">(</span><span class="nam">population</span><span class="op">,</span> <span class="nam">trimmed_size_dic</span><span class="op">=</span><span class="nam">max_contacts</span><span class="op">,</span> <span class="nam">use_clusters</span><span class="op">=</span><span class="key">False</span><span class="op">)</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="com"># Change types</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">for</span> <span class="nam">key</span><span class="op">,</span> <span class="nam">person</span> <span class="key">in</span> <span class="nam">population</span><span class="op">.</span><span class="nam">items</span><span class="op">(</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t144" class="run"><span class="n"><a href="#t144">144</a></span><span class="t"> <span class="key">for</span> <span class="nam">layerkey</span> <span class="key">in</span> <span class="nam">population</span><span class="op">[</span><span class="nam">key</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">.</span><span class="nam">keys</span><span class="op">(</span><span class="op">)</span><span class="op">:</span> </span><span class="r"></span></p>
<p id="t145" class="run"><span class="n"><a href="#t145">145</a></span><span class="t"> <span class="nam">population</span><span class="op">[</span><span class="nam">key</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">layerkey</span><span class="op">]</span> <span class="op">=</span> <span class="nam">list</span><span class="op">(</span><span class="nam">population</span><span class="op">[</span><span class="nam">key</span><span class="op">]</span><span class="op">[</span><span class="str">'contacts'</span><span class="op">]</span><span class="op">[</span><span class="nam">layerkey</span><span class="op">]</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t146" class="pln"><span class="n"><a href="#t146">146</a></span><span class="t"> </span><span class="r"></span></p>
<p id="t147" class="run"><span class="n"><a href="#t147">147</a></span><span class="t"> <span class="nam">log</span><span class="op">.</span><span class="nam">debug</span><span class="op">(</span><span class="str">'make_population(): done.'</span><span class="op">)</span> </span><span class="r"></span></p>
<p id="t148" class="run"><span class="n"><a href="#t148">148</a></span><span class="t"> <span class="key">return</span> <span class="nam">population</span> </span><span class="r"></span></p>
</div>
<div id="footer">
<div class="content">
<p>
<a class="nav" href="index.html">« index</a> <a class="nav" href="https://coverage.readthedocs.io">coverage.py v5.3</a>,
created at 2020-10-05 17:01 -0700
</p>
</div>
</div>
</body>
</html>