In [6]:
import arcpy as ARCPY
import arcgisscripting as ARC
import SSDataObject as SSDO
import SSUtilities as UTILS
import WeightsUtilities as WU
import numpy as NUM
import scipy as SCIPY
import pysal as PYSAL
import os as OS
import pandas as PANDAS

In [9]:
inputFC = r'../data/CA_Polygons.shp'
fullFC = OS.path.abspath(inputFC)
fullPath, fcName = OS.path.split(fullFC)
ssdo = SSDO.SSDataObject(inputFC)
uniqueIDField = "MYID"
fieldNames = ['GROWTH', 'LOGPCR69', 'POP1969', 'PERCNOHS']
ssdo.obtainData(uniqueIDField, fieldNames)
df = ssdo.getDataFrame()
print(df.head())


       GROWTH  LOGPCR69  PERCNOHS  POP1969
158  0.011426  0.176233      37.0  1060099
159 -0.137376  0.214186      38.3      398
160 -0.188417  0.067722      41.4    11240
161 -0.085070 -0.118248      42.9   101057
162 -0.049022 -0.081377      48.1    13328

In [10]:
import pysal2ArcGIS as PYSAL_UTILS
swmFile = OS.path.join(fullPath, "rook_bin.swm")
w = PYSAL_UTILS.swm2Weights(ssdo, swmFile)
maxp = PYSAL.region.Maxp(w, X[:,0:2], 3000000., floor_variable = X[:,2])
maxpGroups = NUM.empty((ssdo.numObs,), int)
for regionID, orderIDs in enumerate(maxp.regions):
    maxpGroups[orderIDs] = regionID
    print((regionID, orderIDs))


(0, [37, 40, 42])
(1, [44, 24, 51, 22, 17, 31, 3, 50, 16, 30, 46, 10, 11, 33, 38, 52, 0, 6, 57, 45, 28, 2, 8, 1, 54, 47, 27, 48, 20, 56, 5, 7, 25, 21, 13])
(2, [19, 9, 53, 23, 34, 14, 49, 4, 15])
(3, [39, 41, 55, 18, 26, 43])
(4, [35, 32, 12])
(5, [36])
(6, [29])

In [ ]:
from pysal.weights.Distance import Kernel
kernelW = Kernel(ssdo.xyCoords, fixed=True, k=4, function='GAUSSIAN')
autoTestResult = PYSAL_UTILS.autospace(df.iloc[:,0], df.iloc[:,1:].values, w, kernelW,
                                       opvalue = .1,
                                          name_y = fieldNames[0],
                                          name_x = fieldNames[1:],
                                          name_w = swmFile,
                                          name_gwk = self.gwkName,
                                          name_ds = self.ssdo.inputFC

In [13]:
ARCPY.env.overwriteOutput = True
outputFC = r'E:\Data\Conferences\esri_stat_summit_16\PYDemo\PYDemo.gdb\cluster_output'
outK = SSDO.CandidateField('KMEANS', 'LONG', groups + 1)
outMax = SSDO.CandidateField('MAXP', 'LONG', maxpGroups + 1)
outSKATER = SSDO.CandidateField('SKATER', 'LONG', skater.partitionOutput)
outFields = {'KMEANS': outK, 'MAXP': outMax, 'SKATER': outSKATER}
appendFields = fieldNames + ["NEW_NAME"]
ssdo.output2NewFC(outputFC, outFields, appendFields = appendFields)

In [ ]: