Пример #1
0
def _create_deps(scenarios, groupby):
    available_scenarios = get_available_scenarios(get_named_scenarios())

    py_dependencies = {
        "config.py": SRC / "config.py",
        "scenario_config.py": SRC / "simulation" / "scenario_config.py",
        "plotting.py": SRC / "plotting" / "plotting.py",
    }

    data_dependencies = {}
    scenarios_to_compare = [s for s in scenarios if s in available_scenarios]
    for scenario in scenarios_to_compare:
        outcome = ("newly_infected"
                   if groupby is None else f"newly_infected_by_{groupby}")
        data_dependencies[
            scenario] = create_path_to_scenario_outcome_time_series(
                scenario, outcome)
    dependencies = combine_dictionaries([py_dependencies, data_dependencies])
    return dependencies
Пример #2
0
def _create_parametrization():
    """Create the parametrization for the share known cases plots."""
    named_scenarios = get_named_scenarios()
    available_scenarios = get_available_scenarios(named_scenarios)
    parametrization = []
    for scenario_name in available_scenarios:
        nice_name = make_scenario_name_nice(scenario_name).title()
        for groupby in ["age_group_rki", None]:
            depends_on = create_path_to_share_known_cases_of_scenario(
                scenario_name, groupby)
            produces = create_path_to_share_known_cases_plot(
                scenario_name, groupby)
            title = (
                f"Share Known Cases {'By Age Group' if groupby else ''} in {nice_name}"
            )
            title = None
            parametrization.append((depends_on, title, groupby, produces))

    return "depends_on, title, groupby, produces", parametrization
Пример #3
0
def _create_scenario_share_known_cases_parametrization():
    """Create the parametrization for the share known cases."""
    named_scenarios = get_named_scenarios()
    available_scenarios = get_available_scenarios(named_scenarios)
    parametrization = []

    for scenario_name in available_scenarios:
        for groupby in ["age_group_rki", None]:
            depends_on = {}
            for outcome in ["currently_infected", "knows_currently_infected"]:
                depends_on[
                    outcome] = create_path_to_scenario_outcome_time_series(
                        scenario_name,
                        f"{outcome}_by_{groupby}"
                        if groupby is not None else outcome,
                    )
            produces = create_path_to_share_known_cases_of_scenario(
                scenario_name, groupby)
            parametrization.append((depends_on, produces))
    return "depends_on, produces", parametrization
Пример #4
0
def _create_incidence_parametrization():
    named_scenarios = get_named_scenarios()
    parametrization = []
    period_output_keys = create_period_outputs().keys()
    for name, specs in named_scenarios.items():
        depends_on = {}
        for seed in range(specs["n_seeds"]):
            depends_on[seed] = create_path_to_period_outputs_of_simulation(
                name, seed)

        # this handles the case of 0 seeds, i.e. skipped scenarios
        if depends_on:
            produces = {
                entry:
                create_path_to_scenario_outcome_time_series(name, entry)
                for entry in period_output_keys
            }

            parametrization.append((depends_on, produces))

    return "depends_on, produces", parametrization
    "spring_without_seasonality": frozenset(["rapid_tests", "vaccinations"]),
    "spring_no_effects": frozenset([]),
}

_RAPID_TEST_SCENARIOS_TO_MEMBERS = {
    "spring_baseline": frozenset(["private", "school", "work"]),
    "spring_without_school_and_work_rapid_tests": frozenset(["private"]),
    "spring_without_school_and_private_rapid_tests": frozenset(["work"]),
    "spring_without_work_and_private_rapid_tests": frozenset(["school"]),
    "spring_without_work_rapid_tests": frozenset(["school", "private"]),
    "spring_without_school_rapid_tests": frozenset(["work", "private"]),
    "spring_without_private_rapid_tests": frozenset(["school", "work"]),
    "spring_without_rapid_tests": frozenset([]),
}

_AVAILABLE_SCENARIOS = get_available_scenarios(get_named_scenarios())

_MATPLOTLIB_RC_CONTEXT = {
    "axes.spines.right": False,
    "axes.spines.top": False,
    "legend.frameon": False,
}

_ORDERED_CHANNELS = ["Rapid Tests", "Seasonality", "Vaccinations"]
_ORDERED_RAPID_TEST_CHANNELS = ["Private", "Work", "School"]

_ALL_CHANNEL_SCENARIOS_AVAILABLE = all(i in _AVAILABLE_SCENARIOS
                                       for i in _CHANNEL_SCENARIOS_TO_MEMBERS)
_ALL_RAPID_TEST_SCENARIOS_AVAILABLE = all(
    i in _AVAILABLE_SCENARIOS for i in _RAPID_TEST_SCENARIOS_TO_MEMBERS)
def _create_simulation_parametrization():
    """Convert named scenarios to parametrization.

    Each named scenario is duplicated with different seeds to capture the uncertainty in
    the simulation..

    """
    named_scenarios = get_named_scenarios()

    scenarios = []
    for name, specs in named_scenarios.items():
        is_resumed = specs.get("is_resumed", "fall")
        save_last_states = specs.get("save_last_states", False)
        for seed in range(specs["n_seeds"]):
            produces = {
                "period_outputs":
                create_path_to_period_outputs_of_simulation(name, seed)
            }
            if specs.get("save_rapid_test_statistics", False):
                rapid_test_statistics_path = create_path_to_raw_rapid_test_statistics(
                    name, seed)
                produces["rapid_test_statistics"] = rapid_test_statistics_path

                # since we use "append" mode to build this we need to delete the
                # present file with every run
                if rapid_test_statistics_path.exists():
                    rapid_test_statistics_path.unlink()
            else:
                rapid_test_statistics_path = None

            if save_last_states:
                produces[
                    "last_states"] = create_path_to_last_states_of_simulation(
                        name, seed)

            depends_on = get_simulation_dependencies(
                debug=FAST_FLAG == "debug",
                is_resumed=is_resumed,
            )
            if is_resumed:
                depends_on[
                    "initial_states"] = create_path_to_last_states_of_simulation(
                        f"{is_resumed}_baseline", seed)

            spec_tuple = (
                depends_on,
                specs["sim_input_scenario"],
                specs["params_scenario"],
                specs["start_date"],
                specs["end_date"],
                save_last_states,
                produces,
                500 + 100_000 * seed,
                is_resumed,
                rapid_test_statistics_path,
            )
            scenarios.append(spec_tuple)

    signature = ("depends_on, sim_input_scenario, params_scenario, " +
                 "start_date, end_date, save_last_states, produces, seed, " +
                 "is_resumed, rapid_test_statistics_path")
    return signature, scenarios
from src.plotting.plotting import TEAL
from src.policies.policy_tools import filter_dictionary
from src.simulation.scenario_config import create_path_for_weekly_outcome_of_scenario
from src.simulation.scenario_config import create_path_to_scenario_outcome_time_series
from src.simulation.scenario_config import get_available_scenarios
from src.simulation.scenario_config import get_named_scenarios


_MODULE_DEPENDENCIES = {
    "plotting.py": SRC / "plotting" / "plotting.py",
    "policy_tools.py": SRC / "policies" / "policy_tools.py",
    "scenario_config.py": SRC / "simulation" / "scenario_config.py",
    "empirical": BLD / "data" / "empirical_data_for_plotting.pkl",
}

NAMED_SCENARIOS = get_named_scenarios()

SCHOOL_SCENARIOS = [
    "spring_educ_open_after_easter_without_tests",
    "spring_educ_open_after_easter_with_tests",
    "spring_close_educ_after_easter",
    "spring_baseline",
]


OUTCOMES = [
    "newly_infected",
    "new_known_case",
    "newly_deceased",
    "share_ever_rapid_test",
    "share_rapid_test_in_last_week",
Пример #8
0
from itertools import product

import pandas as pd
import pytask

from src.config import BLD
from src.simulation.scenario_config import (
    create_path_to_rapid_test_statistic_time_series as get_ts_path, )
from src.simulation.scenario_config import create_path_to_raw_rapid_test_statistics
from src.simulation.scenario_config import get_named_scenarios

_N_SEEDS = get_named_scenarios()["spring_baseline"]["n_seeds"]

_DEPENDENCIES = {
    seed: create_path_to_raw_rapid_test_statistics("spring_baseline", seed)
    for seed in range(_N_SEEDS)
}

CHANNELS = ["private", "work", "educ", "overall"]
OUTCOMES = [
    "false_negative",
    "false_positive",
    "tested_negative",
    "tested_positive",
    "true_negative",
    "true_positive",
    "tested",
]
SHARE_TYPES = ["number", "popshare", "testshare"]

RAPID_TEST_STATISTICS = []