Ejemplo n.º 1
0
    def test_local_multijoincount(self):
        columbus = pygeoda.open("./data/columbus.shp")
        columbus_q = pygeoda.queen_weights(columbus)
        nsa = columbus.GetRealCol("nsa")
        nsb = columbus.GetRealCol("nsb")
        nndata = (nsa, nsb)

        #The following two lines will raise warning to use local_bijoincount()
        #nsa_inv = [1-i for i in nsa]
        #lisa = pygeoda.local_multijoincount(columbus_q, (nsa, nsa_inv))

        lisa = pygeoda.local_multijoincount(columbus_q, nndata)

        lvals = lisa.lisa_values()
        self.assertEqual(lvals[0], 2)
        self.assertEqual(lvals[1], 3)
        self.assertEqual(lvals[2], 4)

        pvals = lisa.lisa_pvalues()
        self.assertEqual(pvals[0], 0.213000)
        self.assertEqual(pvals[1], 0.070000)
        self.assertEqual(pvals[2], 0.017000)

        nnvals = lisa.lisa_num_nbrs()
        self.assertEqual(nnvals[0], 2)
        self.assertEqual(nnvals[1], 3)
        self.assertEqual(nnvals[2], 4)
Ejemplo n.º 2
0
 def setUp(self):
     self.guerry = pygeoda.open("./data/Guerry.shp")
     self.queen_w = pygeoda.queen_weights(self.guerry)
     self.crm_prp = self.guerry.GetIntegerCol("Crm_prp")
     self.litercy = self.guerry.GetIntegerCol("Litercy")
     slect_vars = ['Crm_prp','Crm_prs']
     self.data = [self.guerry.GetRealCol(v) for v in slect_vars]
Ejemplo n.º 3
0
 def setUp(self):
     self.guerry = pygeoda.open("./data/Guerry.shp")
     self.queen_w = pygeoda.queen_weights(self.guerry)
     self.data = self.guerry[[
         "Crm_prs", "Crm_prp", "Litercy", "Donatns", "Infants", "Suicids"
     ]]
     self.bound_variable = self.guerry.GetRealCol("Pop1831")
     self.min_bound = 3236.67  # 10% of Pop1831
Ejemplo n.º 4
0
 def setUp(self):
     self.guerry = pygeoda.open("./data/Guerry.shp")
     self.queen_w = pygeoda.queen_weights(self.guerry)
     select_vars = [
         "Crm_prs", "Crm_prp", "Litercy", "Donatns", "Infants", "Suicids"
     ]
     self.data = [self.guerry.GetRealCol(v) for v in select_vars]
     self.Crm_prs = self.guerry.GetRealCol('Crm_prs')
     self.Crm_prp = self.guerry.GetRealCol('Crm_prp')
Ejemplo n.º 5
0
    def test_local_bijoincount(self):
        columbus = pygeoda.open("./data/columbus.shp")
        columbus_q = pygeoda.queen_weights(columbus)
        nsa = columbus.GetRealCol("nsa")
        nsa_inv = [1-i for i in nsa]
        lisa = pygeoda.local_bijoincount(columbus_q, [nsa, nsa_inv])

        jc = lisa.lisa_values()
        self.assertEqual(jc[7], 0)
        self.assertEqual(jc[8], 1)
        self.assertEqual(jc[9], 1)

        pvals = lisa.lisa_pvalues()
        self.assertEqual(pvals[8], 0.002)
        self.assertEqual(pvals[9], 0.034)

        nn = lisa.lisa_num_nbrs()
        self.assertEqual(nn[0], 2)
        self.assertEqual(nn[1], 3)
        self.assertEqual(nn[2], 4)
Ejemplo n.º 6
0
    def test_local_joincount(self):
        columbus = pygeoda.open("./data/columbus.shp")
        columbus_q = pygeoda.queen_weights(columbus)
        nsa = columbus.GetRealCol("nsa")

        lisa = pygeoda.local_joincount(columbus_q, nsa)

        lvals = lisa.lisa_values()
        self.assertEqual(lvals[0], 2)
        self.assertEqual(lvals[1], 3)
        self.assertEqual(lvals[2], 4)

        pvals = lisa.lisa_pvalues()
        self.assertEqual(pvals[0], 0.21299999999999999)
        self.assertEqual(pvals[1], 0.070000000000000007)
        self.assertEqual(pvals[2], 0.017000000000000001)

        nnvals = lisa.lisa_num_nbrs()
        self.assertEqual(nnvals[0], 2)
        self.assertEqual(nnvals[1], 3)
        self.assertEqual(nnvals[2], 4)
import pygeoda
import os
from sys import argv
import matplotlib
import matplotlib.pyplot as plt
import geopandas


# 输入shp文件
dataPath = argv[1]
feild = argv[2]
randomSed = int(argv[3])
filter = float(argv[4])
cpu=int(argv[5])

data = pygeoda.open(dataPath)
queen_w = pygeoda.weights.queen(data)
fieldCol = data.GetIntegerCol(feild)
lisa = pygeoda.local_moran(queen_w, fieldCol)
lisa.SetPermutations(randomSed)
lisa.SetThreads(cpu)
lisa.Run()


lisa_colors = lisa.GetColors()
lisa_labels = lisa.GetLabels()

lisa_cluster = lisa.GetClusterIndicators()
list_p_value = lisa.GetPValues()

fig, ax = plt.subplots(figsize=(10, 10))
Ejemplo n.º 8
0
 def setUp(self):
     self.guerry = pygeoda.open("./data/Guerry.shp")
     self.crm_prp = self.guerry.GetIntegerCol("Crm_prp")
Ejemplo n.º 9
0
import time
import sys
"""
Usage: 
python3 perf_pygeoda.py FILE_PATH VARIABLE_NAME PERMUTATIONS PERMUTATION_METHOD CPU_THREADS
python3 perf_pygeoda.py ./data/natregimes.shp HR60 999 brutal-force 1
python3 perf_pygeoda.py ./data/natregimes.shp HR60 999 lookup-table 8
"""
data_path = sys.argv[1]
var_name = sys.argv[2]
perms = int(sys.argv[3])
perm_method = sys.argv[4]
cpu_threads = int(sys.argv[5])

# prepare the data and weights
dt = pygeoda.open(data_path)
if data_path == './data/Chicago_parcels_points.shp':
    w = pygeoda.weights.knn_weights(dt, 10)
else:
    w = pygeoda.weights.queen_weights(dt)
x = dt.GetRealCol(var_name)

# time it
start_time = time.time()
lisa = pygeoda.local_moran(w,
                           x,
                           permutations=perms,
                           permutation_method=perm_method,
                           cpu_threads=cpu_threads)
run_time = time.time() - start_time
Ejemplo n.º 10
0
 def setUp(self):
     self.nat = pygeoda.open("./data/natregimes.shp")
     self.poly_id = self.nat.GetIntegerCol("POLY_ID")
Ejemplo n.º 11
0
import pygeoda

sdoh = pygeoda.open("./data/us-sdoh-2014-chi_utm.shp")
v = ("1_SES", "2_MOB", "3_URB", "4_MICA")
chsdoh = pygeoda.neighbor_match_test(sdoh, v, 8)
print(chsdoh)
Ejemplo n.º 12
0
import pygeoda

snow = pygeoda.open("./data/deaths_nd_by_house.shp")
v = snow.GetIntegerCol("death_dum")
d20 = pygeoda.weights.distance_weights(snow, dist_thres=20)
print(d20)
snowjc = pygeoda.local_joincount(d20,
                                 v,
                                 permutations=99999,
                                 significance_cutoff=0.01)
snowsig = snowjc.lisa_clusters()
pval = snowjc.lisa_pvalues()
print(sum(snowsig))