src.contact_models.contact_model_functions

Module Contents

Functions

go_to_weekly_meeting(states, params, group_col_name, day_of_week, seed)

Return who participates in a weekly meeting.

go_to_daily_work_meeting(states, params, seed)

Return which people go to work.

meet_daily_other_contacts(states, params, group_col_name, seed)

attends_educational_facility(states, params, id_column, seed)

Indicate which children go to an educational facility.

meet_hh_members(states, params, seed)

Meet household members.

meet_other_non_recurrent_contacts(states, params, seed)

Meet other non recurrent contacts.

_identify_ppl_affected_by_vacation(states)

_draw_potential_vacation_contacts(states, params, state_to_vacation, seed)

calculate_non_recurrent_contacts_from_empirical_distribution(states, params, on_weekends, seed, query=None, reduce_on_condition=True)

Draw how many non recurrent contacts each person will have today.

_draw_nr_of_contacts(distribution, is_participating, states, seed)

Draw the number of contacts for everyone in a is_participating.

_draw_age_varying_nr_of_contacts_numba(support, cum_probs, age_codes, is_participating, seed)

_fast_choice(arr, cdf)

reduce_contacts_on_condition(contacts, states, multiplier, condition, is_recurrent)

Reduce contacts for share of population for which condition is fulfilled.

_pupils_having_vacations_do_not_attend(attends_facility, states, params)

Make pupils stay away from school if their state has vacations.

get_states_w_vacations(date: pandas.Timestamp, params: pandas.DataFrame) → dict

Get states which currently have vacations for pupils.

Attributes

IS_POSITIVE_CASE

Condition for a positive test case.

IS_POSITIVE_CASE = knows_infectious | (knows_immune & symptomatic) | (knows_immune & (cd_received_test_result_true >= -13))[source]

Condition for a positive test case.

The individual either …

  • knows that she is infectious.

  • knows she is immune but still symptomatic.

  • knows she is immune but 14 days since infection have not passed.

Type

str

go_to_weekly_meeting(states, params, group_col_name, day_of_week, seed)[source]

Return who participates in a weekly meeting.

Parameters
  • states (pandas.DataFrame) – sid states DataFrame

  • params (pandas.DataFrame) – DataFrame with two index levels, subcategory and name.

  • group_col_name (str) – name of the column identifying this contact model’s group column.

  • day_of_week (str) – day of the week on which this model takes place.

Returns

same index as states. 1 for workers that

go to the weekly meeting today.

Return type

attends_meeting (pandas.Series)

go_to_daily_work_meeting(states, params, seed)[source]

Return which people go to work.

Parameters
  • states (pandas.DataFrame) – sid states DataFrame

  • params (pandas.DataFrame) – DataFrame with two index levels, subcategory and name. has a “value” column that contains the probabilities to the number of possible columns in the “name” index level.

Returns

same index as states. 1 for workers that go to

work this period, 0 for everyone else.

Return type

attends_work (pandas.Series)

meet_daily_other_contacts(states, params, group_col_name, seed)[source]
attends_educational_facility(states, params, id_column, seed)[source]

Indicate which children go to an educational facility.

Children go to an educational facility on weekdays. During vacations, all children do not go to educational facilities. Furthermore, there is a probability that children stay at home when they experience symptoms or receive a positive test result.

Parameters
  • states (pandas.DataFrame) – The states given by sid.

  • params (pandas.DataFrame) – DataFrame with three category levels,

  • id_column (str) – name of the column in states that identifies which pupils and adults belong to a group.

Returns

It is a series with the same index as states.

The values are one for children that go to the facility and zero for those who do not.

Return type

attends_facility (pandas.Series)

meet_hh_members(states, params, seed)[source]

Meet household members.

As single person households have unique household ids, everyone meets their household unless they are symptomatic. In that case the sick household member don’t meet the others with a certain probability.

Parameters
  • states (pandas.DataFrame) – The states.

  • params (pandas.DataFrame) – DataFrame with two index levels, subcategory and name. has a “value” column that contains the probabilities to the number of possible columns in the “name” index level.

meet_other_non_recurrent_contacts(states, params, seed)[source]

Meet other non recurrent contacts.

Individuals in households with educ_workers, retired and children have additional contacts during vacations.

_identify_ppl_affected_by_vacation(states)[source]
_draw_potential_vacation_contacts(states, params, state_to_vacation, seed)[source]
calculate_non_recurrent_contacts_from_empirical_distribution(states, params, on_weekends, seed, query=None, reduce_on_condition=True)[source]

Draw how many non recurrent contacts each person will have today.

Parameters
  • states (pandas.DataFrame) – sid states DataFrame.

  • params (pandas.DataFrame) – DataFrame with two index levels, subcategory and name. has a “value” column that contains the probabilities to the number of possible columns in the “name” index level.

  • on_weekends (bool or str) – whether to meet on weekends or not. If it’s a string it’s interpreted as the prefix of columns identifying who participates in this contact model on weekends. Then, columns of the form “{on_weekends}_saturday” and “{on_weekends}_sunday” must be in states.

  • query (str) – query string to identify the subset of individuals to which this contact model applies.

Returns

index is the same as states. values is the number of

contacts.

Return type

contacts (pandas.Series)

_draw_nr_of_contacts(distribution, is_participating, states, seed)[source]

Draw the number of contacts for everyone in a is_participating.

Parameters
  • distribution (pandas.Series) – slice of the params DataFrame with the distribution. The subcategory level of the index either identifies the age group specific distribution or must be the same for the whole slice. The name index level gives the support and the values of the Series give the probabilities.

  • is_participating (pandas.Series) – same index as states. True for the individuals that participate in the current contact model, i.e. for which the number of contacts should be drawn.

  • states (pandas.DataFrame) – sid states DataFrame.

Returns

Same index as the states, values are

the number of contacts for each person.

Return type

nr_of_contacts (pandas.Series)

_draw_age_varying_nr_of_contacts_numba(support, cum_probs, age_codes, is_participating, seed)[source]
_fast_choice(arr, cdf)[source]
reduce_contacts_on_condition(contacts, states, multiplier, condition, is_recurrent)[source]

Reduce contacts for share of population for which condition is fulfilled.

The subset of contacts for which contacts are reduced is specified by the condition and whoever has a positive number of contacts. Then, a share of individuals in the subset is sampled and the contacts are set to 0.

Parameters
  • contacts (pandas.Series) – The series with contacts.

  • states (pandas.DataFrame) – The states of one day passed by sid.

  • multiplier (float) – The share of people who maintain their contacts despite condition.

  • condition (str, numpy.ndarray or pandas.Series) – Condition or boolean array or Series which defines the subset of individuals who potentially reduce their contacts.

  • seed (int) –

_pupils_having_vacations_do_not_attend(attends_facility, states, params)[source]

Make pupils stay away from school if their state has vacations.

get_states_w_vacations(date: pandas.Timestamp, params: pandas.DataFrame) dict[source]

Get states which currently have vacations for pupils.

Returns

keys are the states that have vacations

on the current date. Values are the names of the vacation.

Return type

state_to_vacation_name (dict)