def setUp(self): f = lp.open(lp.get_path("mexico.csv")) vnames = ["pcgdp%d" % dec for dec in range(1940, 2010, 10)] y = np.transpose(np.array([f.by_col[v] for v in vnames])) self.y = y[:, 0] regimes = np.array(f.by_col('hanson98')) self.w = lp.block_weights(regimes)
def test_fuzzy_contiguity(self): import libpysal.api as lps import geopandas as gpd rs = lps.get_path('map_RS_BR.shp') rs_df = gpd.read_file(rs) wf = lps.fuzzy_contiguity(rs_df) self.assertEqual(wf.islands, []) self.assertEqual(set(wf.neighbors[0]), set([239, 59, 152, 23, 107]))
def test___init__(self): f = lp.open(lp.get_path("mexico.csv")) vnames = ["pcgdp%d" % dec for dec in range(1940, 2010, 10)] y = np.transpose(np.array([f.by_col[v] for v in vnames])) regimes = np.array(f.by_col('hanson98')) np.random.seed(10) theil_ds = TheilDSim(y, regimes, 999) np.testing.assert_almost_equal( theil_ds.bg_pvalue, np.array([0.4, 0.344, 0.001, 0.001, 0.034, 0.072, 0.032]))
def test___init__(self): # theil = Theil(y) f = lp.open(lp.get_path("mexico.csv")) vnames = ["pcgdp%d" % dec for dec in range(1940, 2010, 10)] y = np.transpose(np.array([f.by_col[v] for v in vnames])) theil_y = Theil(y) np.testing.assert_almost_equal( theil_y.T, np.array([ 0.20894344, 0.15222451, 0.10472941, 0.10194725, 0.09560113, 0.10511256, 0.10660832 ]))
def test___init__(self): # theil_d = TheilD(y, partition) f = lp.open(lp.get_path("mexico.csv")) vnames = ["pcgdp%d" % dec for dec in range(1940, 2010, 10)] y = np.transpose(np.array([f.by_col[v] for v in vnames])) regimes = np.array(f.by_col('hanson98')) theil_d = TheilD(y, regimes) np.testing.assert_almost_equal( theil_d.bg, np.array([ 0.0345889, 0.02816853, 0.05260921, 0.05931219, 0.03205257, 0.02963731, 0.03635872 ]))
def test_nonplanar_neighbors(self): import libpysal.api as lp import geopandas as gpd df = gpd.read_file(lp.get_path('map_RS_BR.shp')) w = lp.Queen.from_dataframe(df) self.assertEqual(w.islands, [ 0, 4, 23, 27, 80, 94, 101, 107, 109, 119, 122, 139, 169, 175, 223, 239, 247, 253, 254, 255, 256, 261, 276, 291, 294, 303, 321, 357, 374 ]) import libpysal wnp = libpysal.weights.util.nonplanar_neighbors(w, df) self.assertEqual(wnp.islands, []) self.assertEqual(w.neighbors[0], []) self.assertEqual(wnp.neighbors[0], [23, 59, 152, 239]) self.assertEqual(wnp.neighbors[23], [0, 45, 59, 107, 152, 185, 246])