def test_shorten_policies_start_only(policies): start = pd.Timestamp("2020-10-01") res = shorten_policies(policies, start_date=start) expected = { "drop_bc_too_late": { "start": pd.Timestamp("2021-01-01"), "end": pd.Timestamp("2021-01-30"), "multiplier": 0.2, }, "adjust_to_start_later": { "start": start, "end": pd.Timestamp("2020-11-01"), "multiplier": 1.0, }, "adjust_to_end_earlier": { "start": pd.Timestamp("2020-11-02"), "end": pd.Timestamp("2020-12-30"), "multiplier": 1.0, }, "unchanged": { "start": pd.Timestamp("2020-11-02"), "end": pd.Timestamp("2020-11-30"), "multiplier": 1.0, }, } assert res == expected
def test_shorten_policies_end_only(policies): end = pd.Timestamp("2020-12-01") res = shorten_policies(policies, end_date=end) expected = { "drop_bc_too_early": { "start": pd.Timestamp("2020-05-01"), "end": pd.Timestamp("2020-05-30"), "multiplier": 0.5, }, "adjust_to_start_later": { "start": pd.Timestamp("2020-09-01"), "end": pd.Timestamp("2020-11-01"), "multiplier": 1.0, }, "adjust_to_end_earlier": { "start": pd.Timestamp("2020-11-02"), "end": end, "multiplier": 1.0, }, "unchanged": { "start": pd.Timestamp("2020-11-02"), "end": pd.Timestamp("2020-11-30"), "multiplier": 1.0, }, } assert res == expected
def plus_10_pct_home_office_after_easter(paths, fixed_inputs): """Hypothetical scenario where there is 10 pct more home office after Easter.""" start_date = fixed_inputs["duration"]["start"] end_date = fixed_inputs["duration"]["end"] contact_models = fixed_inputs["contact_models"] enacted_policies = get_enacted_policies(contact_models) new_policies = _get_policies_with_multiplied_work_attend_multiplier_after_date( enacted_policies=enacted_policies, contact_models=contact_models, multiplier=0.9, split_date=AFTER_EASTER, prefix="work_plus_10_pct_home_office_after_easter", ) new_policies = shorten_policies(new_policies, start_date, end_date) out = { "contact_policies": new_policies, "vaccination_models": _baseline_vaccination_models(paths, fixed_inputs), "rapid_test_models": _baseline_rapid_test_models(fixed_inputs), "rapid_test_reaction_models": _baseline_rapid_test_reaction_models(fixed_inputs), } return out
def strict_home_office_after_summer_scenario_start(paths, fixed_inputs): """Define strict home office after summer scenario starts. The attendance multiplier is set to 0.54 which corresponds to the mean work multiplier in April 2020. """ start_date = fixed_inputs["duration"]["start"] end_date = fixed_inputs["duration"]["end"] contact_models = fixed_inputs["contact_models"] enacted_policies = get_enacted_policies(contact_models) new_policies = _get_policies_with_different_work_attend_multiplier_after_date( enacted_policies=enacted_policies, contact_models=contact_models, new_attend_multiplier=0.54, split_date=SUMMER_SCENARIO_START, prefix="work_strict_home_office_after_summer_scenario_start", ) new_policies = shorten_policies(new_policies, start_date, end_date) out = { "contact_policies": new_policies, "vaccination_models": _baseline_vaccination_models(paths, fixed_inputs), "rapid_test_models": _baseline_rapid_test_models(fixed_inputs), "rapid_test_reaction_models": _baseline_rapid_test_reaction_models(fixed_inputs), } return out
def close_educ_after_april_5(paths, fixed_inputs): start_date = fixed_inputs["duration"]["start"] end_date = fixed_inputs["duration"]["end"] contact_models = fixed_inputs["contact_models"] enacted_policies = get_enacted_policies(contact_models) stays_same, to_change = split_policies(enacted_policies, split_date=AFTER_EASTER) keep = remove_educ_policies(to_change) block_info = { "prefix": "educ_closed_after_april_5", "start_date": AFTER_EASTER, "end_date": VERY_LATE, } new_educ_policies = shut_down_educ_models(contact_models=contact_models, block_info=block_info, educ_type="all") new_policies = combine_dictionaries([stays_same, keep, new_educ_policies]) new_policies = shorten_policies(new_policies, start_date, end_date) out = { "vaccination_models": _baseline_vaccination_models(paths, fixed_inputs), "rapid_test_models": _baseline_rapid_test_models(fixed_inputs), "rapid_test_reaction_models": _baseline_rapid_test_reaction_models(fixed_inputs), "contact_policies": new_policies, } return out
def only_strict_emergency_care_after_april_5(paths, fixed_inputs): start_date = fixed_inputs["duration"]["start"] end_date = fixed_inputs["duration"]["end"] contact_models = fixed_inputs["contact_models"] enacted_policies = get_enacted_policies(contact_models) stays_same, to_change = split_policies(enacted_policies, split_date=AFTER_EASTER) keep = remove_educ_policies(to_change) block_info = { "prefix": "emergency_care_after_april_5", "start_date": AFTER_EASTER, "end_date": VERY_LATE, } new_young_educ_policies = apply_emergency_care_policies( contact_models=contact_models, block_info=block_info, educ_type="young_educ", attend_multiplier=0.25, hygiene_multiplier=HYGIENE_MULTIPLIER, ) school_options = get_school_options_for_strict_emergency_care() new_school_policies = apply_mixed_educ_policies( contact_models=contact_models, block_info=block_info, educ_type="school", **school_options, ) new_policies = combine_dictionaries( [stays_same, keep, new_young_educ_policies, new_school_policies]) new_policies = shorten_policies(new_policies, start_date, end_date) out = { "vaccination_models": _baseline_vaccination_models(paths, fixed_inputs), "rapid_test_models": _baseline_rapid_test_models(fixed_inputs), "rapid_test_reaction_models": _baseline_rapid_test_reaction_models(fixed_inputs), "contact_policies": new_policies, } return out
def robustness_check(paths, fixed_inputs): """Change the inputs to remove knowledge of the time after March 1st. This function does the following: - fix the work attend multiplier to the value of end of February - use a simple linear extrapolation of the February vaccination data. """ exercise_start = pd.Timestamp("2021-03-01") start_date = fixed_inputs["duration"]["start"] end_date = fixed_inputs["duration"]["end"] init_start = start_date - pd.Timedelta(31, unit="D") contact_models = fixed_inputs["contact_models"] enacted_policies = get_enacted_policies(contact_models) # set work multiplier instead of using the policies_with_fixed_work_multiplier = ( _get_policies_with_different_work_attend_multiplier_after_date( enacted_policies=enacted_policies, contact_models=contact_models, new_attend_multiplier=0.75, split_date=exercise_start, prefix="work_fixed_work_multiplier_after_easter", )) policies_with_fixed_work_multiplier = shorten_policies( policies_with_fixed_work_multiplier, start_date, end_date) # replace vaccinations with prediction from February vaccination_shares = pd.read_pickle(paths["vaccination_shares"]) vaccination_models = _replace_vaccination_shares_with_prediction_from_feb( vaccination_shares, init_start) out = { "contact_policies": policies_with_fixed_work_multiplier, "vaccination_models": vaccination_models, "rapid_test_models": _baseline_rapid_test_models(fixed_inputs), "rapid_test_reaction_models": _baseline_rapid_test_reaction_models(fixed_inputs), } return out
def _open_all_educ_after_date(paths, fixed_inputs, split_date, multiplier=HYGIENE_MULTIPLIER): start_date = fixed_inputs["duration"]["start"] end_date = fixed_inputs["duration"]["end"] contact_models = fixed_inputs["contact_models"] enacted_policies = get_enacted_policies(contact_models) stays_same, to_change = split_policies(enacted_policies, split_date=split_date) after_split_without_educ_policies = remove_educ_policies(to_change) block_info = { "prefix": f"open_all_educ_after_{pd.Timestamp(split_date).date()}", "start_date": split_date, "end_date": VERY_LATE, } new_educ_policies = reduce_educ_models( contact_models=contact_models, block_info=block_info, educ_type="all", multiplier=multiplier, ) new_policies = combine_dictionaries( [stays_same, after_split_without_educ_policies, new_educ_policies]) new_policies = shorten_policies(new_policies, start_date, end_date) out = { "contact_policies": new_policies, "vaccination_models": _baseline_vaccination_models(paths, fixed_inputs), "rapid_test_models": _baseline_rapid_test_models(fixed_inputs), "rapid_test_reaction_models": _baseline_rapid_test_reaction_models(fixed_inputs), } return out
def test_shorten_policies_both_dates(policies): start = pd.Timestamp("2020-10-01") end = pd.Timestamp("2020-12-01") res = shorten_policies(policies, start_date=start, end_date=end) expected = { "adjust_to_start_later": { "start": start, "end": pd.Timestamp("2020-11-01"), "multiplier": 1.0, }, "adjust_to_end_earlier": { "start": pd.Timestamp("2020-11-02"), "end": end, "multiplier": 1.0, }, "unchanged": { "start": pd.Timestamp("2020-11-02"), "end": pd.Timestamp("2020-11-30"), "multiplier": 1.0, }, } assert res == expected
def _baseline_policies(fixed_inputs): start_date = fixed_inputs["duration"]["start"] end_date = fixed_inputs["duration"]["end"] policies = get_enacted_policies(fixed_inputs["contact_models"]) policies = shorten_policies(policies, start_date, end_date) return policies