import pandas as pd
import geopandas as gpd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib as mpl
import libpysal as ps
from mgwr.gwr import GWR, MGWR
from mgwr.sel_bw import Sel_BW
import scipy as sp
from matplotlib_scalebar.scalebar import ScaleBar
from mgwr.utils import shift_colormap, truncate_colormap
import numpy as np
import itertools
import time
import statsmodels.api as sm
from sklearn import linear_model
from sklearn.metrics import mean_squared_error
import statsmodels.api as statm
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
df = pd.read_csv("Georgia/MGWR_session_results.csv")
gdf = gpd.read_file("Georgia/G_utm.shp")
df.columns
gdf.columns
gdf = gdf.merge(df,left_on='AreaKey',right_on='AreaKey',how='inner')
gdf.columns
#Trial
gdf.plot('beta_PctRural')
t_crit = [2.809,2.168,2.744,2.216,2.169,2.159]
t_cols = ['t_Intercept','t_PctRural', 't_PctBach', 't_PctEld', 't_PctFB', 't_PctBlack']
b_cols = [ 'beta_Intercept', 'beta_PctRural', 'beta_PctBach', 'beta_PctEld','beta_PctFB','beta_PctBlack']
bt_cols = [ 'bt_Intercept', 'bt_PctRural', 'bt_PctBach', 'bt_PctEld','bt_PctFB','bt_PctBlack']
for i in range(6):
gdf.loc[gdf[t_cols[i]] >=t_crit[i], bt_cols[i]] = gdf[b_cols[i]]
gdf.loc[gdf[t_cols[i]] <=-t_crit[i], bt_cols[i]] = gdf[b_cols[i]]
gdf['bt_PctRural']
gdf = gdf.fillna(0.0)
##Significant estimates for Local Intercept
fig, ax = plt.subplots(figsize=(10,7))
gdf.plot(column='bt_Intercept',cmap='coolwarm', ax=ax, linewidth=0.01,scheme ='FisherJenks',legend=True,k=5)
gdf[gdf['bt_Intercept']==0].plot(color='white',ax=ax,**{'edgecolor':'grey', 'alpha':1,'linewidth':1},legend=False)
ax.margins(0)
ax.tick_params(left=False, labelleft=False, bottom=False, labelbottom=False)
ax.axis("off")
#'bt_Intercept', 'bt_PctRural', 'bt_PctBach', 'bt_PctEld','bt_PctFB'
#Significant estimates for Pct Rural
fig, ax = plt.subplots(figsize=(10,7))
gdf.plot(column='bt_PctRural',cmap='coolwarm', ax=ax, linewidth=0.01,scheme ='FisherJenks',legend=True,k=1)
gdf[gdf['bt_PctRural']==0].plot(color='white',ax=ax,**{'edgecolor':'grey', 'alpha':1,'linewidth':1},legend=False)
ax.margins(0)
ax.tick_params(left=False, labelleft=False, bottom=False, labelbottom=False)
ax.axis("off")
#Significant estimates for bt_PctBach
fig, ax = plt.subplots(figsize=(10,7))
gdf.plot(column='bt_PctBach',cmap='Blues_r', ax=ax, linewidth=0.01,scheme ='FisherJenks',legend=True,k=5)
gdf[gdf['bt_PctBach']==0].plot(color='white',ax=ax,**{'edgecolor':'grey', 'alpha':1,'linewidth':1},legend=False)
ax.margins(0)
ax.tick_params(left=False, labelleft=False, bottom=False, labelbottom=False)
ax.axis("off")
#Significant estimates for bt_PctEld
fig, ax = plt.subplots(figsize=(10,7))
gdf.plot(column='bt_PctEld',cmap='Reds', ax=ax, linewidth=0.01,scheme ='FisherJenks',legend=True,k=5)
gdf[gdf['bt_PctEld']==0].plot(color='white',ax=ax,**{'edgecolor':'grey', 'alpha':1,'linewidth':1},legend=False)
ax.margins(0)
ax.tick_params(left=False, labelleft=False, bottom=False, labelbottom=False)
ax.axis("off")
#Significant estimates for bt_PctFB
fig, ax = plt.subplots(figsize=(10,7))
gdf.plot(column='bt_PctFB',cmap='Reds', ax=ax, linewidth=0.01,scheme ='FisherJenks',legend=True,k=1)
gdf[gdf['bt_PctFB']==0].plot(color='white',ax=ax,**{'edgecolor':'grey', 'alpha':1,'linewidth':1},legend=False)
ax.margins(0)
ax.tick_params(left=False, labelleft=False, bottom=False, labelbottom=False)
ax.axis("off")
#Significant estimates for bt_PctBlack
fig, ax = plt.subplots(figsize=(10,7))
gdf.plot(column='bt_PctBlack',cmap='Reds', ax=ax, linewidth=0.01,scheme ='FisherJenks',legend=True,k=5)
gdf[gdf['bt_PctBlack']==0].plot(color='white',ax=ax,**{'edgecolor':'grey', 'alpha':1,'linewidth':1},legend=False)
ax.margins(0)
ax.tick_params(left=False, labelleft=False, bottom=False, labelbottom=False)
ax.axis("off")