emod-api 3.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- emod_api/__init__.py +1 -0
- emod_api/campaign.py +170 -0
- emod_api/channelreports/__init__.py +0 -0
- emod_api/channelreports/channels.py +433 -0
- emod_api/channelreports/icj_to_csv.py +65 -0
- emod_api/channelreports/plot_icj_means.py +149 -0
- emod_api/channelreports/plot_prop_report.py +205 -0
- emod_api/channelreports/utils.py +326 -0
- emod_api/config/__init__.py +0 -0
- emod_api/config/default_from_schema.py +16 -0
- emod_api/config/default_from_schema_no_validation.py +177 -0
- emod_api/config/from_overrides.py +135 -0
- emod_api/demographics/__init__.py +0 -0
- emod_api/demographics/age_distribution.py +163 -0
- emod_api/demographics/base_input_file.py +28 -0
- emod_api/demographics/calculators.py +159 -0
- emod_api/demographics/demographic_exceptions.py +54 -0
- emod_api/demographics/demographics.py +249 -0
- emod_api/demographics/demographics_base.py +752 -0
- emod_api/demographics/demographics_overlay.py +41 -0
- emod_api/demographics/fertility_distribution.py +235 -0
- emod_api/demographics/implicit_functions.py +112 -0
- emod_api/demographics/mortality_distribution.py +227 -0
- emod_api/demographics/node.py +456 -0
- emod_api/demographics/overlay_node.py +16 -0
- emod_api/demographics/properties_and_attributes.py +737 -0
- emod_api/demographics/service/__init__.py +0 -0
- emod_api/demographics/service/grid_construction.py +143 -0
- emod_api/demographics/service/service.py +55 -0
- emod_api/demographics/susceptibility_distribution.py +170 -0
- emod_api/demographics/updateable.py +58 -0
- emod_api/legacy/__init__.py +0 -0
- emod_api/legacy/plotAllCharts.py +230 -0
- emod_api/migration/__init__.py +0 -0
- emod_api/migration/__main__.py +22 -0
- emod_api/migration/migration.py +782 -0
- emod_api/multidim_plotter.py +80 -0
- emod_api/schema_to_class.py +440 -0
- emod_api/serialization/__init__.py +0 -0
- emod_api/serialization/census_and_mod_pop.py +48 -0
- emod_api/serialization/dtk_file_support.py +61 -0
- emod_api/serialization/dtk_file_tools.py +1378 -0
- emod_api/serialization/dtk_file_utility.py +141 -0
- emod_api/serialization/serialized_population.py +205 -0
- emod_api/spatialreports/__init__.py +0 -0
- emod_api/spatialreports/__main__.py +67 -0
- emod_api/spatialreports/plot_spat_means.py +99 -0
- emod_api/spatialreports/spatial.py +210 -0
- emod_api/utils/__init__.py +26 -0
- emod_api/utils/distributions/__init__.py +0 -0
- emod_api/utils/distributions/base_distribution.py +38 -0
- emod_api/utils/distributions/bimodal_distribution.py +64 -0
- emod_api/utils/distributions/constant_distribution.py +58 -0
- emod_api/utils/distributions/demographic_distribution_flag.py +16 -0
- emod_api/utils/distributions/distribution_type.py +15 -0
- emod_api/utils/distributions/dual_constant_distribution.py +68 -0
- emod_api/utils/distributions/dual_exponential_distribution.py +75 -0
- emod_api/utils/distributions/exponential_distribution.py +63 -0
- emod_api/utils/distributions/gaussian_distribution.py +69 -0
- emod_api/utils/distributions/log_normal_distribution.py +61 -0
- emod_api/utils/distributions/poisson_distribution.py +59 -0
- emod_api/utils/distributions/uniform_distribution.py +70 -0
- emod_api/utils/distributions/weibull_distribution.py +69 -0
- emod_api/utils/str_enum.py +6 -0
- emod_api/weather/__init__.py +0 -0
- emod_api/weather/weather.py +428 -0
- emod_api-3.0.2.dist-info/METADATA +131 -0
- emod_api-3.0.2.dist-info/RECORD +71 -0
- emod_api-3.0.2.dist-info/WHEEL +5 -0
- emod_api-3.0.2.dist-info/licenses/LICENSE +21 -0
- emod_api-3.0.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
from collections import Counter
|
|
3
|
+
from functools import partial
|
|
4
|
+
from collections.abc import Iterable
|
|
5
|
+
from typing import Union, Optional, Callable
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pandas as pd
|
|
9
|
+
from sklearn.pipeline import make_pipeline
|
|
10
|
+
from sklearn.preprocessing import StandardScaler
|
|
11
|
+
|
|
12
|
+
from emod_api.demographics.age_distribution import AgeDistribution
|
|
13
|
+
from emod_api.demographics.base_input_file import BaseInputFile
|
|
14
|
+
from emod_api.demographics.fertility_distribution import FertilityDistribution
|
|
15
|
+
from emod_api.demographics.mortality_distribution import MortalityDistribution
|
|
16
|
+
from emod_api.demographics.node import Node
|
|
17
|
+
from emod_api.demographics.demographic_exceptions import InvalidNodeIdException
|
|
18
|
+
from emod_api.demographics.properties_and_attributes import IndividualProperty
|
|
19
|
+
from emod_api.demographics.susceptibility_distribution import SusceptibilityDistribution
|
|
20
|
+
from emod_api.utils.distributions.base_distribution import BaseDistribution
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class DemographicsBase(BaseInputFile):
|
|
24
|
+
"""
|
|
25
|
+
Base class for :py:obj:`emod_api:emod_api.demographics.Demographics` and
|
|
26
|
+
:py:obj:`emod_api:emod_api.demographics.DemographicsOverlay`.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
DEFAULT_NODE_NAME = 'default_node'
|
|
30
|
+
|
|
31
|
+
class UnknownNodeException(ValueError):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
class DuplicateNodeIdException(Exception):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
class DuplicateNodeNameException(Exception):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
def __init__(self, nodes: list[Node], idref: str = None, default_node: Node = None):
|
|
41
|
+
"""
|
|
42
|
+
Passed-in default nodes are optional. If one is not passed in, one will be created.
|
|
43
|
+
"""
|
|
44
|
+
super().__init__(idref=idref)
|
|
45
|
+
self.nodes = nodes
|
|
46
|
+
self.implicits = list()
|
|
47
|
+
self.migration_files = list()
|
|
48
|
+
|
|
49
|
+
# verify that the provided non-default nodes have ids > 0
|
|
50
|
+
for node in self.nodes:
|
|
51
|
+
if node.id <= 0:
|
|
52
|
+
raise InvalidNodeIdException(f"Non-default nodes must have integer ids > 0 . Found id: {node.id}")
|
|
53
|
+
|
|
54
|
+
# Build the default node if not provided and then perform some setup/verification
|
|
55
|
+
default_node = self._generate_default_node() if default_node is None else default_node
|
|
56
|
+
self.default_node = default_node
|
|
57
|
+
self.default_node.name = self.DEFAULT_NODE_NAME
|
|
58
|
+
if self.default_node.id != 0:
|
|
59
|
+
raise InvalidNodeIdException(f"Default nodes must have an id of 0. It is {self.default_node.id} .")
|
|
60
|
+
self.metadata = self.generate_headers()
|
|
61
|
+
# TODO: remove the following setting of birth_rate on the default node once this EMOD binary issue is fixed
|
|
62
|
+
# https://github.com/InstituteforDiseaseModeling/DtkTrunk/issues/4009
|
|
63
|
+
if self.default_node.birth_rate is None:
|
|
64
|
+
self.default_node.birth_rate = 0
|
|
65
|
+
|
|
66
|
+
# enforce unique node ids and names
|
|
67
|
+
self.verify_demographics_integrity()
|
|
68
|
+
|
|
69
|
+
def _generate_default_node(self) -> Node:
|
|
70
|
+
default_node = Node(lat=0, lon=0, pop=0, name=self.DEFAULT_NODE_NAME, forced_id=0)
|
|
71
|
+
# TODO: remove the following setting of birth_rate on the default node once this EMOD binary issue is fixed
|
|
72
|
+
# https://github.com/InstituteforDiseaseModeling/DtkTrunk/issues/4009
|
|
73
|
+
default_node.birth_rate = 0
|
|
74
|
+
return default_node
|
|
75
|
+
|
|
76
|
+
def apply_overlay(self, overlay_nodes: list[Node]) -> None:
|
|
77
|
+
"""
|
|
78
|
+
Overlays a set of nodes onto the demographics object. Only overlay nodes with ids matching current demographic
|
|
79
|
+
node_ids will be overlayed (extending/overriding exisiting node data).
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
overlay_nodes (list[Node]): a list of Node objects that will overlay/override data in the demographics
|
|
83
|
+
object.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
Nothing
|
|
87
|
+
"""
|
|
88
|
+
existing_nodes_by_id = self._all_nodes_by_id
|
|
89
|
+
for overlay_node in overlay_nodes:
|
|
90
|
+
if overlay_node.id in existing_nodes_by_id:
|
|
91
|
+
self.get_node_by_id(node_id=overlay_node.id).update(overlay_node)
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def node_ids(self):
|
|
95
|
+
"""
|
|
96
|
+
Return the list of (geographic) node ids.
|
|
97
|
+
"""
|
|
98
|
+
return [node.id for node in self.nodes]
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def node_count(self):
|
|
102
|
+
"""
|
|
103
|
+
Return the number of (geographic) nodes.
|
|
104
|
+
"""
|
|
105
|
+
message = "node_count is a deprecated property of Node objects, use len(demog.nodes) instead."
|
|
106
|
+
warnings.warn(message=message, category=DeprecationWarning, stacklevel=2)
|
|
107
|
+
return len(self.nodes)
|
|
108
|
+
|
|
109
|
+
def get_node(self, nodeid: int) -> Node:
|
|
110
|
+
"""
|
|
111
|
+
Return the node with node.id equal to nodeid.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
nodeid: an id to use in retrieving the requested Node object. None or 0 for 'the default node'.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
a Node object
|
|
118
|
+
"""
|
|
119
|
+
message = "get_node() is a deprecated function of Node objects, use get_node_by_id() instead. " \
|
|
120
|
+
"(For example, demographics.get_node_by_id(node_id=4))"
|
|
121
|
+
warnings.warn(message=message, category=DeprecationWarning, stacklevel=2)
|
|
122
|
+
return self.get_node_by_id(node_id=nodeid)
|
|
123
|
+
|
|
124
|
+
def verify_demographics_integrity(self):
|
|
125
|
+
"""
|
|
126
|
+
One stop shopping for making sure a demographics object doesn't have known invalid settings.
|
|
127
|
+
"""
|
|
128
|
+
self._verify_node_id_uniqueness()
|
|
129
|
+
self._verify_node_name_uniqueness()
|
|
130
|
+
|
|
131
|
+
@staticmethod
|
|
132
|
+
def _duplicates_check(items: Iterable) -> list:
|
|
133
|
+
"""
|
|
134
|
+
Simple function that detects and returns the duplicates in an provide iterable.
|
|
135
|
+
Args:
|
|
136
|
+
items: a collection of items to search for duplicates
|
|
137
|
+
|
|
138
|
+
Returns: a list of duplicated items from the provided list
|
|
139
|
+
"""
|
|
140
|
+
usage_count = Counter(items)
|
|
141
|
+
return [item for item in usage_count.keys() if usage_count[item] > 1]
|
|
142
|
+
|
|
143
|
+
def _verify_node_id_uniqueness(self):
|
|
144
|
+
nodes = self._all_nodes
|
|
145
|
+
node_ids = [node.id for node in nodes]
|
|
146
|
+
duplicate_items = self._duplicates_check(items=node_ids)
|
|
147
|
+
if len(duplicate_items) > 0:
|
|
148
|
+
duplicate_items_str = [str(item) for item in duplicate_items]
|
|
149
|
+
duplicates_str = ", ".join(duplicate_items_str)
|
|
150
|
+
raise self.DuplicateNodeIdException(f"Duplicate node ids detected: {duplicates_str}")
|
|
151
|
+
|
|
152
|
+
def _verify_node_name_uniqueness(self):
|
|
153
|
+
nodes = self._all_nodes
|
|
154
|
+
node_names = [node.name for node in nodes]
|
|
155
|
+
duplicate_items = self._duplicates_check(items=node_names)
|
|
156
|
+
if len(duplicate_items) > 0:
|
|
157
|
+
duplicate_items_str = [str(item) for item in duplicate_items]
|
|
158
|
+
duplicates_str = ", ".join(duplicate_items_str)
|
|
159
|
+
raise self.DuplicateNodeNameException(f"Duplicate node names detected: {duplicates_str}")
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def _all_nodes(self) -> list[Node]:
|
|
163
|
+
all_nodes = self.nodes + [self.default_node]
|
|
164
|
+
return all_nodes
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def _all_node_names(self) -> list[int]:
|
|
168
|
+
return [node.name for node in self._all_nodes]
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def _all_nodes_by_name(self) -> dict[int, Node]:
|
|
172
|
+
return {node.name: node for node in self._all_nodes}
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def _all_node_ids(self) -> list[int]:
|
|
176
|
+
return [node.id for node in self._all_nodes]
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def _all_nodes_by_id(self) -> dict[int, Node]:
|
|
180
|
+
return {node.id: node for node in self._all_nodes}
|
|
181
|
+
|
|
182
|
+
def get_node_by_id(self, node_id: int) -> Node:
|
|
183
|
+
"""
|
|
184
|
+
Returns the Node object requested by its node id.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
node_id: a node_id to use in retrieving the requested Node object. None or 0 for 'the default node'.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
a Node object
|
|
191
|
+
"""
|
|
192
|
+
return list(self.get_nodes_by_id(node_ids=[node_id]).values())[0]
|
|
193
|
+
|
|
194
|
+
def get_nodes_by_id(self, node_ids: list[int]) -> dict[int, Node]:
|
|
195
|
+
"""
|
|
196
|
+
Returns the Node objects requested by their node id.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
node_ids: a list of node ids to use in retrieving Node objects. None or 0 for 'the default node'.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
a dict with id: node entries
|
|
203
|
+
"""
|
|
204
|
+
# replace a None id (default node) request with 0
|
|
205
|
+
if node_ids is None:
|
|
206
|
+
node_ids = [0]
|
|
207
|
+
if None in node_ids:
|
|
208
|
+
node_ids.remove(None)
|
|
209
|
+
node_ids.append(0)
|
|
210
|
+
|
|
211
|
+
missing_node_ids = [node_id for node_id in node_ids if node_id not in self._all_node_ids]
|
|
212
|
+
if len(missing_node_ids) > 0:
|
|
213
|
+
msg = ', '.join([str(node_id) for node_id in missing_node_ids])
|
|
214
|
+
raise self.UnknownNodeException(f"The following node id(s) were requested but do not exist in this demographics "
|
|
215
|
+
f"object:\n{msg}")
|
|
216
|
+
requested_nodes = {node_id: node for node_id, node in self._all_nodes_by_id.items() if node_id in node_ids}
|
|
217
|
+
return requested_nodes
|
|
218
|
+
|
|
219
|
+
def get_node_by_name(self, node_name: str) -> Node:
|
|
220
|
+
"""
|
|
221
|
+
Returns the Node object requested by its node name.
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
node_name: a node_name to use in retrieving the requested Node object. None for 'the default node'.
|
|
225
|
+
|
|
226
|
+
Returns:
|
|
227
|
+
a Node object
|
|
228
|
+
"""
|
|
229
|
+
return list(self.get_nodes_by_name(node_names=[node_name]).values())[0]
|
|
230
|
+
|
|
231
|
+
def get_nodes_by_name(self, node_names: list[str]) -> dict[str, Node]:
|
|
232
|
+
"""
|
|
233
|
+
Returns the Node objects requested by their node name.
|
|
234
|
+
|
|
235
|
+
Args:
|
|
236
|
+
node_names: a list of node names to use in retrieving Node objects. None for 'the default node'.
|
|
237
|
+
|
|
238
|
+
Returns:
|
|
239
|
+
a dict with name: node entries
|
|
240
|
+
"""
|
|
241
|
+
# replace a None name (default node) request with the default node's name
|
|
242
|
+
if node_names is None:
|
|
243
|
+
node_names = [self.default_node.name]
|
|
244
|
+
if None in node_names:
|
|
245
|
+
node_names.remove(None)
|
|
246
|
+
node_names.append(self.default_node.name)
|
|
247
|
+
|
|
248
|
+
missing_node_names = [node_name for node_name in node_names if node_name not in self._all_node_names]
|
|
249
|
+
if len(missing_node_names) > 0:
|
|
250
|
+
msg = ', '.join([str(node_name) for node_name in missing_node_names])
|
|
251
|
+
raise self.UnknownNodeException(f"The following node name(s) were requested but do not exist in this demographics "
|
|
252
|
+
f"object:\n{msg}")
|
|
253
|
+
requested_nodes = {node_name: node for node_name, node in self._all_nodes_by_name.items()
|
|
254
|
+
if node_name in node_names}
|
|
255
|
+
return requested_nodes
|
|
256
|
+
|
|
257
|
+
def set_demographics_filenames(self, filenames: list[str]):
|
|
258
|
+
"""
|
|
259
|
+
Set paths to demographic file.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
filenames: Paths to demographic files.
|
|
263
|
+
"""
|
|
264
|
+
from emod_api.demographics.implicit_functions import _set_demographic_filenames
|
|
265
|
+
|
|
266
|
+
self.implicits.append(partial(_set_demographic_filenames, filenames=filenames))
|
|
267
|
+
|
|
268
|
+
def infer_natural_mortality(self,
|
|
269
|
+
file_male,
|
|
270
|
+
file_female,
|
|
271
|
+
interval_fit: Optional[list[Union[int, float]]] = None,
|
|
272
|
+
which_point='mid',
|
|
273
|
+
predict_horizon=2050,
|
|
274
|
+
csv_out=False,
|
|
275
|
+
n=0, # I don't know what this means
|
|
276
|
+
results_scale_factor=1.0 / 365.0) -> [dict, dict]:
|
|
277
|
+
"""
|
|
278
|
+
Calculate and set the expected natural mortality by age, sex, and year from data, predicting what it would
|
|
279
|
+
have been without disease (HIV-only).
|
|
280
|
+
"""
|
|
281
|
+
from collections import OrderedDict
|
|
282
|
+
from sklearn.linear_model import LinearRegression
|
|
283
|
+
from functools import reduce
|
|
284
|
+
from emod_api.demographics.implicit_functions import _set_mortality_age_gender_year
|
|
285
|
+
warnings.warn('infer_natural_mortality() is deprecated. Please use modern country model loading.',
|
|
286
|
+
DeprecationWarning, stacklevel=2)
|
|
287
|
+
|
|
288
|
+
if interval_fit is None:
|
|
289
|
+
interval_fit = [1970, 1980]
|
|
290
|
+
|
|
291
|
+
name_conversion_dict = {'Age (x)': 'Age',
|
|
292
|
+
'Central death rate m(x,n)': 'Mortality_mid',
|
|
293
|
+
'Age interval (n)': 'Interval',
|
|
294
|
+
'Period': 'Years'
|
|
295
|
+
}
|
|
296
|
+
sex_dict = {'Male': 0, 'Female': 1}
|
|
297
|
+
|
|
298
|
+
def construct_interval(x, y):
|
|
299
|
+
return x, x + y
|
|
300
|
+
|
|
301
|
+
def midpoint(x, y):
|
|
302
|
+
return (x + y) / 2.0
|
|
303
|
+
|
|
304
|
+
def generate_dict_order(tuple_list, which_entry=1):
|
|
305
|
+
my_unordered_list = tuple_list.apply(lambda x: x[which_entry])
|
|
306
|
+
dict_to_order = OrderedDict(zip(tuple_list, my_unordered_list))
|
|
307
|
+
return dict_to_order
|
|
308
|
+
|
|
309
|
+
def map_year(x_tuple, flag='mid'):
|
|
310
|
+
valid_entries_loc = ['mid', 'end', 'start']
|
|
311
|
+
|
|
312
|
+
if flag not in valid_entries_loc:
|
|
313
|
+
raise ValueError('invalid endpoint specified')
|
|
314
|
+
|
|
315
|
+
if flag == 'mid':
|
|
316
|
+
return (x_tuple[0] + x_tuple[1]) / 2.0
|
|
317
|
+
elif flag == 'start':
|
|
318
|
+
return x_tuple[0]
|
|
319
|
+
else:
|
|
320
|
+
return x_tuple[1]
|
|
321
|
+
|
|
322
|
+
df_mort_male = pd.read_csv(file_male, usecols=name_conversion_dict)
|
|
323
|
+
df_mort_male['Sex'] = 'Male'
|
|
324
|
+
df_mort_female = pd.read_csv(file_female, usecols=name_conversion_dict)
|
|
325
|
+
df_mort_female['Sex'] = 'Female'
|
|
326
|
+
df_mort = pd.concat([df_mort_male, df_mort_female], axis=0)
|
|
327
|
+
df_mort.rename(columns=name_conversion_dict, inplace=True)
|
|
328
|
+
df_mort['Years'] = df_mort['Years'].apply(lambda x: tuple(
|
|
329
|
+
[float(zz) for zz in x.split('-')])) # this might be a bit too format specific (ie dashes in input)
|
|
330
|
+
|
|
331
|
+
# log transform the data and drop unneeded columns
|
|
332
|
+
df_mort['log_Mortality_mid'] = df_mort['Mortality_mid'].apply(lambda x: np.log(x))
|
|
333
|
+
df_mort['Age'] = df_mort[['Age', 'Interval']].apply(lambda zz: construct_interval(*zz), axis=1)
|
|
334
|
+
|
|
335
|
+
year_order_dict = generate_dict_order(df_mort['Years'])
|
|
336
|
+
age_order_dict = generate_dict_order(df_mort['Age'])
|
|
337
|
+
df_mort['sortby2'] = df_mort['Age'].map(age_order_dict)
|
|
338
|
+
df_mort['sortby1'] = df_mort['Sex'].map(sex_dict)
|
|
339
|
+
df_mort['sortby3'] = df_mort['Years'].map(year_order_dict)
|
|
340
|
+
df_mort.sort_values(['sortby1', 'sortby2', 'sortby3'], inplace=True)
|
|
341
|
+
df_mort.drop(columns=['Mortality_mid', 'Interval', 'sortby1', 'sortby2', 'sortby3'], inplace=True)
|
|
342
|
+
|
|
343
|
+
# convert to years (and to string for age_list due to really annoying practical slicing reasons
|
|
344
|
+
df_mort['Years'] = df_mort['Years'].apply(lambda x: map_year(x, which_point))
|
|
345
|
+
df_mort['Age'] = df_mort['Age'].apply(lambda x: str(x))
|
|
346
|
+
df_before_time = df_mort[df_mort['Years'].between(0, interval_fit[0])].copy()
|
|
347
|
+
|
|
348
|
+
df_mort.set_index(['Sex', 'Age'], inplace=True)
|
|
349
|
+
sex_list = list(set(df_mort.index.get_level_values('Sex')))
|
|
350
|
+
age_list = list(set(df_mort.index.get_level_values('Age')))
|
|
351
|
+
|
|
352
|
+
df_list = []
|
|
353
|
+
for sex in sex_list:
|
|
354
|
+
for age in age_list:
|
|
355
|
+
tmp_data = df_mort.loc[(sex, age, slice(None)), :]
|
|
356
|
+
extrap_model = make_pipeline(StandardScaler(with_mean=False), LinearRegression())
|
|
357
|
+
|
|
358
|
+
first_extrap_df = tmp_data[tmp_data['Years'].between(interval_fit[0], interval_fit[1])]
|
|
359
|
+
xx = tmp_data[tmp_data['Years'].between(interval_fit[0], predict_horizon)].values[:, 0]
|
|
360
|
+
|
|
361
|
+
values = first_extrap_df.values
|
|
362
|
+
extrap_model.fit(values[:, 0].reshape(-1, 1), values[:, 1])
|
|
363
|
+
|
|
364
|
+
extrap_predictions = extrap_model.predict(xx.reshape(-1, 1))
|
|
365
|
+
|
|
366
|
+
loc_df = pd.DataFrame.from_dict({'Sex': sex, 'Age': age, 'Years': xx, 'Extrap': extrap_predictions})
|
|
367
|
+
loc_df.set_index(['Sex', 'Age', 'Years'], inplace=True)
|
|
368
|
+
|
|
369
|
+
df_list.append(loc_df.copy())
|
|
370
|
+
|
|
371
|
+
df_e1 = pd.concat(df_list, axis=0)
|
|
372
|
+
|
|
373
|
+
df_list_final = [df_mort, df_e1]
|
|
374
|
+
df_total = reduce(lambda left, right: pd.merge(left, right, on=['Sex', 'Age', 'Years']), df_list_final)
|
|
375
|
+
|
|
376
|
+
df_total = df_total.reset_index(inplace=False).set_index(['Sex', 'Age'], inplace=False)
|
|
377
|
+
|
|
378
|
+
df_total['Extrap'] = df_total['Extrap'].apply(np.exp)
|
|
379
|
+
df_total['Data'] = df_total['log_Mortality_mid'].apply(np.exp)
|
|
380
|
+
df_before_time['Data'] = df_before_time['log_Mortality_mid'].apply(np.exp)
|
|
381
|
+
|
|
382
|
+
df_before_time.set_index(['Sex', 'Age'], inplace=True)
|
|
383
|
+
df_total = pd.concat([df_total, df_before_time], axis=0, join='outer', sort=True)
|
|
384
|
+
|
|
385
|
+
df_total.reset_index(inplace=True)
|
|
386
|
+
df_total['sortby2'] = df_total['Age'].map(age_order_dict)
|
|
387
|
+
df_total['sortby1'] = df_total['Sex'].map(sex_dict)
|
|
388
|
+
df_total.sort_values(by=['sortby1', 'sortby2', 'Years'], inplace=True)
|
|
389
|
+
df_total.drop(columns=['sortby1', 'sortby2'], inplace=True)
|
|
390
|
+
|
|
391
|
+
estimates_list = []
|
|
392
|
+
estimates_list.append(df_total.copy())
|
|
393
|
+
# estimates_list = [df_total.copy()] alternative
|
|
394
|
+
|
|
395
|
+
def min_not_nan(x_list):
|
|
396
|
+
loc_in = list(filter(lambda x: not np.isnan(x), x_list))
|
|
397
|
+
return np.min(loc_in)
|
|
398
|
+
|
|
399
|
+
# This was in another function before
|
|
400
|
+
df = estimates_list[n]
|
|
401
|
+
df['FE'] = df[['Data', 'Extrap']].apply(min_not_nan, axis=1)
|
|
402
|
+
df['Age'] = df['Age'].apply(lambda x: int(x.split(',')[1].split(')')[0]))
|
|
403
|
+
male_df = df[df['Sex'] == 'Male']
|
|
404
|
+
female_df = df[df['Sex'] == 'Female']
|
|
405
|
+
|
|
406
|
+
male_df.set_index(['Sex', 'Age', 'Years'], inplace=True)
|
|
407
|
+
female_df.set_index(['Sex', 'Age', 'Years'], inplace=True)
|
|
408
|
+
male_data = male_df['FE']
|
|
409
|
+
female_data = female_df['FE']
|
|
410
|
+
|
|
411
|
+
male_data = male_data.unstack(-1)
|
|
412
|
+
male_data.sort_index(level='Age', inplace=True)
|
|
413
|
+
female_data = female_data.unstack(-1)
|
|
414
|
+
female_data.sort_index(level='Age', inplace=True)
|
|
415
|
+
|
|
416
|
+
years_out_male = list(male_data.columns)
|
|
417
|
+
years_out_female = list(female_data.columns)
|
|
418
|
+
|
|
419
|
+
age_out_male = list(male_data.index.get_level_values('Age'))
|
|
420
|
+
age_out_female = list(male_data.index.get_level_values('Age'))
|
|
421
|
+
|
|
422
|
+
male_output = male_data.values
|
|
423
|
+
female_output = female_data.values
|
|
424
|
+
|
|
425
|
+
if csv_out:
|
|
426
|
+
male_data.to_csv(f'Male{csv_out}')
|
|
427
|
+
female_data.to_csv(f'Female{csv_out}')
|
|
428
|
+
|
|
429
|
+
# TBD: This is the part that should use base file functionality
|
|
430
|
+
|
|
431
|
+
dict_female = {'AxisNames': ['age', 'year'],
|
|
432
|
+
'AxisScaleFactors': [365.0, 1],
|
|
433
|
+
'AxisUnits': ['years', 'years'],
|
|
434
|
+
'PopulationGroups': [age_out_female, years_out_female],
|
|
435
|
+
'ResultScaleFactor': results_scale_factor,
|
|
436
|
+
'ResultUnits': 'annual deaths per capita',
|
|
437
|
+
'ResultValues': female_output.tolist()
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
dict_male = {'AxisNames': ['age', 'year'],
|
|
441
|
+
'AxisScaleFactors': [365.0, 1],
|
|
442
|
+
'AxisUnits': ['years', 'years'],
|
|
443
|
+
'PopulationGroups': [age_out_male, years_out_male],
|
|
444
|
+
'ResultScaleFactor': results_scale_factor,
|
|
445
|
+
'ResultUnits': 'annual deaths per capita',
|
|
446
|
+
'ResultValues': male_output.tolist()
|
|
447
|
+
}
|
|
448
|
+
self.implicits.append(_set_mortality_age_gender_year)
|
|
449
|
+
return dict_female, dict_male
|
|
450
|
+
|
|
451
|
+
def to_dict(self) -> dict:
|
|
452
|
+
self.verify_demographics_integrity()
|
|
453
|
+
demographics_dict = {
|
|
454
|
+
'Defaults': self.default_node.to_dict(),
|
|
455
|
+
'Nodes': [node.to_dict() for node in self.nodes],
|
|
456
|
+
'Metadata': self.metadata
|
|
457
|
+
}
|
|
458
|
+
demographics_dict["Metadata"]["NodeCount"] = len(self.nodes)
|
|
459
|
+
return demographics_dict
|
|
460
|
+
|
|
461
|
+
def set_birth_rate(self, rate: float, node_ids: list[int] = None):
|
|
462
|
+
"""
|
|
463
|
+
Sets a specified population-dependent birth rate value on the target node(s). Automatically handles any
|
|
464
|
+
necessary config updates.
|
|
465
|
+
|
|
466
|
+
Args:
|
|
467
|
+
rate: (float) The birth rate to set in units of births/year/1000-women
|
|
468
|
+
node_ids: (list[int]) The node id(s) to apply changes to. None or 0 means the default node.
|
|
469
|
+
|
|
470
|
+
Returns:
|
|
471
|
+
|
|
472
|
+
"""
|
|
473
|
+
from emod_api.demographics.implicit_functions import _set_population_dependent_birth_rate
|
|
474
|
+
|
|
475
|
+
rate = rate / 365 / 1000 # converting to births/day/woman, which is what EMOD internally uses.
|
|
476
|
+
nodes = self.get_nodes_by_id(node_ids=node_ids)
|
|
477
|
+
for _, node in nodes.items():
|
|
478
|
+
node.birth_rate = rate
|
|
479
|
+
self.implicits.append(_set_population_dependent_birth_rate)
|
|
480
|
+
|
|
481
|
+
#
|
|
482
|
+
# These distribution setters accept either a simple or complex distribution
|
|
483
|
+
#
|
|
484
|
+
|
|
485
|
+
def set_age_distribution(self,
|
|
486
|
+
distribution: Union[BaseDistribution, AgeDistribution],
|
|
487
|
+
node_ids: list[int] = None) -> None:
|
|
488
|
+
"""
|
|
489
|
+
Set the distribution from which the initial ages of the population will be drawn. At initialization, each person
|
|
490
|
+
will be randomly assigned an age from the given distribution. Automatically handles any necessary config
|
|
491
|
+
updates.
|
|
492
|
+
|
|
493
|
+
Args:
|
|
494
|
+
distribution: The distribution to set. Can either be a BaseDistribution object for a simple distribution
|
|
495
|
+
or AgeDistribution object for complex.
|
|
496
|
+
node_ids: The node id(s) to apply changes to. None or 0 means the default node.
|
|
497
|
+
|
|
498
|
+
Returns:
|
|
499
|
+
Nothing
|
|
500
|
+
"""
|
|
501
|
+
from emod_api.demographics.implicit_functions import _set_age_simple, _set_age_complex
|
|
502
|
+
|
|
503
|
+
self._set_distribution(distribution=distribution,
|
|
504
|
+
use_case='age',
|
|
505
|
+
simple_distribution_implicits=[_set_age_simple],
|
|
506
|
+
complex_distribution_implicits=[_set_age_complex],
|
|
507
|
+
node_ids=node_ids)
|
|
508
|
+
|
|
509
|
+
def set_susceptibility_distribution(self,
|
|
510
|
+
distribution: Union[BaseDistribution, SusceptibilityDistribution],
|
|
511
|
+
node_ids: list[int] = None) -> None:
|
|
512
|
+
"""
|
|
513
|
+
Set a distribution that will impact the probability that a person will acquire an infection based on immunity.
|
|
514
|
+
The SusceptibilityDistribution is used to define an age-based distribution from which a probability is selected
|
|
515
|
+
to determine if a person is susceptible or not. The older ages of the distribution are only used during
|
|
516
|
+
initialization. Automatically handles any necessary config updates. Susceptibility distributions are NOT
|
|
517
|
+
compatible or supported for Malaria or HIV simulations.
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
Args:
|
|
521
|
+
distribution: The distribution to set. Can either be a BaseDistribution object for a simple distribution
|
|
522
|
+
or SusceptibilityDistribution object for complex.
|
|
523
|
+
node_ids: The node id(s) to apply changes to. None or 0 means the default node.
|
|
524
|
+
|
|
525
|
+
Returns:
|
|
526
|
+
Nothing
|
|
527
|
+
"""
|
|
528
|
+
from emod_api.demographics.implicit_functions import _set_suscept_simple, _set_suscept_complex
|
|
529
|
+
|
|
530
|
+
self._set_distribution(distribution=distribution,
|
|
531
|
+
use_case='susceptibility',
|
|
532
|
+
simple_distribution_implicits=[_set_suscept_simple],
|
|
533
|
+
complex_distribution_implicits=[_set_suscept_complex],
|
|
534
|
+
node_ids=node_ids)
|
|
535
|
+
|
|
536
|
+
#
|
|
537
|
+
# These distribution setters only accept simple distributions
|
|
538
|
+
#
|
|
539
|
+
|
|
540
|
+
def set_prevalence_distribution(self,
|
|
541
|
+
distribution: BaseDistribution,
|
|
542
|
+
node_ids: list[int] = None) -> None:
|
|
543
|
+
"""
|
|
544
|
+
Sets a prevalence distribution on the demographics object. Automatically handles any necessary config updates.
|
|
545
|
+
Initial prevalence distributions are not compatible with HIV EMOD simulations.
|
|
546
|
+
|
|
547
|
+
Args:
|
|
548
|
+
distribution: The distribution to set. Must be a BaseDistribution object for a simple distribution.
|
|
549
|
+
node_ids: The node id(s) to apply changes to. None or 0 means the default node.
|
|
550
|
+
|
|
551
|
+
Returns:
|
|
552
|
+
Nothing
|
|
553
|
+
"""
|
|
554
|
+
from emod_api.demographics.implicit_functions import _set_init_prev
|
|
555
|
+
|
|
556
|
+
self._set_distribution(distribution=distribution,
|
|
557
|
+
use_case='prevalence',
|
|
558
|
+
simple_distribution_implicits=[_set_init_prev],
|
|
559
|
+
node_ids=node_ids)
|
|
560
|
+
|
|
561
|
+
def set_migration_heterogeneity_distribution(self,
|
|
562
|
+
distribution: BaseDistribution,
|
|
563
|
+
node_ids: list[int] = None) -> None:
|
|
564
|
+
"""
|
|
565
|
+
Sets a migration heterogeneity distribution on the demographics object. Automatically handles any necessary
|
|
566
|
+
config updates.
|
|
567
|
+
|
|
568
|
+
Args:
|
|
569
|
+
distribution: The distribution to set. Must be a BaseDistribution object for a simple distribution.
|
|
570
|
+
node_ids: The node id(s) to apply changes to. None or 0 means the default node.
|
|
571
|
+
|
|
572
|
+
Returns:
|
|
573
|
+
Nothing
|
|
574
|
+
"""
|
|
575
|
+
|
|
576
|
+
from emod_api.demographics.implicit_functions import _set_migration_model_fixed_rate
|
|
577
|
+
from emod_api.demographics.implicit_functions import _set_enable_migration_model_heterogeneity
|
|
578
|
+
|
|
579
|
+
implicits = [_set_migration_model_fixed_rate, _set_enable_migration_model_heterogeneity]
|
|
580
|
+
self._set_distribution(distribution=distribution,
|
|
581
|
+
use_case='migration_heterogeneity',
|
|
582
|
+
simple_distribution_implicits=implicits,
|
|
583
|
+
node_ids=node_ids)
|
|
584
|
+
|
|
585
|
+
# TODO: This belongs in emodpy-malaria, as that is the one disease that uses this set of parameters.
|
|
586
|
+
# Should be moved into a subclass of emodpy Demographics inside emodpy-malaria during a 2.0 conversion of it.
|
|
587
|
+
# https://github.com/EMOD-Hub/emodpy-malaria/issues/126
|
|
588
|
+
# def set_innate_immune_distribution(self,
|
|
589
|
+
# distribution: BaseDistribution,
|
|
590
|
+
# innate_immune_variation_type: str,
|
|
591
|
+
# node_ids: list[int] = None) -> None:
|
|
592
|
+
# """
|
|
593
|
+
# Sets a innate immune distribution on the demographics object. Automatically handles any necessary config
|
|
594
|
+
# updates.
|
|
595
|
+
#
|
|
596
|
+
# Args:
|
|
597
|
+
# distribution: The distribution to set. Must be a BaseDistribution object for a simple distribution.
|
|
598
|
+
# innate_immune_variation_type: the variation type to configure in EMOD. Must be either CYTOKINE_KILLING
|
|
599
|
+
# or PYROGENIC_THRESHOLD to be compatible with setting a innate immune distribution.
|
|
600
|
+
# node_ids: The node id(s) to apply changes to. None or 0 means the default node.
|
|
601
|
+
#
|
|
602
|
+
# Returns:
|
|
603
|
+
# Nothing
|
|
604
|
+
# """
|
|
605
|
+
# from emod_api.demographics.implicit_functions import _set_immune_variation_type_cytokine_killing, \
|
|
606
|
+
# _set_immune_variation_type_pyrogenic_threshold
|
|
607
|
+
#
|
|
608
|
+
# valid_types = [self.CYTOKINE_KILLING, self.PYROGENIC_THRESHOLD]
|
|
609
|
+
# if innate_immune_variation_type == self.CYTOKINE_KILLING:
|
|
610
|
+
# implicits = [_set_immune_variation_type_cytokine_killing]
|
|
611
|
+
# elif innate_immune_variation_type == self.PYROGENIC_THRESHOLD:
|
|
612
|
+
# implicits = [_set_immune_variation_type_pyrogenic_threshold]
|
|
613
|
+
# else:
|
|
614
|
+
# valid_types_str = ', '.join(valid_types)
|
|
615
|
+
# raise ValueError(f'innate_immune_variation_type must be one of: {valid_types_str} ... to allow use of a '
|
|
616
|
+
# f'distribution.')
|
|
617
|
+
#
|
|
618
|
+
# self._set_distribution(distribution=distribution,
|
|
619
|
+
# use_case='innate_immune',
|
|
620
|
+
# simple_distribution_implicits=implicits,
|
|
621
|
+
# node_ids=node_ids)
|
|
622
|
+
|
|
623
|
+
#
|
|
624
|
+
# These distribution setters only accept complex distributions
|
|
625
|
+
#
|
|
626
|
+
|
|
627
|
+
def set_mortality_distribution(self,
|
|
628
|
+
distribution_male: MortalityDistribution,
|
|
629
|
+
distribution_female: MortalityDistribution,
|
|
630
|
+
node_ids: list[int] = None) -> None:
|
|
631
|
+
"""
|
|
632
|
+
Sets the gendered mortality distributions on the demographics object. Automatically handles any necessary
|
|
633
|
+
config updates.
|
|
634
|
+
|
|
635
|
+
Args:
|
|
636
|
+
distribution_male: The male MortalityDistribution to set. Must be a MortalityDistribution object for a
|
|
637
|
+
complex distribution.
|
|
638
|
+
distribution_female: The female MortalityDistribution to set. Must be a MortalityDistribution object for a
|
|
639
|
+
complex distribution.
|
|
640
|
+
node_ids: The node id(s) to apply changes to. None or 0 means the default node.
|
|
641
|
+
|
|
642
|
+
Returns:
|
|
643
|
+
Nothing
|
|
644
|
+
"""
|
|
645
|
+
|
|
646
|
+
# Note that we only need to set the implicit function once, even though we set two distributions.
|
|
647
|
+
from emod_api.demographics.implicit_functions import _set_enable_natural_mortality
|
|
648
|
+
from emod_api.demographics.implicit_functions import _set_mortality_age_gender_year
|
|
649
|
+
|
|
650
|
+
implicits = [_set_enable_natural_mortality, _set_mortality_age_gender_year]
|
|
651
|
+
self._set_distribution(distribution=distribution_male,
|
|
652
|
+
use_case='mortality_male',
|
|
653
|
+
complex_distribution_implicits=implicits,
|
|
654
|
+
node_ids=node_ids)
|
|
655
|
+
self._set_distribution(distribution=distribution_female,
|
|
656
|
+
use_case='mortality_female',
|
|
657
|
+
node_ids=node_ids)
|
|
658
|
+
|
|
659
|
+
def _set_distribution(self,
|
|
660
|
+
distribution: Union[
|
|
661
|
+
BaseDistribution,
|
|
662
|
+
AgeDistribution,
|
|
663
|
+
SusceptibilityDistribution,
|
|
664
|
+
FertilityDistribution,
|
|
665
|
+
MortalityDistribution],
|
|
666
|
+
use_case: str,
|
|
667
|
+
simple_distribution_implicits: list[Callable] = None,
|
|
668
|
+
complex_distribution_implicits: list[Callable] = None,
|
|
669
|
+
node_ids: list[int] = None) -> None:
|
|
670
|
+
"""
|
|
671
|
+
A common core function for setting simple and complex distributions for all uses in EMOD demographics. This
|
|
672
|
+
should not be called directly by users.
|
|
673
|
+
|
|
674
|
+
Args:
|
|
675
|
+
distribution: The distribution object to set. If it is a BaseDistribution object, a simple distribution
|
|
676
|
+
will be set on the demographics object. If it is of any other allowed type, a complex distribution is
|
|
677
|
+
set.
|
|
678
|
+
use_case: A string used to identify which function to call on specified nodes to properly configure the
|
|
679
|
+
specified distribution.
|
|
680
|
+
simple_distribution_implicits: for simple distributions, a list of functions to call at config build-time to
|
|
681
|
+
ensure the specified distribution is utilized properly.
|
|
682
|
+
complex_distribution_implicits: for complex distributions, a list of functions to call at config build-time
|
|
683
|
+
to ensure the specified distribution is utilized properly.
|
|
684
|
+
node_ids: The node id(s) to apply changes to. None or 0 means the default node.
|
|
685
|
+
|
|
686
|
+
Returns:
|
|
687
|
+
Nothing
|
|
688
|
+
"""
|
|
689
|
+
if isinstance(distribution, BaseDistribution):
|
|
690
|
+
distribution_values = distribution.get_demographic_distribution_parameters()
|
|
691
|
+
function_name = f"_set_{use_case}_simple_distribution"
|
|
692
|
+
implicit_calls = simple_distribution_implicits
|
|
693
|
+
else:
|
|
694
|
+
function_name = f"_set_{use_case}_complex_distribution"
|
|
695
|
+
distribution_values = {'distribution': distribution}
|
|
696
|
+
implicit_calls = complex_distribution_implicits
|
|
697
|
+
|
|
698
|
+
nodes = self.get_nodes_by_id(node_ids=node_ids)
|
|
699
|
+
for _, node in nodes.items():
|
|
700
|
+
getattr(node, function_name)(**distribution_values)
|
|
701
|
+
|
|
702
|
+
# ensure the config is properly set up to know about this distribution
|
|
703
|
+
if implicit_calls is not None:
|
|
704
|
+
self.implicits.extend(implicit_calls)
|
|
705
|
+
|
|
706
|
+
def add_individual_property(self,
|
|
707
|
+
property: str,
|
|
708
|
+
values: Union[list[str], list[float]] = None,
|
|
709
|
+
initial_distribution: list[float] = None,
|
|
710
|
+
node_ids: list[int] = None,
|
|
711
|
+
overwrite_existing: bool = False) -> None:
|
|
712
|
+
"""
|
|
713
|
+
Adds a new individual property or replace values on an already-existing property in a demographics object.
|
|
714
|
+
|
|
715
|
+
Individual properties act as 'labels' on model agents that can be used for identifying and targeting
|
|
716
|
+
subpopulations in campaign elements and reports. For example, model agents may be given a property
|
|
717
|
+
('Accessibility') that labels them as either having access to health care (value: 'Yes') or not (value: 'No').
|
|
718
|
+
|
|
719
|
+
Another example: a property ('Risk') could label model agents as belonging to a spectrum of value categories
|
|
720
|
+
(values: 'HIGH', 'MEDIUM', 'LOW') that govern disease-related behavior.
|
|
721
|
+
|
|
722
|
+
Note: EMOD requires individual property key and values (property and values arguments) to be the same across all
|
|
723
|
+
nodes. The initial distributions of individual properties (initial_distribution) can vary across nodes.
|
|
724
|
+
|
|
725
|
+
Documentation of individual properties and HINT:
|
|
726
|
+
For malaria, see :doc:`emod-malaria:emod/model-properties`
|
|
727
|
+
and for HIV, see :doc:`emod-hiv:emod/model-properties`.
|
|
728
|
+
|
|
729
|
+
Args:
|
|
730
|
+
property: a new individual property key to add. If property already exists an exception is raised
|
|
731
|
+
unless overwrite_existing is True. 'property' must be the same across all nodes, note above.
|
|
732
|
+
values: A list of valid values for the property key. For example, ['Yes', 'No'] for an 'Accessibility'
|
|
733
|
+
property key. 'values' must be the same across all nodes, note above.
|
|
734
|
+
initial_distribution: The fractional, between 0 and 1, initial distribution of each valid values entry.
|
|
735
|
+
Order must match values argument. The values must add up to 1.
|
|
736
|
+
node_ids: The node ids to apply changes to. None or 0 means the 'Defaults' node, which will apply to all
|
|
737
|
+
the nodes unless a node has its own individual properties re-definition.
|
|
738
|
+
overwrite_existing: When True, overwrites existing individual properties with the same key. If False,
|
|
739
|
+
raises an exception if the property already exists in the node(s).
|
|
740
|
+
|
|
741
|
+
Returns:
|
|
742
|
+
None
|
|
743
|
+
"""
|
|
744
|
+
nodes = self.get_nodes_by_id(node_ids=node_ids).values()
|
|
745
|
+
individual_property = IndividualProperty(property=property,
|
|
746
|
+
values=values,
|
|
747
|
+
initial_distribution=initial_distribution)
|
|
748
|
+
for node in nodes:
|
|
749
|
+
if not overwrite_existing and node.has_individual_property(property_key=property):
|
|
750
|
+
raise ValueError(f"Property key '{property}' already present in IndividualProperties list")
|
|
751
|
+
|
|
752
|
+
node.individual_properties.add(individual_property=individual_property, overwrite=overwrite_existing)
|