Data & ModelParams

We apply a utility/abstraction layer to our data to simplify plotting and other operations later.

Before we can construct our model Parameters, we have to import and manipulate/restructure our data a bit as follows:

data to modelParams

Data

class covid19_npis.data.Country(path_to_folder)[source]

Country data class! Contains death, new_cases/positive tests, daily tests, interventions and config data for a specific country. Retrieves this data from a gives folder. There are the following specifications for the data:

  • new_cases.csv
    • Time/Date column has to be named “date” or “time”

    • Age group columns have to be named consistent between different data and countries

  • interventions.csv
    • Time/Date column has to be named “date” or “time”

    • Different intervention as additional columns with intervention name as column name

  • tests.csv
    • Time/Date column has to be named “date” or “time”

    • Daily performed tests column with name “tests”

  • deaths.csv
    • Time/Date column has to be named “date” or “time”

    • Daily deaths column has to be named “deaths”

    • Optional: Daily deaths per age group same column names as in new_cases

  • population.csv
    • Age column named “age”

    • Column Number of people per age named “PopTotal”

  • config.json, dict:
    • name : “country_name”

    • age_groupsdict
      • “column_name” : [age_lower, age_upper]

Also calculates change points and interventions automatically on init.

Parameters

path_to_folder (string) – Filepath to the folder, which holds all the data for the country! Should be something like “../data/Germany”. That is new_cases.csv, interventions.csv, population.csv

create_change_points(df)[source]

Create change points for a single intervention and also adds interventions if they do not exist yet.

Parameters

df (pandas.DataFrame) – Single intervention column with datetime index.

Returns

Change points dict {name:[cps]}

classmethod add_intervention(name, num_stages)[source]

Constructs and adds intervention to the class attributes if that intervention does not exist yet! This is done by name check.

Parameters
  • name (string) – Name of the intervention

  • time_series (pandas.DataFrame) – Intervention indexs as time series with datetime index!

classmethod set_intervention_alpha_prior(name, prior_loc, prior_scale)[source]

Manual set prior for effectivity alpha for a intervention via the name. That is it set prior_alpha_loc and prior_alpha_scale of a Intervention instance.

Parameters
  • name (string) – Name of intervention

  • prior_loc (number) –

  • prior_scale (number) –

classmethod get_intervention_by_name(name)[source]

Gets intervention from interventions array via name

Returns

Intervention

class covid19_npis.data.Intervention(name, num_stages, prior_alpha_loc=0.1, prior_alpha_scale=0.1)[source]
Parameters
  • name (string) – Name of the intervention

  • num_stages (int,) – Number of different stages the intervention can have.

  • prior_alpha_loc (number, optional) –

  • prior_alpha_scale (number, optional) –

class covid19_npis.data.Change_point(date_data, gamma_max)[source]
Parameters
  • prior_date_loc (number) – Mean of prior distribution for the location (date) of the change point.

  • gamma_max – Gamma max value for change point

  • length (number, optional) – Length of change point

  • prior_date_scale (number, optional) – Scale of prior distribution for the location (date) of the change point.

ModelParams

class covid19_npis.ModelParams(countries, const_contact=True, R_interval_time=5, sim_begin='2020-05-01', sim_end='2020-11-30', offset_sim_data=20, minimal_daily_cases=40, min_offset_sim_death_data=40, minimal_daily_deaths=10, spline_degree=3, spline_stride=7, dtype='float32')[source]

This is a class for all model parameters. It is mainly used to have a convenient to access data in model wide parameters e.g. start date for simulation.

This class also contains the data used for fitting. dataframe is the original dataframe. data_tensor is a tensor in the correct shape (time x countries x age) with values replace by nans when no data is available.

Parameters

countries (list, covid19_npis.data.Country) – Data objects for multiple countries

classmethod from_folder(fpath, **kwargs)[source]

Create modelParams class from folder containing differet regions or countrys

country_by_name(name)[source]

Returns country by name

property countries

Data objectes for each country.

Returns

List of all country object

_update_data_summary()[source]

# Update Data summary

property data_summary

Data summary for modelParams object.

property gamma_data_tensor

Creates a ragged tensor with dimension intervention, country, change_points The change points dimension can have different sizes.

property date_data_tensor

Creates a tensor with dimension intervention, country, change_points Padded with 0.0 for none existing change points

property pos_tests_dataframe

New cases as multiColumn dataframe level 0 = country/region and level 1 = age group.

property pos_tests_total_data_tensor

Tensor of daily new cases / positive tests for countries/regions and age groups.

Returns


Dimensions: time, country, agegroup

Return type

tf.Tensor

property pos_tests_data_tensor

Tensor of daily new cases / positive tests for countries/regions and age groups.

Returns


Dimensions: time, country, agegroup

Return type

tf.Tensor

property total_tests_dataframe

Dataframe of total tests in all countries. Datetime index and country columns as Multiindex.

property total_tests_data_tensor

returns:
Dimensions: time, country :rtype: tf.Tensor

property deaths_dataframe

Dataframe of deaths in all countries. Datetime index and country columns as Multiindex.

property deaths_data_tensor

returns:
Dimensions: time, country :rtype: tf.Tensor

property N_dataframe

Dataframe of population in all countries. Datetime index and country columns as Multiindex.

property N_data_tensor

Creates the population tensor with automatically calculated age strata/brackets.
Dimensions: country, age_groups

property N_data_tensor_total

Creates the population tensor for every age.
Dimensions: country, age

property indices_begin_data

Returns the index of every country when the first case is reported. It could be that for some countries, the index is later than self.offset_sim_data.

property length_data

returns: Length of the inserted/loaded data in days :rtype: number

property length_sim

returns: Length of the simulation in days. :rtype: number

property spline_basis

Calculates B-spline basis.

Returns

Return type


Dimensions: modelParams.length_sim, modelParams.num_splines

_make_global()[source]

Run once if you want to make the modelParams global. Used in plotting