emodpy_hiv.demographics.year_age_rate module#
This module contains stuff related to a YearAgeRate dataframe object that can be used to create demographic objects.
- class emodpy_hiv.demographics.year_age_rate.YearAgeRate(df: DataFrame | None = None, csv_filename: str | None = None)[source]#
Bases:
object
The YearAgeRate class is a wrapper around a pandas dataframe such that the dataframe is expected to have a specific format that is used in the demographics. Objects of this class are used as output from UN World Pop functions and as input into the creation of a Demograhics object. This gives us a standard format of the data for most population-based demographic data.
- The dataframe is expected to have four columns:
node_id: An integer representing the node the data is associated with
- min_year: A float representing the calendar start year of the period of years
for which the represents.
min_age: A float representing the age of the people in years.
- rate: The value (a float) of this column depends on the data contained.
It can be a rate of fertility or mortality or a fraction of the population.
This format assumes that the year/age ranges are contiguous from one value to the next largest value. For example, if a row has a min_age = 15 and the next row of the same year with the next largest min_age is 20, then the data for the row where min_age = 15 is for the age range of [15-20), where 15 is included and 20 is excluded. This is the same for min_year.
For a given node id, the format assumes that each min_year has the exact same set of min_ages. Different nodes can have different min_years or min_ages, but within a given node, they must be the same. The format also assumes that min_year and min_age for a given node are not duplicated.
- COL_NAME_NODE_ID = 'node_id'#
- COL_NAME_MIN_YEAR = 'min_year'#
- COL_NAME_MIN_AGE = 'min_age'#
- COL_NAME_RATE = 'rate'#
- COL_NAMES = ['node_id', 'min_year', 'min_age', 'rate']#
- SORT_BY_COLUMNS = ['node_id', 'min_year', 'min_age']#
- to_csv(csv_filename)[source]#
Save the dataframe to a csv file.
- Parameters:
csv_filename – The name of the file to write the dataframe to.
- to_age_distributions() List[Tuple[int, AgeDistribution]] [source]#
Convert this YearAgeRate object ot a list of (node_id, AgeDistribution) tuples. For each node in the dataframe, there will be a tuple in the list where the first value is the node_id and the second is an AgeDistribution object that can be used when creating a Demographics object.
The “rate” column is assumed to be the fraction of people in that year and age range. The dataframe is also assumed to only have the data for one year.
NOTE: EMOD expects the ReslutValues/Ages to be maximums of the bin. This implies that if the last age has a DistributionValue = 1.0, then there should be no people aged greater than this last age. It also means that the first age is also a minimum. For example, if the first age were 1.0, then there can be zero people less than 1.0. !!!THIS APPLIES ONLY TO THE OUTPUT OF THIS FUNCTION AND NOT THE INPUT!!!
- to_fertility_distributions() List[Tuple[int, FertilityDistribution]] [source]#
Convert this YearAgeRate object to a list of tuples of node_id and FertilityDistribution.
The method assumes that the user wants the data in a step-wise format. That is, for a calendar year range and age range, the user wants EMOD to produce the same value/rate for the entire range. The rate doesn’t change until the year or age moves to a new range.
For the max age of the last bin, a value of 125 is used and, for the max_year of the last bin, a value of 2100 is used. Using these maximums still produces the correct values because we want the result constant for the entire range. Having the range wider just produces the same constant.
- to_mortality_distributions(stepwise_for_year: bool = True) Dict[int, MortalityDistribution] [source]#
Convert this YearAgeRate object to a dict of node_id: MortalityDistribution entries.
The method assumes that the user wants the data in a step-wise format. That is, for a calendar year range and age range, the user wants EMOD to produce the same value/rate for the entire range. The rate doesn’t change until the year or age moves to a new range.
For the max age of the last bin, a value of 125 is used and, for the max_year of the last bin, a value of 2100 is used. Using these maximums still produces the correct values because we want the result constant for the entire range. Having the range wider just produces the same constant.
- Parameters:
stepwise_for_year – If true, the age and calendar year both in step-wise format. If false, calendar year is adjust by 2.5 and the linear interpolation will be used between calendar years.
- emodpy_hiv.demographics.year_age_rate.plot(year_age_rate_list: List[YearAgeRate], title: str | None = None, node_id: int = 0, img_dir: str | None = None, filename_to_save_to: str | None = None)[source]#
Create a plot window with one subplot for each min_age value and where the subplot will has min_year on the x-axis and “rate” on the y-axis. Each YearAgeRate object in the ‘year_age_rate_list’ will have one curve on each subplot
- Parameters:
year_age_rate_list – A list of YearAgeRate objects that have same min_age values for all min_year values. The min_year values do not need to be the same, just the min_ages.
title – The title of the plot window.
node_id – Data will be extracted from the YearAgeRate objects for this node.
img_dir – If this is defined, the images are saved to this directory. If not defined, the images are displayed in a window.
filename_to_save_to – The name of the file to save the image to. This is only used if img_dir is defined.