Package: covid-alberta
Covid AlbertaThis is a small package that I have developed to look at some of the alberta specific covid data.This file will become your README and also the index of your documentation.Installpip install covid_albertaWeb ScraperThealbertaC19is a class that scrapes the updated stats off of thealberta Covid-19 website.example of using the webscraperabC19scaper = 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 dataframesab_totals.tail()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>cum_casesConfirmed_countProbable_countDaily_countActive_cumDied_cumRecovered_cum2020-04-041250381957618233222020-04-051308352358676243822020-04-061344201636712274492020-04-071409392665776275182020-04-081423951487629518ab_regions.tail()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Calgary_cumulativeCentral_cumulativeEdmont_cumulativeNorth_cumulativeSouth_cumulativeUnknown_cumulative2020-04-0477861315751922020-04-0580165340792122020-04-0682165348862222020-04-0785472364942322020-04-088607236895262ab_testing.tail()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>test_count2020-04-0417372020-04-0511122020-04-0611292020-04-0713192020-04-08459These are all pandas DataFrames. For more info on using pandas check out the pandascookbook.analysisthese are functions that I have started working on for some quick analyses of the data. The main one being doubling ratesDoubling timesthecalculate_doublingtimesfunction returns 2 columns.dtimeis how many days our count has been doubling from the first reported case to get to todays case countdtime_rwis 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 liketotals_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()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>dtimedtime_rw2020-04-042.8188977.1199922020-04-052.8976707.3535862020-04-062.9829739.6133342020-04-073.05914011.6171912020-04-083.15044217.176893regions_dt.tail()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Calgary_dtimeCalgary_dtime_rwCentral_dtimeCentral_dtime_rwEdmont_dtimeEdmont_dtime_rwNorth_dtimeNorth_dtime_rwSouth_dtimeSouth_dtime_rwUnknown_dtimeUnknown_dtime_rw2020-04-043.0196937.2969034.04671414.7356653.8723645.8646233.6925148.1414934.4727697.609425002020-04-053.1102087.5873494.15119112.8265713.9563756.2618733.8072398.0086294.5534056.431655002020-04-063.2020709.9708584.31723918.6377024.0828348.6361923.8902857.9592554.7091206.000000002020-04-073.28606512.1817634.37606615.4414204.18903711.3097713.9666878.0296144.8634247.289318002020-04-083.38524319.6560614.53814320.8854054.32363915.8351584.1096799.3879344.8931598.56604800PlotsHere 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 tomy websiteI'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'})