SerializedPopulation
Class to load and manipulate a saved population.
SerializedPopulation
Opens the passed file and reads in all the nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
str
|
serialized population file |
required |
Examples:
Create an instance of SerializedPopulation::
1 2 |
|
Source code in emod_api/serialization/SerializedPopulation.py
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 |
|
nodes
property
All nodes.
Examples:
Delete number_of_ind individuals from node 0::
1 2 |
|
Only keep individuals with a certain condition::
1 |
|
Change susceptibility of an individual::
1 2 3 |
|
Copy individual[0] from node 0, change properties and add individual as new individual::
1 2 3 4 5 6 |
|
Infect an individual with an infection copied from another individual::
1 2 3 4 |
|
flush()
Save all made changes to the node(s).
Source code in emod_api/serialization/SerializedPopulation.py
70 71 72 73 |
|
get_next_individual_suid(node_id)
Each individual needs a unique identifier, this function returns one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
int
|
The first parameter. |
required |
Returns:
Type | Description |
---|---|
dict
|
The return value. True for success, False otherwise. |
Examples:
To get a unique id for an individual::
1 2 |
|
Source code in emod_api/serialization/SerializedPopulation.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
get_next_infection_suid()
Each infection needs a unique identifier, this function returns one.
Source code in emod_api/serialization/SerializedPopulation.py
89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
write(output_file='my_sp_file.dtk')
Write the population to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_file
|
str
|
output file |
'my_sp_file.dtk'
|
Source code in emod_api/serialization/SerializedPopulation.py
75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
find(name, handle, currentlevel='dtk.nodes')
Recursively searches for a paramters that matches or is close to name and prints out where to find it in the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
the paramter you are looking for e.g. "age", "gender". |
required |
handle
|
Union[str, Iterable]
|
some iterable data structure, can be a list of nodes, a node, list of individuals, etc |
required |
currentlevel
|
str
|
just a string to print out where the found item is located e.g. "dtk.nodes" or "dtk.node.individuals" |
'dtk.nodes'
|
Examples:
What is the exact paramteter name used for the age of an individual?::
1 2 3 4 5 6 7 |
|
Source code in emod_api/serialization/SerializedPopulation.py
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 |
|
get_parameters(handle, currentlevel='dtk.nodes')
Return a set of all parameters in the serialized population file. Helpful to get an overview about what is in the serialized population file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handle
|
Union[str, Iterable]
|
some iterable data structure, can be a list of nodes, a node, list of individuals, etc |
required |
currentlevel
|
str
|
just a string to print out where the found item is located e.g. "dtk.nodes" or "dtk.node.individuals |
'dtk.nodes'
|
Examples:
Print all parameters in serialized population file::
1 2 |
|
Source code in emod_api/serialization/SerializedPopulation.py
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 |
|