-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38d26ae
commit 4e2b7b1
Showing
4 changed files
with
52 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
import polars as pl | ||
from tqdm import tqdm | ||
from pathlib import Path | ||
import plotnine as p9 | ||
from src.query.utils import collect_year, compute_binomial_interval | ||
from src.query.utils import query_disease_location_year, compute_binomial_interval | ||
|
||
BASE_PATH = Path(".") | ||
# optional if using external disk: BASE_PATH = Path("E:/", "disease_database") | ||
COMBINED_DATA_FOLDER = Path("processed_data", "combined") | ||
LOCATION_EXCEL_FILE = Path("raw_data", "manual_input", "municipalities_1869.xlsx") | ||
|
||
|
||
def query_map( | ||
disease_query: str, | ||
year: int, | ||
): | ||
def query_space(disease_query: str, year: int): | ||
# iterate over each municipality | ||
muni_df = pl.read_excel(LOCATION_EXCEL_FILE) | ||
muni_df = pl.read_excel(BASE_PATH / LOCATION_EXCEL_FILE).head() | ||
text_df = pl.scan_parquet( | ||
BASE_PATH / COMBINED_DATA_FOLDER / f"combined_{year}_{year + 1}.parquet" | ||
) | ||
df_list = [] | ||
for row in tqdm(muni_df.iter_rows(named=True), total=len(muni_df)): | ||
try: | ||
df_list.append( | ||
collect_year(disease=disease_query, location=row["Regex"], year=year).with_columns(pl.lit(row["cbscode"]).alias("cbscode")) | ||
query_disease_location_year( | ||
df_lazy=text_df, | ||
disease="(?i)" + disease_query, | ||
location="(?i)" + row["Regex"], | ||
year=year, | ||
).with_columns( | ||
pl.lit(row["cbscode"]).alias("cbscode"), | ||
pl.lit(row["amsterdamcode"]).alias("amsterdamcode"), | ||
pl.lit(row["Municipality"]).alias("Municipality"), | ||
) | ||
) | ||
except Exception as e: | ||
print(e) | ||
df = pl.concat(df_list) | ||
df = df.with_columns( | ||
compute_binomial_interval(df["n_both"], df["n_location"]) | ||
) | ||
df = df.with_columns(compute_binomial_interval(df["n_both"], df["n_location"])) | ||
return df | ||
|
||
res = query_map(r"choler.*|krim.?koorts", 1866) | ||
|
||
res.write_ | ||
res = query_space(r"choler.*|krim.?koorts", 1866) | ||
|
||
res.sort(["Municipality", "yr", "mo"]) | ||
|
||
res.write_parquet(Path("processed_data", "cholera_1866.parquet")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters