def calculate_weights(self, threshold=None, p=2, *args, **kwargs):
        """
        Parameters
        ----------
        threshold  : float
                     distance band
        p          : float
                     Minkowski p-norm distance metric parameter:
                     1<=p<=infinity
                     2: Euclidean distance
                     1: Manhattan distance
        """
        if threshold is None:
            if hasattr(self, 'threshold'):
                threshold = self.threshold
            else:
                raise ValueError("Must set threshold first")
        logging.warning('{}: Treshold = {}'.format(self.name, threshold))
        logging.info('{}: Starting weight calculation'.format(self.name))
        t = time.process_time()

        self.weights = pysal.DistanceBand(self.points_array,
                                          threshold=threshold,
                                          p=p,
                                          *args,
                                          **kwargs)

        logging.debug('{}: Weight calculation elapsed time {}'.format(
            self.name, str(timedelta(seconds=time.process_time() - t))))
        return self.weights
Ejemplo n.º 2
0
def gpd_distanceBandW(gpdf, threshold=11.2):
    """
    https://github.com/pysal/pysal/blob/master/pysal/weights/Distance.py
    """
    points = gpd_points(gpdf)
    w = pysal.DistanceBand(points, threshold)
    return w
Ejemplo n.º 3
0
 def test_DistanceBand_ints(self):
     """ see issue #126 """
     w = pysal.rook_from_shapefile(
         pysal.examples.get_path("lattice10x10.shp"))
     polygons = pysal.open(pysal.examples.get_path("lattice10x10.shp"),
                           "r").read()
     points2 = [tuple(map(int, poly.vertices[0])) for poly in polygons]
     w2 = pysal.DistanceBand(points2, 1)
     for k in range(w.n):
         self.assertEqual(w[k], w2[k])
Ejemplo n.º 4
0
 def test_DistanceBand(self):
     """ see issue #126 """
     w = pysal.rook_from_shapefile(
         pysal.examples.get_path("lattice10x10.shp"))
     polygons = pysal.open(pysal.examples.get_path("lattice10x10.shp"),
                           "r").read()
     points1 = [poly.centroid for poly in polygons]
     w1 = pysal.DistanceBand(points1, 1)
     for k in range(w.n):
         self.assertEqual(w[k], w1[k])
Ejemplo n.º 5
0
    def test_DistanceBand_arc(self):
        pts = [x.centroid for x in pysal.open(self.arcShp)]
        dist = pysal.cg.sphere.arcdist  # default radius is Earth KM
        full = np.matrix([[dist(pts[i], pts[j]) for j in xrange(
            len(pts))] for i in xrange(len(pts))])

        kd = pysal.cg.kdtree.KDTree(pts, distance_metric='Arc',
                                    radius=pysal.cg.sphere.RADIUS_EARTH_KM)
        w = pysal.DistanceBand(kd, full.max(), binary=False, alpha=1.0)
        self.assertTrue((w.sparse.todense() == full).all())