Exemple #1
0
 def test_threshold_continuousW_from_array(self):
     points = [(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)]
     wid = pysal.threshold_continuousW_from_array(points, 11.2)
     self.assertEquals(wid.weights[0], [0.10000000000000001,
                                        0.089442719099991588])
     wid2 = pysal.threshold_continuousW_from_array(points, 11.2, alpha=-2.0)
     self.assertEquals(wid2.weights[0], [0.01, 0.0079999999999999984])
Exemple #2
0
 def test_threshold_continuousW_from_array(self):
     points = [(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)]
     wid = pysal.threshold_continuousW_from_array(points, 11.2)
     wds = {wid.neighbors[0][i]: v for i, v in enumerate(wid.weights[0])}
     self.assertEqual(wds, {1: 0.10000000000000001,
                            3: 0.089442719099991588})
     wid2 = pysal.threshold_continuousW_from_array(points, 11.2, alpha=-2.0)
     wds = {wid2.neighbors[0][i]: v for i, v in enumerate(wid2.weights[0])}
     self.assertEquals(wid2.weights[0], [0.01, 0.0079999999999999984])
Exemple #3
0
 def test_threshold_continuousW_from_array(self):
     points = [(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)]
     wid = pysal.threshold_continuousW_from_array(points, 11.2)
     wds = {wid.neighbors[0][i]: v for i, v in enumerate(wid.weights[0])}
     self.assertEqual(wds, {
         1: 0.10000000000000001,
         3: 0.089442719099991588
     })
     wid2 = pysal.threshold_continuousW_from_array(points, 11.2, alpha=-2.0)
     wds = {wid2.neighbors[0][i]: v for i, v in enumerate(wid2.weights[0])}
     self.assertEquals(wid2.weights[0], [0.01, 0.0079999999999999984])
Exemple #4
0
 def test_threshold(self):
     md = pysal.min_threshold_dist_from_shapefile(self.polyShp)
     self.assertEqual(md, 0.61886415807685413)
     wid = pysal.threshold_continuousW_from_array(self.points, 11.2)
     self.assertEqual(wid.weights[0], [0.10000000000000001,
                                       0.089442719099991588])
     wid2 = pysal.threshold_continuousW_from_array(
         self.points, 11.2, alpha=-2.0)
     self.assertEqual(wid2.weights[0], [0.01, 0.0079999999999999984])
     w = pysal.threshold_continuousW_from_shapefile(
         self.polyShp, 0.62, idVariable="POLYID")
     self.assertEqual(w.weights[1], [1.6702346893743334,
                                     1.7250729841938093])
Exemple #5
0
 def test_threshold(self):
     md = pysal.min_threshold_dist_from_shapefile(self.polyShp)
     self.assertEqual(md, 0.61886415807685413)
     wid = pysal.threshold_continuousW_from_array(self.points, 11.2)
     self.assertEqual(wid.weights[0], [0.10000000000000001,
                                       0.089442719099991588])
     wid2 = pysal.threshold_continuousW_from_array(
         self.points, 11.2, alpha=-2.0)
     self.assertEqual(wid2.weights[0], [0.01, 0.0079999999999999984])
     w = pysal.threshold_continuousW_from_shapefile(
         self.polyShp, 0.62, idVariable="POLYID")
     self.assertEqual(w.weights[1], [1.6702346893743334,
                                     1.7250729841938093])
 def buildWeights(self):
     """Performs Distance-based Weights Creation"""
     ARCPY.SetProgressor("default", "Constructing spatial weights object...")
     
     #### Shorthand Attributes ####
     distanceType = self.distanceType
     threshold = self.threshold
     knnNum = self.knnNum
     idField = self.idField
     outputExt = self.outputExt
     ssdo = self.ssdo
     
     #### Create Distance-based WeightObj (0-based IDs) ####
     dataArray = ssdo.xyCoords
     if distanceType.upper() == DISTTYPE[0]:
         weightObj = PYSAL.threshold_binaryW_from_array(dataArray, threshold)
     elif distanceType.upper() == DISTTYPE[1]:
         weightObj = PYSAL.knnW_from_array(dataArray, knnNum)
     elif distanceType.upper() == DISTTYPE[2]:
         alpha = -1 * self.inverseDist
         weightObj = PYSAL.threshold_continuousW_from_array(\
             dataArray, threshold, alpha=alpha)
       
     #### Re-Create WeightObj for NOT 0-based idField #### 
     if idField:
         if ssdo.master2Order.keys() != ssdo.master2Order.values(): 
             o2M = ssdo.order2Master
             neighborDict = {o2M[oid] : [o2M[nid] for nid in nbrs] \
                             for oid,nbrs in weightObj.neighbors.items()}
             weightDict = {o2M[oid] : weights \
                           for oid, weights in weightObj.weights.items()}
             weightObj = W(neighborDict, weightDict)
         
     #### Save weightObj Class Object for Writing Result #### 
     self.weightObj = weightObj
Exemple #7
0
 def test_threshold(self):
     md = pysal.min_threshold_dist_from_shapefile(self.polyShp)
     self.assertEqual(md, 0.61886415807685413)
     wid = pysal.threshold_continuousW_from_array(self.points, 11.2)
     wds = {wid.neighbors[0][i]: v for i, v in enumerate(wid.weights[0])}
     self.assertEqual(wds, {1: 0.10000000000000001,
                            3: 0.089442719099991588})
     wid2 = pysal.threshold_continuousW_from_array(
         self.points, 11.2, alpha=-2.0)
     wds = {wid2.neighbors[0][i]: v for i, v in enumerate(wid2.weights[0])}
     self.assertEqual(wds, {1: 0.01, 3: 0.0079999999999999984})
     w = pysal.threshold_continuousW_from_shapefile(
         self.polyShp, 0.62, idVariable="POLYID")
     wds = {w.neighbors[1][i]: v for i, v in enumerate(w.weights[1])}
     self.assertEqual(wds, {2: 1.6702346893743334,
                            3: 1.7250729841938093})
Exemple #8
0
 def test_threshold(self):
     md = pysal.min_threshold_dist_from_shapefile(self.polyShp)
     self.assertEqual(md, 0.61886415807685413)
     wid = pysal.threshold_continuousW_from_array(self.points, 11.2)
     wds = {wid.neighbors[0][i]: v for i, v in enumerate(wid.weights[0])}
     self.assertEqual(wds, {
         1: 0.10000000000000001,
         3: 0.089442719099991588
     })
     wid2 = pysal.threshold_continuousW_from_array(self.points,
                                                   11.2,
                                                   alpha=-2.0)
     wds = {wid2.neighbors[0][i]: v for i, v in enumerate(wid2.weights[0])}
     self.assertEqual(wds, {1: 0.01, 3: 0.0079999999999999984})
     w = pysal.threshold_continuousW_from_shapefile(self.polyShp,
                                                    0.62,
                                                    idVariable="POLYID")
     wds = {w.neighbors[1][i]: v for i, v in enumerate(w.weights[1])}
     self.assertEqual(wds, {2: 1.6702346893743334, 3: 1.7250729841938093})
Exemple #9
0
    def buildWeights(self):
        """Performs Distance-based Weights Creation"""
        ARCPY.SetProgressor("default",
                            "Constructing spatial weights object...")

        #### Shorthand Attributes ####
        distanceType = self.distanceType
        threshold = self.threshold
        knnNum = self.knnNum
        idField = self.idField
        outputExt = self.outputExt
        ssdo = self.ssdo

        #### Create Distance-based WeightObj (0-based IDs) ####
        dataArray = ssdo.xyCoords
        if distanceType.upper() == DISTTYPE[0]:
            weightObj = PYSAL.threshold_binaryW_from_array(
                dataArray, threshold)
        elif distanceType.upper() == DISTTYPE[1]:
            weightObj = PYSAL.knnW_from_array(dataArray, knnNum)
        elif distanceType.upper() == DISTTYPE[2]:
            alpha = -1 * self.inverseDist
            weightObj = PYSAL.threshold_continuousW_from_array(\
                dataArray, threshold, alpha=alpha)

        #### Re-Create WeightObj for NOT 0-based idField ####
        if idField:
            if ssdo.master2Order.keys() != ssdo.master2Order.values():
                o2M = ssdo.order2Master
                neighborDict = {o2M[oid] : [o2M[nid] for nid in nbrs] \
                                for oid,nbrs in weightObj.neighbors.items()}
                weightDict = {o2M[oid] : weights \
                              for oid, weights in weightObj.weights.items()}
                weightObj = W(neighborDict, weightDict)

        #### Save weightObj Class Object for Writing Result ####
        self.weightObj = weightObj