|
14 | 14 |
|
15 | 15 | from emod_api.demographics import demographics_templates as DT |
16 | 16 | from emod_api.demographics.base_input_file import BaseInputFile |
17 | | -from emod_api.demographics.demographics_templates import CrudeRate, YearlyRate |
18 | 17 | from emod_api.demographics.node import Node |
19 | 18 | from emod_api.demographics.age_distribution_old import AgeDistributionOld as AgeDistribution |
20 | 19 | from emod_api.demographics.demographic_exceptions import InvalidNodeIdException |
@@ -400,38 +399,40 @@ def SetMinimalNodeAttributes(self): |
400 | 399 | # DTK is births per person per day. |
401 | 400 | def SetBirthRate(self, |
402 | 401 | birth_rate: float, |
403 | | - node_ids: List = None): |
| 402 | + node_ids: List[int] = None) -> None: |
404 | 403 | """ |
405 | 404 | Set Default birth rate to birth_rate. Turn on Vital Dynamics and Births implicitly. |
| 405 | +
|
| 406 | + Args: |
| 407 | + birth_rate: (float) The birth rate in units of births/year/1000-women |
| 408 | + node_ids: a list of node_ids. None or 0 indicates the default node. |
| 409 | +
|
| 410 | + Returns: |
| 411 | + Nothing |
406 | 412 | """ |
407 | 413 | warnings.warn('SetBirthRate() is deprecated. Default nodes should now be represented by Node ' |
408 | 414 | 'objects and passed to the Demographics object during the constructor call. They can be modified ' |
409 | 415 | 'afterward, if needed.', |
410 | 416 | DeprecationWarning, stacklevel=2) |
411 | | - if type(birth_rate) is float or type(birth_rate) is int: |
412 | | - birth_rate = CrudeRate(birth_rate) |
413 | | - dtk_birthrate = birth_rate.get_dtk_rate() |
| 417 | + dtk_birthrate = birth_rate / 365 / 1000 |
| 418 | + |
414 | 419 | if node_ids is None: |
415 | 420 | self.raw['Defaults']['NodeAttributes'].update({ |
416 | 421 | "BirthRate": dtk_birthrate |
417 | 422 | }) |
418 | 423 | else: |
419 | | - for node_id in node_ids: |
420 | | - self.get_node_by_id(node_id=node_id).birth_rate = dtk_birthrate |
| 424 | + nodes = self.get_nodes_by_id(node_ids=node_ids) |
| 425 | + for _, node in nodes.items(): |
| 426 | + node.birth_rate = dtk_birthrate |
421 | 427 | self.implicits.append(DT._set_population_dependent_birth_rate) |
422 | 428 |
|
423 | 429 | def SetMortalityRate(self, |
424 | | - mortality_rate: CrudeRate, node_ids: List[int] = None): |
| 430 | + mortality_rate: float, node_ids: List[int] = None): |
425 | 431 | """ |
426 | 432 | Set constant mortality rate to mort_rate. Turn on Enable_Natural_Mortality implicitly. |
427 | 433 | """ |
428 | 434 | warnings.warn('SetMortalityRate() is deprecated. Please use the emodpy Demographics method: ' |
429 | 435 | 'set_mortality_distribution()', DeprecationWarning, stacklevel=2) |
430 | | - |
431 | | - # yearly_mortality_rate = YearlyRate(mortality_rate) |
432 | | - if type(mortality_rate) is float or type(mortality_rate) is int: |
433 | | - mortality_rate = CrudeRate(mortality_rate) |
434 | | - mortality_rate = mortality_rate.get_dtk_rate() |
435 | 436 | if node_ids is None: |
436 | 437 | # setting = {"MortalityDistribution": DT._ConstantMortality(yearly_mortality_rate).to_dict()} |
437 | 438 | setting = {"MortalityDistribution": DT._ConstantMortality(mortality_rate).to_dict()} |
@@ -643,7 +644,8 @@ def SetDefaultNodeAttributes(self, birth=True): |
643 | 644 | "Region": 1, |
644 | 645 | "Seaport": 1} |
645 | 646 | if birth: |
646 | | - self.SetBirthRate(YearlyRate(math.log(1.03567))) |
| 647 | + # raise Exception("This will be removed in a new issue/PR shortly. Do not use.") |
| 648 | + self.SetBirthRate(birth_rate=math.log(1.03567)) |
647 | 649 |
|
648 | 650 | def SetDefaultProperties(self): |
649 | 651 | """ |
@@ -674,26 +676,36 @@ def SetDefaultFromTemplate(self, template, setter_fn=None): |
674 | 676 |
|
675 | 677 | # TODO: is this useful in a way that warrants a special-case function in emodpy built around set_age_distribution? |
676 | 678 | # https://github.com/InstituteforDiseaseModeling/emod-api-old/issues/788 |
677 | | - def SetEquilibriumAgeDistFromBirthAndMortRates(self, CrudeBirthRate=CrudeRate(40), CrudeMortRate=CrudeRate(20), |
678 | | - node_ids=None): |
| 679 | + def SetEquilibriumAgeDistFromBirthAndMortRates(self, |
| 680 | + birth_rate: float = 40.0, |
| 681 | + mortality_rate: float = 20.0, |
| 682 | + node_ids: List[int] = None): |
679 | 683 | """ |
680 | | - Set the inital ages of the population to a sensible equilibrium profile based on the specified input birth and |
681 | | - death rates. Note this does not set the fertility and mortality rates. |
| 684 | + Set age distribution based on birth and death rates. Implicit function. |
| 685 | +
|
| 686 | + Args: |
| 687 | + birth_rate: (float) The birth rate in units of births/year/1000-women |
| 688 | + mortality_rate: (float) The mortality rate in units of deaths/year/1000 people |
| 689 | + node_ids: a list of node_ids. None or 0 indicates the default node. |
| 690 | + Returns: |
| 691 | + Nothing |
682 | 692 | """ |
683 | | - warnings.warn('SetEquilibriumAgeDistFromBirthAndMortRates() is deprecated. Please use the emodpy Demographics method: ' |
684 | | - 'set_age_distribution()', DeprecationWarning, stacklevel=2) |
| 693 | + warnings.warn( |
| 694 | + 'SetEquilibriumAgeDistFromBirthAndMortRates() is deprecated. Please use the emodpy Demographics method: ' |
| 695 | + 'set_age_distribution()', DeprecationWarning, stacklevel=2) |
685 | 696 |
|
686 | | - yearly_birth_rate = YearlyRate(CrudeBirthRate) |
687 | | - yearly_mortality_rate = YearlyRate(CrudeMortRate) |
688 | | - dist = DT._EquilibriumAgeDistFromBirthAndMortRates(yearly_birth_rate, yearly_mortality_rate) |
| 697 | + dist = DT._EquilibriumAgeDistFromBirthAndMortRates(birth_rate=birth_rate, |
| 698 | + mortality_rate=mortality_rate) |
689 | 699 | setter_fn = DT._set_age_complex |
| 700 | + |
690 | 701 | if node_ids is None: |
691 | 702 | self.SetDefaultFromTemplate(dist, setter_fn) |
692 | 703 | else: |
693 | 704 | new_dist = AgeDistribution() |
694 | 705 | dist = new_dist.from_dict(dist["AgeDistribution"]) |
695 | | - for node in node_ids: |
696 | | - self.get_node_by_id(node_id=node)._set_age_complex_distribution(dist) |
| 706 | + nodes = self.get_nodes_by_id(node_ids=node_ids) |
| 707 | + for _, node in nodes.items(): |
| 708 | + node._set_age_complex_distribution(dist) |
697 | 709 | self.implicits.append(setter_fn) |
698 | 710 |
|
699 | 711 | def SetInitialAgeExponential(self, rate=0.0001068, description=""): |
|
0 commit comments