Skip to content

Commit

Permalink
Oops forgot to commit the files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Zhao committed Sep 11, 2019
1 parent ba1e66f commit edee9ed
Show file tree
Hide file tree
Showing 149 changed files with 49,749 additions and 0 deletions.
18,319 changes: 18,319 additions & 0 deletions Interactive Map - Data Visualization.twb

Large diffs are not rendered by default.

Binary file added carbon/Adi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Aka.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Anglo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Arab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Armenian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Bagga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Baloch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Bania.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Bhar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Bhil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Brahmin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Bru.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Burmese.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Chak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Chang.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Chin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Christian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Deaf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Dom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Domar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Gond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Han Chinese.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Ho.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Jew.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Kambo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added carbon/Karan.png
Binary file added carbon/Karen.png
Binary file added carbon/Khas.png
Binary file added carbon/Kol.png
Binary file added carbon/Kom.png
Binary file added carbon/Kuki Chin.png
Binary file added carbon/Kunbi.png
Binary file added carbon/Lama.png
Binary file added carbon/Mahratta.png
Binary file added carbon/Malayali.png
Binary file added carbon/Mali.png
Binary file added carbon/Mandarin.png
Binary file added carbon/Mara.png
Binary file added carbon/Miji.png
Binary file added carbon/Mir.png
Binary file added carbon/Mon.png
Binary file added carbon/Monpa.png
Binary file added carbon/Munda.png
Binary file added carbon/Na.png
Binary file added carbon/Naga.png
Binary file added carbon/Nagar.png
Binary file added carbon/Pale.png
Binary file added carbon/Pan.png
Binary file added carbon/Pap.png
Binary file added carbon/Parsee.png
Binary file added carbon/Pashtun.png
Binary file added carbon/Pasi.png
Binary file added carbon/Persian.png
Binary file added carbon/Portuguese.png
Binary file added carbon/Rai.png
Binary file added carbon/Sali.png
Binary file added carbon/Shaikh.png
Binary file added carbon/Shan.png
Binary file added carbon/Sinhalese.png
Binary file added carbon/South Asian.png
Binary file added carbon/Tai.png
Binary file added carbon/Tak.png
Binary file added carbon/Tangsa.png
Binary file added carbon/Tibetan.png
Binary file added carbon/Toto.png
Binary file added carbon/Turkmen.png
Binary file added carbon/Vellalan.png
Binary file added carbon/Viswakarma.png
Binary file added carbon/Za.png
Binary file added carbon/Zo.png
Binary file added carbon/tribal.png
Binary file added climate/Adi.png
Binary file added climate/Aka.png
Binary file added climate/Anglo.png
Binary file added climate/Arab.png
Binary file added climate/Armenian.png
Binary file added climate/Bagga.png
Binary file added climate/Bania.png
Binary file added climate/Bhar.png
Binary file added climate/Bhil.png
Binary file added climate/Brahmin.png
Binary file added climate/Bru.png
Binary file added climate/Burmese.png
Binary file added climate/Chak.png
Binary file added climate/Chang.png
Binary file added climate/Chin.png
Binary file added climate/Christian.png
Binary file added climate/Deaf.png
Binary file added climate/Dom.png
Binary file added climate/Domar.png
Binary file added climate/Gond.png
Binary file added climate/Han Chinese.png
Binary file added climate/Ho.png
Binary file added climate/Jew.png
Binary file added climate/Kambo.png
Binary file added climate/Karen.png
Binary file added climate/Khas.png
Binary file added climate/Kol.png
Binary file added climate/Kom.png
Binary file added climate/Kuki Chin.png
Binary file added climate/Kunbi.png
Binary file added climate/Lama.png
Binary file added climate/Mahratta.png
Binary file added climate/Malayali.png
Binary file added climate/Mandarin.png
Binary file added climate/Mara.png
Binary file added climate/Miji.png
Binary file added climate/Mir.png
Binary file added climate/Mon.png
Binary file added climate/Na.png
Binary file added climate/Naga.png
Binary file added climate/Nagar.png
Binary file added climate/Pale.png
Binary file added climate/Pan.png
Binary file added climate/Pap.png
Binary file added climate/Pashtun.png
Binary file added climate/Pasi.png
Binary file added climate/Persian.png
Binary file added climate/Portuguese.png
Binary file added climate/Rai.png
Binary file added climate/Sali.png
Binary file added climate/Shaikh.png
Binary file added climate/Shan.png
Binary file added climate/Sinhalese.png
Binary file added climate/South Asian.png
Binary file added climate/Tai.png
Binary file added climate/Tak.png
Binary file added climate/Tangsa.png
Binary file added climate/Tibetan.png
Binary file added climate/Toto.png
Binary file added climate/Turkmen.png
Binary file added climate/Vellalan.png
Binary file added climate/Viswakarma.png
Binary file added climate/Za.png
Binary file added climate/Zo.png
Binary file added climate/atrisk/Mali.png
Binary file added climate/atrisk/Monpa.png
Binary file added climate/atrisk/Munda.png
Binary file added climate/outlier/Baloch.png
Binary file added climate/outlier/Karan.png
Binary file added climate/outlier/Parsee.png
Binary file added climate/tribal.png
239 changes: 239 additions & 0 deletions countries.csv

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions data_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from itertools import count
import matplotlib.font_manager

def weighted_avg_and_std(values, weights):
"""
Return the weighted average and standard deviation.
values, weights -- Numpy ndarrays with the same shape.
"""
average = np.average(values, weights=weights)
# Fast and numerically precise:
variance = np.average((values-average)**2, weights=weights)
return (average, np.sqrt(variance))

def calc_country_pop(country):
return np.sum(df.loc[df['Country'] == country]['Population'].values)

def normalize(df, feature_name):
result = df.copy()
try:
max_value = df[feature_name].max()
min_value = df[feature_name].min()
result[feature_name] = (df[feature_name] - min_value) / (
max_value - min_value)
except:
result[feature_name] = df[feature_name]
return result


data_path = 'C:/Users/Sejin/PycharmProjects/kaggle-python36/venv/urbana2018/data/merged_people_groups_20181203-climate_vuln.csv'
df = pd.read_csv(data_path, index_col=0)

key = 'cv_Mortality_Climate_total_2030 (Number of People)'

df = df.dropna(subset=[key, 'Population'])
countries = pd.read_csv('countries.csv')
mergedata = df.merge(countries, how='outer', left_on='Country', right_on='Country')
mergedata = mergedata.dropna(subset=[key, 'Population'])
mergedata[' PoplPeoples '] = [float(value.replace(',','')) for value in mergedata[' PoplPeoples ']]
df['risk'] = df[key].values/mergedata[' PoplPeoples '].values
df = normalize(df, 'risk')
# df

df.to_csv ('normClimateData.csv', sep=',')

key = 'risk'

subdf = df.loc[df['Country'].isin(['India'])]

pg_list = subdf['PeopNameAcrossCountries'].values
pg_set = set()

for pg in pg_list:
temp_pg_set = set(pg.replace(', ', ',').split(','))
pg_set = pg_set.union(temp_pg_set)
pgs = list(pg_set)
pgs.sort()

cm = plt.cm.get_cmap('RdYlBu_r')
all_avg, all_std = weighted_avg_and_std(df[key].values, df['Population'].values)

matplotlib.font_manager._rebuild()
matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
#names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
#print(names) # names

thin = {'fontname': 'Lato-Bold'}
bold = {'fontname': 'Lato', 'fontweight': 'bold'}

# numfigs = 146
for pg in pgs:
#print(pg)
subdf = df.loc[df['PeopNameAcrossCountries'].str.contains(pg)]
if subdf.shape[0] < 10:
continue
elif subdf[[key, 'Population']].isnull().any().any():
continue
x = subdf[key].values
weights = subdf['Population'].values
avg, std = weighted_avg_and_std(x, weights)

fig = plt.figure()
n, bins, patches = plt.hist(x, weights=weights, range=(min(df[key]), max(df[key])), align='mid')
bin_centers = 0.5 * (bins[:-1] + bins[1:])
col = bin_centers - min(bin_centers)
col /= max(col)

for c, p in zip(col, patches):
plt.setp(p, 'facecolor', cm(c))



#plt.rcParams['font.family'] = 'sans-serif'
#plt.rcParams['font.sans-serif'] = 'Lato'

plt.axvline(x=avg, color='r')
plt.errorbar(x=avg, y=max(n), xerr=std, ecolor='r', capsize=10)
plt.axvline(x=all_avg, color='k')
plt.errorbar(x=all_avg, y=max(n), xerr=all_std, ecolor='k', capsize=10)

plt.title(pg, bold)
plt.xlabel('2030 Climate Mortality Risk', bold)
plt.ylabel('Population', bold)

#plt.waitforbuttonpress()
fig.savefig(pg + '.png')
plt.close(fig)
print('Done')
Binary file added graphics/mockup-SouthAsia.png
Binary file added graphics/mockup-WorldMap.png
15,540 changes: 15,540 additions & 0 deletions normClimateData.csv

Large diffs are not rendered by default.

15,540 changes: 15,540 additions & 0 deletions normData.csv

Large diffs are not rendered by default.

0 comments on commit edee9ed

Please sign in to comment.