emodpy_hiv.demographics.infer_natural_mortality module#

emodpy_hiv.demographics.infer_natural_mortality.infer_natural_mortality(year_age_rate_data: YearAgeRate, interval_fit: tuple[float, float] | None = None, predict_horizon: float = 2100.0) YearAgeRate[source]#

Convert the raw mortality data to what would have been the expected natural mortality had HIV not caused a spike in mortality. This algorithm assumes that during the ‘interval_fit’ mortality rates had a relatively steady decline (i.e. less people were dying each year), but shortly after the ‘interval_fit’ there was a spike in mortality. The algorithm uses the data in the ‘interval_fit’ and extrapolates it out over the time period.

It assumes that the input data is for only one node.

Parameters:
  • year_age_rate_data – This is a YearAgeRate data object containing the raw mortality data, probably output from the extract_mortality() function

  • interval_fit – This tuple contains the range of years that we want to determine the mortality trend before the HIV epidemic. These years will be extrapolated from the end of the fit forward.

  • predict_horizon – This determines how far out the data will be extrapolated.

Returns:

A YearAgeRate object with the inferred mortality rates.

emodpy_hiv.demographics.infer_natural_mortality.mortality_read_infer_plot(country: str, version: str, gender: str, interval_fit: tuple[float, float] | None = None, save_data: bool = False, other_csv_filename: str | None = None, img_dir: str | None = None, filename_to_save_to: str | None = None) None[source]#

Extract the mortality data from the given file for the given country and plot both the raw data and the inferred data (without HIV deaths). The plot window will have a plot for each age where the data in the plot shows the rate per year for that age group. The label shows the minimum age of the band. This means that the age range being represented is from this value to the next largest age that is plotted.

Parameters:
  • un_world_pop_filename – The path to a UN World Population spreadsheet containing mortality data. It can be for either female or male.

  • country – The name of the country to be extracted. It must match exactly to the country name used in the referenced spreadsheet.

  • version – The year/version of the indicated spreadsheet. Each year has a slightly different format. Supported versions are 2012, 2015, 2019, 2024

  • gender – The gender of the data to be extracted. Possible values are ‘male’ and ‘female’.

  • save_data – If true (default is False), two YearAgeRate CSV formatted files are output into the current directory. The files are: ‘raw_mortality_year_age_rate.csv’ and ‘mortality_minus_hiv_year_age_rate.csv’.

  • other_csv_filename – If the filename is defined, it reads an expected YearAgeRate CSV file and plots it with the raw and inferred data from the spreadsheet. This allows the user to plot other mortality data (i.e. older versions) with the new data.

  • 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.

Returns:

No return

emodpy_hiv.demographics.infer_natural_mortality.mortality_read_infer_plot_app(country: str, version: str, gender: str, min_year: int, max_year: int, save_data: bool = False, other_csv_filename: str | None = None, img_dir: str | None = None) None[source]#

Using the ‘version’ and ‘gender’, select the UN World Population mortality data file. Extract the mortality data from the selected file for the given country and plot both the raw data and the inferred data (without HIV deaths). The plot will have a plot for each age where the data in the plot shows the rate per year for that age group. The label shows the minimum age of the band. This means that the age range being represented is from this value to the next largest age that is plotted.

Parameters:
  • country – The name of the country to be extracted. It must match exactly to the country name used in the referenced spreadsheet.

  • version – The year/version of the indicated spreadsheet. Each year has a slightly different format. Supported versions are 2012, 2015, 2019, 2024

  • gender – The gender of the data to be extracted. Possible values are ‘male’ and ‘female’.

  • min_year – The start year of the interval to fit the data to.

  • max_year – The end year of the interval to fit the data to.

  • save_data – If true (default is False), two YearAgeRate CSV formatted files are output into the current directory. The files are: ‘raw_mortality_year_age_rate.csv’ and ‘mortality_minus_hiv_year_age_rate.csv’.

  • other_csv_filename – If the filename is defined, it reads an expected YearAgeRate CSV file and plots it with the raw and inferred data from the spreadsheet. This allows the user to plot other mortality data (i.e. older versions) with the new data.

  • img_dir – If this is defined, the images are saved to this directory. If not defined, the images are displayed in a window.

Returns:

No return