def heatmap_Hepatitis_A(): Hepatitis_A = heatmap_disease_matrix('Hepatitis A') Hepatitis_A = Hepatitis_A.drop([ 'GUAM', 'PAC TRUST TERR', 'AMERICAN SAMOA', 'NORTHERN MARIANA ISLANDS' ], axis=1) fig, ax = plt.subplots(figsize=(15, 15)) flatui = [ '#ecf0f1', '#bdc3c7', '#95a5a6', '#7f8c8d', '#f1c40f', '#f39c12', '#d35400', '#e74c3c' ] sns.set_palette(flatui) my_cmap = ListedColormap(flatui) sns.set(font_scale=1.2) sns.set_style({"savefig.dpi": 500}) ax = sns.heatmap(Hepatitis_A.T, linewidths=.20, cmap=my_cmap, ax=ax, vmin=0, vmax=500, xticklabels=5) ax.set_title('Hepatitis A', fontsize=18, fontweight='bold') ax.axvline(x=22, color='k', linewidth=2.5) ax.text(22, 0.5, ' Vaccine introduced', fontsize=10, fontweight='bold') plt.yticks(rotation='horizontal') fig.tight_layout() fig.savefig('Heatmap of Hepatitis_A.pdf')
def heatmap_Mumps(): Mumps = heatmap_disease_matrix('Mumps') fig, ax = plt.subplots(figsize=(15, 15)) flatui = [ '#ecf0f1', '#bdc3c7', '#95a5a6', '#7f8c8d', '#f1c40f', '#f39c12', '#d35400', '#e74c3c' ] sns.set_palette(flatui) my_cmap = ListedColormap(flatui) sns.set(font_scale=1.2) sns.set_style({"savefig.dpi": 500}) ax = sns.heatmap(Mumps.T, linewidths=.20, cmap=my_cmap, ax=ax, vmin=0, vmax=2500, xticklabels=5) ax.set_title('Mumps', fontsize=18, fontweight='bold') ax.axvline(x=10, color='k', linewidth=3) ax.text(10.3, 0.5, ' Vaccine introduced', fontsize=10, fontweight='bold') plt.yticks(rotation='horizontal') fig.tight_layout() fig.savefig('Heatmap of Mumps.pdf')
def heatmap_Smallpox(): Smallpox = heatmap_disease_matrix('Smallpox') Smallpox = Smallpox.drop(Smallpox.index[list(range(27))]) fig, ax = plt.subplots(figsize=(15, 15)) flatui = [ '#ecf0f1', '#bdc3c7', '#95a5a6', '#7f8c8d', '#f1c40f', '#f39c12', '#d35400', '#e74c3c' ] sns.set_palette(flatui) my_cmap = ListedColormap(flatui) sns.set(font_scale=1.2) sns.set_style({"savefig.dpi": 500}) ax = sns.heatmap(Smallpox.T, linewidths=.20, cmap=my_cmap, ax=ax, vmin=0, vmax=500, xticklabels=2) ax.set_title('Smallpox', fontsize=18, fontweight='bold') ax.axvline(x=12, color='k', linewidth=3) ax.text(12, 0.3, ' Vaccine introduced', fontsize=10, fontweight='bold') plt.yticks(rotation='horizontal') fig.tight_layout() fig.savefig('Heatmap of Smallpox.pdf')
def heatmap_Measles(): Measles = heatmap_disease_matrix('Measles') Measles = Measles.loc[ 1928:] #drop rows before 1928 for measles, since missing data Measles = Measles.drop( [ 'GUAM', 'PAC TRUST TERR', 'AMERICAN SAMOA', 'NORTHERN MARIANA ISLANDS' ], axis=1) #drop those states with no recording numbers fig, ax = plt.subplots(figsize=(15, 15)) flatui = [ '#ecf0f1', '#bdc3c7', '#95a5a6', '#7f8c8d', '#f1c40f', '#f39c12', '#d35400', '#e74c3c' ] sns.set_palette(flatui) my_cmap = ListedColormap(flatui) sns.set(font_scale=1.2) sns.set_style({"savefig.dpi": 100}) ax = sns.heatmap(Measles.T, linewidths=.20, cmap=my_cmap, ax=ax, vmin=0, vmax=3000, xticklabels=5) ax.set_title('Measles', fontsize=18, fontweight='bold') ax.axvline(x=36, color='k', linewidth=2.5) ax.text(36, 0.1, ' Vaccine introduced', fontsize=10, fontweight='bold') plt.yticks(rotation='horizontal') fig.tight_layout() fig.savefig('Heatmap of Measles.pdf')
def heatmap_Rubella(): Rubella = heatmap_disease_matrix('Rubella') Rubella = Rubella.drop(['GUAM', 'PAC TRUST TERR', 'AMERICAN SAMOA'], axis=1) fig, ax = plt.subplots(figsize=(15, 15)) flatui = [ '#ecf0f1', '#bdc3c7', '#95a5a6', '#7f8c8d', '#f1c40f', '#f39c12', '#d35400', '#e74c3c' ] sns.set_palette(flatui) my_cmap = ListedColormap(flatui) sns.set(font_scale=1.2) sns.set_style({"savefig.dpi": 500}) ax = sns.heatmap(Rubella.T, linewidths=.20, cmap=my_cmap, ax=ax, vmin=0, vmax=1500, xticklabels=5) ax.set_title('Rubella', fontsize=18, fontweight='bold') ax.axvline(x=4, color='k', linewidth=3) ax.text(4, 0.3, ' Vaccine introduced', fontsize=10, fontweight='bold') plt.yticks(rotation='horizontal') fig.tight_layout() fig.savefig('Heatmap of Rubella.pdf')
def __init__(self, disease): self.name = disease if self.name not in disease_list: raise diseaseExceptioin() else: self.data = mt.heatmap_disease_matrix(disease) self.lower = self.data.index.min() self.upper = self.data.index.max()
def get_std_data_by_year(year, disease): data = mt.heatmap_disease_matrix(disease).ix[year] num_records = [ data[i.upper()] if i.upper() in data.index else 0 for i in state ] # to keep in the form of max_num = np.max(num_records) std_num_records = [i / max_num if max_num != 0 else 0 for i in num_records] return std_num_records #so define a exception class here.
def get_mean(disease): ''' Return the mean number of infected people before and after the year of vaccine invented, Note: in some cases the mean number before vaccine invented is NaN since our dataset doesn't have recorded data back to that time. ''' valid_list = [ 'measles', 'hepatitis_a', 'rubella', 'poliomyelitis', 'smallpox', 'mumps' ] if disease not in valid_list: raise InvalidDisease df = heatmap_disease_matrix(disease) df['sum_all_state'] = df.sum(axis=1) df = df[['sum_all_state']] if disease == 'measles': mean_before_vc = np.mean(df.loc[:Measles_vaccine_year]) mean_after_vc = np.mean(df.loc[Measles_vaccine_year:]) elif disease == 'hepatitis_a': mean_before_vc = np.mean(df.loc[:Hepatitis_A_vaccine_year]) mean_after_vc = np.mean(df.loc[Hepatitis_A_vaccine_year:]) elif disease == 'rubella': mean_before_vc = np.mean(df.loc[:Rubella_vaccine_year]) mean_after_vc = np.mean(df.loc[Rubella_vaccine_year:]) elif disease == 'poliomyelitis': mean_before_vc = np.mean(df.loc[:Poliomyelitis_vaccine_year]) mean_after_vc = np.mean(df.loc[Poliomyelitis_vaccine_year:]) elif disease == 'smallpox': mean_before_vc = np.mean(df.loc[:Smallpox_vaccine_year]) mean_after_vc = np.mean(df.loc[Smallpox_vaccine_year:]) else: mean_before_vc = np.mean(df.loc[:Mumps_vaccine_year]) mean_after_vc = np.mean(df.loc[Mumps_vaccine_year:]) return [mean_before_vc['sum_all_state'], mean_after_vc['sum_all_state']]
def detect_year(input_year, disease): data = mt.heatmap_disease_matrix(disease) if input_year in data.index: return True else: return False