def run_download(_): run_date = pd.Timestamp.now().strftime("%d-%m-%Y") print(f"Starting download of API files on {run_date}") # set up root = Path("/tmp") data = mkdir(root/"data") # download aggregated CSVs as well download_data(data, "states.csv") download_data(data, "districts.csv") print("Uploading time series to storage bucket.") bucket = storage.Client().bucket(bucket_name) bucket.blob("pipeline/raw/districts.csv")\ .upload_from_filename(str(data/"districts.csv"), content_type = "text/csv") bucket.blob("pipeline/raw/states.csv")\ .upload_from_filename(str(data/"states.csv"), content_type = "text/csv") return 'OK!'
plt.show() return coef def notch_filter(ts): "Implement notch filter with notches at {1/7, 2/7}" fs, f0, Q = 1, 1/7, 1 b1, a1 = iirnotch(f0, Q, fs) b2, a2 = iirnotch(2*f0, 2*Q, fs) b = convolve(b1, b2) a = convolve(a1, a2) notched = pd.Series(filtfilt(b, a, ts)) notched.index = ts.index return notched root = cwd() data = mkdir(root/"data") figs = mkdir(root/"figs") ########################################################### # download latest case data # download_data(data, 'state_wise_daily.csv') # df = load_statewise_data(data/"state_wise_daily.csv") # ts = get_time_series(df, "state") ########################################################### # load delay data api_diff = pd.read_csv(data/"daily_diff.csv", parse_dates=["status_change_date", "report_date"], dayfirst=True) delay = api_diff[(api_diff.current_status == "Hospitalized") & (api_diff.report_date > "2020-08-02")].copy() delay = delay.drop(columns = [col for col in delay.columns if col.startswith("Unnamed")] + ["rowhash"]) delay["newhash"] = delay[["patient_number", "date_announced", "detected_district", "detected_state","current_status", "status_change_date", "num_cases"]].apply(lambda x: hash(tuple(x)), axis = 1) delay = delay.drop_duplicates(subset=["newhash"], keep="first")
import pandas as pd from epimargin.utils import setup, mkdir data, _ = setup() peru = mkdir(data/"peru") schema = dict(zip( "FECHA_CORTE;UUID;FECHA_FALLECIMIENTO;EDAD_DECLARADA;SEXO;FECHA_NAC;DEPARTAMENTO;PROVINCIA;DISTRITO".split(";"), "CUT_DATE;UUID;DEATH_DATE;DECLARED_AGE;SEX;BIRTH_DATE;DEPARTMENT;PROVINCE;DISTRICT".lower().split(";") )) #source: https://www.datosabiertos.gob.pe/dataset/fallecidos-por-covid-19-ministerio-de-salud-minsa df = pd.read_csv(peru/"fallecidos_covid.csv", delimiter = ";", encoding = "ISO-8859-1")\ .rename(columns = schema) df[df.district == "IQUITOS"][["death_date", "declared_age", "sex", "district"]]\ .assign( death_date = lambda _: pd.to_datetime(_["death_date"].astype(str).str.lstrip("0"), format = "%Y%m%d"), sex = lambda _: _["sex"].str[0] )\ .to_csv(peru/"iquitos.csv")
from studies.age_structure.TN_CMIE.commons import * from tqdm.std import tqdm import epimargin.plots as plt sns.set(style = "whitegrid") num_sims = 1000 simulation_range = 1 * years phi_points = [_ * percent * annually for _ in (25, 50, 100, 200)] simulation_initial_conditions = pd.read_csv(data/"simulation_initial_conditions.csv")\ .drop(columns = ["Unnamed: 0"])\ .set_index("district") districts_to_run = simulation_initial_conditions num_age_bins = 7 seed = 0 dst = mkdir(data/f"sim_metrics{num_sims}") def save_metrics(policy, tag): np.savez(dst/f"{tag}.npz", dT = policy.dT_total, dD = policy.dD_total, pi = policy.pi, q0 = policy.q0, q1 = policy.q1, Dj = policy.D ) def prioritize(num_doses, S, prioritization): Sp = S[:, prioritization] dV = np.where(Sp.cumsum(axis = 1) <= num_doses, Sp, 0) dV[np.arange(len(dV)), (Sp.cumsum(axis = 1) > dV.cumsum(axis = 1)).argmax(axis = 1)] = num_doses - dV.sum(axis = 1)
infectious_period = 1/gamma smooth = notched_smoothing(window) # simulation parameters simulation_start = pd.Timestamp("April 15, 2021") num_sims = 1000 focus_states = ["Tamil Nadu", "Punjab", "Maharashtra", "Bihar", "West Bengal"] # states to evaluate at state level (no district level data) coalesce_states = ["Delhi", "Manipur", "Dadra And Nagar Haveli And Daman And Diu", "Andaman And Nicobar Islands"] # experiment_tag = "OD_IFR_Rtdownscale_fullstate" experiment_tag = "unitvaxhazard_TN_IFR" # epi_dst = tev_src = mkdir(ext/f"{experiment_tag}_epi_{num_sims}_{simulation_start.strftime('%b%d')}") # epi_dst = tev_src = mkdir(Path("/Volumes/dedomeno/covid/vax-nature/OD_IFR_Rtdownscale_fullstate_epi_1000_Apr15")) epi_dst = tev_src = mkdir(Path("/Volumes/dedomeno/covid/vax-nature/all_india_coalesced_epi_1000_Apr15")) tev_dst = fig_src = mkdir(ext/f"{experiment_tag}_tev_{num_sims}_{simulation_start.strftime('%b%d')}") # misc survey_date = "October 23, 2020" # palette TN_color = "firebrick" IN_color = "#292f36" no_vax_color = "black" contactrate_vax_color = "darkorange" random_vax_color = "royalblue" mortality_vax_color = "forestgreen" agebin_colors = [ "#05668d", "#427aa1", "#679436", "#a5be00", "#ffcb77", "#d0393b", "#7a306c"]