In [1]:
# local
from fludashboard.libs.flu_data import prepare_keys_name
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
In this example, we show the current year incidence up to given week.
Along with the current incidence, we present the following intensity thresholds:
Low activity threshold: estimated epidemic threshold based on historical levels. Minimum: incidence equivalent to 5 cases.
High activity threshold: incidence considered high based on historical levels. Minimum: incidence equivalent to 10 cases.
Very high activity threshold: incidence considered very high based on historical levels. Minimum: incidence equivalent to 20 cases.
In [2]:
df_hist = pd.read_csv('../data/historical_estimated_values.csv', encoding='utf-8')
df_inci = pd.read_csv('../data/current_estimated_values.csv', encoding='utf-8')
df_typi = pd.read_csv('../data/mem-typical.csv', encoding='utf-8')
df_thre = pd.read_csv('../data/mem-report.csv', encoding='utf-8')
prepare_keys_name(df_hist)
prepare_keys_name(df_inci)
prepare_keys_name(df_typi)
prepare_keys_name(df_thre)
level_dict = {
'L0': 'Baixa',
'L1': 'Epidêmica',
'L2': 'Alta',
'L3': 'Muito alta'
}
In [3]:
df_inci.columns
Out[3]:
In [4]:
df_inci.head(5)
Out[4]:
In [5]:
df_typi.head(5)
Out[5]:
In [6]:
df_thre.tail(5)
Out[6]:
Entries with dfthresholds['se típica do inicio do surto'] = NaN have activity too low for proper epidemic threshold definition
In [18]:
k = ['epiyear', 'epiweek', 'base_epiyear', 'base_epiweek']
df_inci2017 = df_inci[
(df_inci.epiyear == 2017) &
# (df_inci.epiweek >= 15) &
(df_inci.dado == 'srag') &
(df_inci.escala == 'incidência') &
(df_inci.uf == 'BR')
].copy()
df_inci2017.sort_values(['epiyear', 'epiweek'], inplace=True)
df_inci_chart = df_inci2017.copy()
df_inci_chart.index = df_inci_chart.epiweek
In [19]:
k = ['epiyear', 'epiweek', 'base_epiyear', 'base_epiweek']
df_hist2017 = df_hist[
(df_hist.base_epiyear == 2017) &
(df_hist.base_epiweek == 23) &
(df_hist.dado == 'srag') &
(df_hist.escala == 'incidência') &
(df_hist.uf == 'BR')
].copy()
df_hist2017.sort_values(['epiyear', 'epiweek'], inplace=True)
df_hist_chart = df_hist2017.copy()
df_hist_chart.index = df_hist_chart.epiweek
In [20]:
# 50% estimated cases
df_inci_chart[['srag', '50%', '2.5%', '97.5%']].plot()
plt.title('Incidence')
plt.grid(True)
plt.show()
df_hist_chart[['srag', '50%', '2.5%', '97.5%']].plot()
plt.title('Historial')
plt.grid(True)
plt.show()
In [21]:
df_hist2017['estimated_cases'] = df_hist2017['50%']
df = pd.merge(
df_inci2017[['epiweek', 'srag', '2.5%', '97.5%']],
df_hist2017[['epiweek', 'estimated_cases']],
on='epiweek', how='outer'
)
df.set_index('epiweek', inplace=True)
df.plot()
plt.grid(True)
plt.title('Incidence X Historial')
plt.show()
For each week w selected by the user, the notification curve will always be that which is found on df_inci, while the estimates will be that stored in df_hist. Data df_inci only has the most recent estimates, which are based on the most recent week with data. The estimates obtained at each week is stored at df_hist.
So, first of all, we will slice the historical data to week w, and limit current data to week <= w. If w=23, the historical dataset is already correctly sliced in df_hist2017, so we just have to limit the current for the proper plot:
In [22]:
df_hist[
(df_hist.base_epiyear == 2017) &
(df_hist.dado == 'srag') &
(df_hist.escala == 'incidência') &
(df_hist.uf == 'BR')
].base_epiweek.unique()
Out[22]:
In [23]:
# First, last keep only stable weeksfor notification curve:
df_inci2017.loc[(df_inci2017.situation != 'stable'), 'srag'] = np.nan
# Adapt historical dataset:
df_hist.sort_values(['epiyear', 'epiweek'], inplace=True)
df_hist['estimated_cases'] = df_hist['50%']
# User selected week:
y = 2017
w = 23
def week_data(y, w):
df_week_inci = df_inci2017[(df_inci2017.epiweek <= w)]
df_week_hist = df_hist[
(df_hist.base_epiyear == y) &
(df_hist.base_epiweek == w) &
(df_hist.dado == 'srag') &
(df_hist.escala == 'incidência') &
(df_hist.uf == 'BR')
].copy()
df = pd.merge(
df_week_inci[['epiweek', 'srag']],
df_week_hist[['epiweek', 'estimated_cases', '2.5%', '97.5%']],
on='epiweek', how='outer'
)
df.set_index('epiweek', inplace=True)
return df
df = week_data(y, w)
df.plot()
plt.grid(True)
plt.show()
In [13]:
w = 28
df = week_data(y, w)
df.plot()
plt.grid(True)
plt.show()
In [14]:
w = 33
df = week_data(y, w)
df.plot()
plt.grid(True)
plt.show()