Beispiel #1
0
def test_moran_loc_bv_scatterplot():
    link_to_data = examples.get_path('Guerry.shp')
    gdf = gpd.read_file(link_to_data)
    x = gdf['Suicids'].values
    y = gdf['Donatns'].values
    w = Queen.from_dataframe(gdf)
    w.transform = 'r'
    # Calculate Univariate and Bivariate Moran
    moran_loc = Moran_Local(y, w)
    moran_loc_bv = Moran_Local_BV(x, y, w)
    # try with p value so points are colored
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv)
    plt.close(fig)

    # try with p value and different figure size
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv,
                                       p=0.05,
                                       aspect_equal=False)
    plt.close(fig)

    assert_raises(ValueError, _moran_loc_bv_scatterplot, moran_loc, p=0.5)
    assert_warns(UserWarning,
                 _moran_loc_bv_scatterplot,
                 moran_loc_bv,
                 p=0.5,
                 scatter_kwds=dict(c='r'))
Beispiel #2
0
def test_moran_loc_bv_scatterplot():
    link_to_data = examples.get_path('Guerry.shp')
    gdf = gpd.read_file(link_to_data)
    x = gdf['Suicids'].values
    y = gdf['Donatns'].values
    w = Queen.from_dataframe(gdf)
    w.transform = 'r'
    # Calculate Bivariate Moran
    moran_loc_bv = Moran_Local_BV(x, y, w)
    # try with p value so points are colored
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv)
    plt.close(fig)

    # try with p value and different figure size
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv, p=0.05)
    plt.close(fig)
Beispiel #3
0
def test_moran_scatterplot():
    gdf = _test_data()
    x = gdf['Suicids'].values
    y = gdf['Donatns'].values
    w = Queen.from_dataframe(gdf)
    w.transform = 'r'
    # Calculate `esda.moran` Objects
    moran = Moran(y, w)
    moran_bv = Moran_BV(y, x, w)
    moran_loc = Moran_Local(y, w)
    moran_loc_bv = Moran_Local_BV(y, x, w)
    # try with p value so points are colored or warnings apply
    fig, _ = moran_scatterplot(moran, p=0.05, aspect_equal=False)
    plt.close(fig)
    fig, _ = moran_scatterplot(moran_loc, p=0.05)
    plt.close(fig)
    fig, _ = moran_scatterplot(moran_bv, p=0.05)
    plt.close(fig)
    fig, _ = moran_scatterplot(moran_loc_bv, p=0.05)
    plt.close(fig)
Beispiel #4
0
def test_moran_scatterplot():
    link_to_data = examples.get_path('Guerry.shp')
    gdf = gpd.read_file(link_to_data)
    x = gdf['Suicids'].values
    y = gdf['Donatns'].values
    w = Queen.from_dataframe(gdf)
    w.transform = 'r'
    # Calculate `esda.moran` Objects
    moran = Moran(y, w)
    moran_bv = Moran_BV(y, x, w)
    moran_loc = Moran_Local(y, w)
    moran_loc_bv = Moran_Local_BV(y, x, w)
    # try with p value so points are colored or warnings apply
    fig, _ = moran_scatterplot(moran, p=0.05)
    plt.close(fig)
    fig, _ = moran_scatterplot(moran_loc, p=0.05)
    plt.close(fig)
    fig, _ = moran_scatterplot(moran_bv, p=0.05)
    plt.close(fig)
    fig, _ = moran_scatterplot(moran_loc_bv, p=0.05)
    plt.close(fig)
Beispiel #5
0
def test_moran_loc_bv_scatterplot():
    gdf = _test_data()
    x = gdf['Suicids'].values
    y = gdf['Donatns'].values
    w = Queen.from_dataframe(gdf)
    w.transform = 'r'
    # Calculate Univariate and Bivariate Moran
    moran_loc = Moran_Local(y, w)
    moran_loc_bv = Moran_Local_BV(x, y, w)
    # try with p value so points are colored
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv)
    plt.close(fig)

    # try with p value and different figure size
    fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv, p=0.05,
                                       aspect_equal=False)
    plt.close(fig)

    raises(ValueError, _moran_loc_bv_scatterplot, moran_loc, p=0.5)
    warns(UserWarning, _moran_loc_bv_scatterplot, moran_loc_bv, p=0.5,
                 scatter_kwds=dict(c='r'))
Beispiel #6
0
distGeo170['dist'] = np.array(distGeo170['DIST_CODE'].values).astype(int)
# distGeo170 = gpd.read_file("data/geo2_gh2010.gpkg")
# distGeo170['dist'] = np.array(distGeo170['DIST2010'].values).astype(int)
x = pd.read_csv('data/data_fromR.csv')
distGeo170 = pd.merge(distGeo170,
                      x,
                      left_on='dist',
                      right_on='dist',
                      how='outer')

w = weights.Queen.from_dataframe(distGeo170)

for tempYear in [2010, 2013, 2017]:
    tempVar1 = 'sachet_usage_' + str(tempYear)
    tempVar2 = 'HH_DENSITY_' + str(tempYear)
    moran_loc_bv = Moran_Local_BV(distGeo170[tempVar1], distGeo170[tempVar2],
                                  w)
    distGeo170['p_sim_' + str(tempYear)] = moran_loc_bv.p_sim
    distGeo170['q_' + str(tempYear)] = moran_loc_bv.q

dist_geo_170_lisa = distGeo170.copy()
dist_geo_170_lisa.to_file('data/dist_geo_170_updated.gpkg',
                          driver='GPKG',
                          index=True)

## Spatial autocorrelation of sachet drinking consuming
## regions in 2010, 2013 and 2017

## Calculate spatial autocorrelation for the consumption rate of sachet water
w = weights.Queen.from_dataframe(distGeo170)
w.transform = 'r'
moran_I = []
Beispiel #7
0
def moran_local_bv(dataset):
    x = dataset['AVG_SUICIDE_RATE'].values
    y = dataset['AVG_DISEASE_RATE'].values
    moran_bv = Moran_Local_BV(y, x, weights)
    return moran_bv