data.loaders

data.loaders

Load data

Functions

Name Description
get_age_distribution Load age distribution for a given country or countries.
get_age_distribution_over_time Load age distribution for a given country or countries over time.
get_birth_rates Load crude birth rates for a given country
get_country_aliases Define aliases for countries with odd names in the data
get_death_rates Load death rates for a given country or countries.
get_total_pop Load total population for a given country or countries.
load_calib_data Normalize calibration target data into a single wide DataFrame.
map_entries Find a match between the JSON file and the provided location(s).

get_age_distribution

data.loaders.get_age_distribution(
    location=None,
    year=None,
    total_pop_file=None,
    age_datafile=None,
)

Load age distribution for a given country or countries.

Parameters

Name Type Description Default
location str name of the country to load the age distribution for None
year int year to load the age distribution for None
total_pop_file str optional filepath to save total population size for every year None

Returns

Name Type Description
age_data array Numpy array of age distributions, or dict if multiple locations

get_age_distribution_over_time

data.loaders.get_age_distribution_over_time(location=None, popage_datafile=None)

Load age distribution for a given country or countries over time.

Parameters

Name Type Description Default
location str name of the country to load the age distribution for None

Returns

Name Type Description
age_data dataframe Pandas dataframe with age distribution over time

get_birth_rates

data.loaders.get_birth_rates(location=None, birth_datafile=None)

Load crude birth rates for a given country

Parameters

Name Type Description Default
location str or list name of the country to load the birth rates for None
birth_datafile str / Path read from this CSV instead of the bundled data (schema: Time, CBR) None

Returns

Name Type Description
birth_rates arr years and crude birth rates

get_country_aliases

data.loaders.get_country_aliases()

Define aliases for countries with odd names in the data

get_death_rates

data.loaders.get_death_rates(
    location=None,
    by_sex=True,
    overall=False,
    death_datafile=None,
)

Load death rates for a given country or countries.

Parameters

Name Type Description Default
location str or list name of the country or countries to load the age distribution for None
by_sex bool whether to rates by sex True
overall bool whether to load total rate False
death_datafile str / Path read from this CSV instead of the bundled data (schema: Time, AgeGrpStart, Sex, mx) None

Returns

Name Type Description
death_rates dict death rates by age and sex

get_total_pop

data.loaders.get_total_pop(location=None, pop_datafile=None)

Load total population for a given country or countries.

Parameters

Name Type Description Default
location str or list name of the country to load the total population for None

Returns

Name Type Description
pop_data dataframe Dataframe of year and pop_size columns

load_calib_data

data.loaders.load_calib_data(data)

Normalize calibration target data into a single wide DataFrame.

Accepts

  • pd.DataFrame (index=‘t’, dot-scoped columns): assumed standardized; returned unchanged (with the t index enforced).
  • dict[str, pd.DataFrame]: legacy form; each value is a wide DataFrame keyed by a target name ('all_hpv.cancers'). Multi-column values are flattened with the key as scope prefix.
  • list / tuple of paths or long-format DataFrames: each item is a long CSV / DataFrame with year, name, [age, sex, genotype,] value columns; dispatched by column presence and merged outer-join on year.

Returns: a single pd.DataFrame with float year index (name=‘t’) and dot-scoped columns.

map_entries

data.loaders.map_entries(json, location, df=None)

Find a match between the JSON file and the provided location(s).

Parameters

Name Type Description Default
json list or dict the data being loaded required
location list or str the list of locations to pull from required