This file will become your README and also the index of your documentation.
pip install covid_alberta
Web Scraper
The albertaC19
is a class that scrapes the updated stats off of the alberta Covid-19 website.
example of using the webscraper
abC19scaper = covid_alberta.albertaC19(outputfolder="")
# I don't plan on writing out the data in this example thus the keywords
ab_totals, ab_regions, ab_testing = abC19scaper.scrape_all(fltypes=None, return_dataframes=True)
Now we can show the dataframes
ab_totals.tail()
ab_regions.tail()
ab_testing.tail()
These are all pandas DataFrames. For more info on using pandas check out the pandas cookbook.
analysis
these are functions that I have started working on for some quick analyses of the data. The main one being doubling rates
Doubling times
the calculate_doublingtimes
function returns 2 columns.
dtime
is how many days our count has been doubling from the first reported case to get to todays case count
dtime_rw
is a rolling window calcualtion. So if you window is 6 days it looks at what our doubling rate, starting from the case count 6 days ago, would have to be to get to todays case count.
I started off looking at the rolling window calculation. However the more I look into it the more I'm not happy with using the rolling window. Our information about Covid-19 cases are changing so rapidly, that the rolling window calculation tends to be too noisy and too optimistic to be useful. We can calculate both below and see what they look like
totals_dt = covid_alberta.calculate_doublingtimes(ab_totals, col_suffix="cum_cases", combine_df=False)
regions_dt = covid_alberta.calculate_doublingtimes(ab_regions, col_suffix="cumulative", combine_df=False)
totals_dt.tail()
regions_dt.tail()
Plots
Here is some of the plots I've used for looking at the data. For this example I'm using matplotlib. Plotly creates nice plots but is a little harder to include in this documentation since it's hosted on github pages. If you head over to my website I'll post the plotly code and example of the interactive plots there.
import matplotlib.pyplot as plt
# Set defaults and settings
days_to_trim = 1
date_fmt = "%B %d"
# Grab the data we want for the plots and trim the last day off
plt_totals = ab_totals[:-days_to_trim]
plt_total_dt = totals_dt[:-days_to_trim]
plt_regions = ab_regions[:-days_to_trim]
plt_regions_dt = regions_dt[:-days_to_trim]
# use a format dictionary so I only have to set them in one location
fmt = {'alb': {'x_data': plt_totals['cum_cases'],
'y_data': plt_total_dt['dtime'],
'last_date': plt_totals.index.strftime(date_fmt)[-1],
'annot_x': plt_totals['cum_cases'][-1],
'annot_y': plt_total_dt['dtime'][-1],
'color': 'green',
'label': 'Alberta'},
'cal': {'x_data': plt_regions['Calgary_cumulative'],
'y_data': plt_regions_dt['Calgary_dtime'],
'last_date': plt_regions.index.strftime(date_fmt)[-1],
'annot_x': plt_regions['Calgary_cumulative'][-1],
'annot_y': plt_regions_dt['Calgary_dtime'][-1],
'color': 'orange',
'label': 'Calgary'},
'edm': {'x_data': plt_regions['Edmont_cumulative'],
'y_data': plt_regions_dt['Edmont_dtime'],
'last_date': plt_regions.index.strftime(date_fmt)[-1],
'annot_x': plt_regions['Edmont_cumulative'][-1],
'annot_y': plt_regions_dt['Edmont_dtime'][-1],
'color': 'blue',
'label': 'Edmonton'},
}
# Setup the plot
fig, ax = plt.subplots(figsize=(8,6))
# Create the scatter plots using a loop and the dictionary above
for rgn in ['alb', 'cal', 'edm']:
ax.plot(fmt[rgn]['x_data'], fmt[rgn]['y_data'],
c=fmt[rgn]['color'], label=fmt[rgn]['label'])
# add an annotation to the last point
for rgn in ['alb', 'cal', 'edm']:
ax.plot(fmt[rgn]['annot_x'], fmt[rgn]['annot_y'], 'o', c=fmt[rgn]['color'])
ax.text(fmt[rgn]['annot_x'] - 60, fmt[rgn]['annot_y'] + 0.08, fmt[rgn]['last_date'],
fontdict={'color': fmt[rgn]['color'], 'size': 8, 'weight': 'bold'})
# fancy up the plot
ax.grid(which='both', linestyle=(0, (5, 3)), lw=0.5)
ax.legend(frameon=True, fancybox=True, shadow=True)
ax.set_ylabel('Doubling Time (Days)', fontdict={'size': 9, 'family': 'sans-serif', 'style':'italic'})
ax.set_xlabel('Cumulative Case Count', fontdict={'size': 9, 'family': 'sans-serif', 'style':'italic'})
title = ax.set_title("Alberta: Doubling Time by Cumulative Cases",
fontdict={'fontsize': 10, 'family': 'sans-serif', 'fontweight': 'bold'})