Exemple #1
0
def iterate_simulation(current_state, seir_parameters, phase, initial):
    """
    Iterate over simulation phase, returning evolution and new current state.
    """

    res = entrypoint(current_state, seir_parameters, phase, initial)
    current_state = (res.drop("scenario", axis=1).iloc[-1].to_dict()
                     )  # new initial = last date

    return res, current_state
Exemple #2
0
def run_simulation(user_input, config):
    """
    Run simulation phases and return hospital demand.
    
    Parameters
    ----------
    user_input["population_params"]: str
            Explicit population parameters:
                    - N: population
                    - I: infected
                    - R: recovered
                    - D: deaths
            
    user_input["strategy"]: dict
            Simulation parameters for each phase (from user input):
                - scenario: date
                    
    Return
    ------
    
    pd.Dataframe
        States evolution over phases
        
    """

    dfs = {"worst": np.nan, "best": np.nan}

    # Run worst scenario
    for bound in dfs.keys():

        phase = {"scenario": "projection_current_rt", "n_days": 90}

        # Get Rts
        if not user_input["state_id"] and not user_input["city_id"]:
            phase["R0"] = 3
        else:
            phase["R0"] = get_rt(user_input["place_type"], user_input, config,
                                 bound)

        res = entrypoint(
            user_input["population_params"],
            config["br"]["seir_parameters"],
            phase=phase,
            initial=True,
        )

        res = res.reset_index(drop=True)
        res.index += 1
        res.index.name = "dias"

        dfs[bound] = res

    return dfs