Esempio n. 1
0
def read_time_file(filename):
    global seed_file_cache
    if filename not in seed_file_cache:
        with open(filename, "r") as FILE:
            time_seeds = [[num for num in line.split(',')] for line in FILE]
        Console.debug("Times of seeding:", variables=[time_seeds])

        # convert to dates and counts
        time_seeds = np.array(time_seeds)
        time_seeds_trust = time_seeds[:, 1].astype(int)
        time_seeds_count = time_seeds[:, 2].astype(int)

        time_seeds_date = [[i.split('-')] for i in time_seeds[:, 0]]
        time_seeds_date = [[int(i[0][0]),
                            int(i[0][1]),
                            int(i[0][2])] for i in time_seeds_date]
        time_seeds_date = [
            datetime(i[0], i[1], i[2]).date() for i in time_seeds_date
        ]

        # store outputs
        seed_file_cache[filename] = "STORED"
        seed_file_cache["time_seeds_date"] = time_seeds_date
        seed_file_cache["time_seeds_trust"] = time_seeds_trust
        seed_file_cache["time_seeds_count"] = time_seeds_count

    return seed_file_cache["time_seeds_date"], seed_file_cache[
        "time_seeds_trust"], seed_file_cache["time_seeds_count"]
Esempio n. 2
0
def iterate_lockdown(network, population, **kwargs):
    from metawards.iterators import iterate_default

    advance_funcs = iterate_default(network=network,
                                    population=population,
                                    **kwargs)

    # read parameters from custom user parameters
    params = network.params
    nstages = int(params.user_params["nstages"])

    start_day = int(params.user_params["start_day"])
    R0 = params.user_params["R0"]

    duration = params.user_params["duration"]
    scale_uv = params.user_params["scale_uv"]
    cutoff = params.user_params["cutoff"]

    day = population.day

    if day >= start_day:
        # in lockdown

        # which stage are we in?
        stage = 0
        scl = scale_uv[0] / R0
        cut = cutoff[0]

        end_day = start_day + int(duration[0])

        if day <= end_day:
            stage = 0
        else:
            for i in range(1, nstages):
                end_day += int(duration[i])
                scl = scale_uv[i] / R0
                cut = cutoff[i]

                if day <= end_day:
                    stage = i
                    break

            if day > end_day:
                print("Lockdown ended")
                scl = 1.0
                cut = 1000  # 1000 km

        population.scale_uv = scl
        params.dyn_dist_cutoff = cut

        Console.debug("LOCKDOWN", variables=[stage, scl, cut])

    return advance_funcs
def read_file(filename, nage):
    global file_cache
    if filename not in file_cache:
        with open(filename, "r") as FILE:
            contact_matrix = [[num for num in line.split(',')]
                              for line in FILE]
            # set up interaction matrix
            matrix = [[0.0 for i in range(nage)] for j in range(nage)]
            for i in range(nage):
                for j in range(nage):
                    matrix[i][j] = float(contact_matrix[i][j])
        Console.debug("Interaction matrix", variables=[matrix])
        file_cache[filename] = matrix
    return file_cache[filename]
Esempio n. 4
0
def read_age_file(filename):
    global seed_file_cache
    if filename not in seed_file_cache:
        with open(filename, "r") as FILE:
            age_probs = [[num for num in line.split(',')] for line in FILE]
        Console.debug("Age-level seeding probabilities:",
                      variables=[age_probs])

        # convert to correct format
        age_probs = np.array(age_probs)
        age_probs_ind = age_probs[:, 0].astype(int)
        age_probs = age_probs[:, 1].astype(float)

        # save in cache
        seed_file_cache[filename] = "STORED"
        seed_file_cache["age_probs_ind"] = age_probs_ind
        seed_file_cache["age_probs"] = age_probs

    return seed_file_cache["age_probs_ind"], seed_file_cache["age_probs"]
Esempio n. 5
0
def read_seed_file(filename):
    global seed_file_cache
    if filename not in seed_file_cache:
        with open(filename, "r") as FILE:
            ward_probs = [[num for num in line.split(',')] for line in FILE]
        Console.debug("Ward-level seeding probabilities:",
                      variables=[ward_probs])

        # convert to correct format
        ward_probs = np.array(ward_probs)
        ward_probs_ind = ward_probs[:, 0].astype(int)
        ward_probs_trust = ward_probs[:, 1].astype(int)
        ward_probs = ward_probs[:, 2].astype(float)

        # save in cache
        seed_file_cache[filename] = "STORED"
        seed_file_cache["ward_probs_ind"] = ward_probs_ind
        seed_file_cache["ward_probs_trust"] = ward_probs_trust
        seed_file_cache["ward_probs"] = ward_probs

    return seed_file_cache["ward_probs_ind"], seed_file_cache[
        "ward_probs_trust"], seed_file_cache["ward_probs"]
Esempio n. 6
0
def iterate_debug(**kwargs):
    Console.debug("Something")
    return []