How to use the libpysal.weights.DistanceBand.from_dataframe function in libpysal

To help you get started, we’ve selected a few libpysal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martinfleis / momepy / tests / test_weights.py View on Github external
def test_DistanceBand(self):
        lp = libpysal.weights.DistanceBand.from_dataframe(self.df_buildings, 100)
        lp_ids = libpysal.weights.DistanceBand.from_dataframe(
            self.df_buildings, 100, ids="uID"
        )
        db = mm.DistanceBand(self.df_buildings, 100)
        db_ids = mm.DistanceBand(self.df_buildings, 100, ids="uID")

        for k in range(len(self.df_buildings)):
            assert k in db.neighbors.keys()
            assert sorted(lp.neighbors[k]) == sorted(db.neighbors[k])
        for k in self.df_buildings.uID:
            assert k in db_ids.neighbors.keys()
            assert sorted(lp_ids.neighbors[k]) == sorted(db_ids.neighbors[k])

        db_cent_false = mm.DistanceBand(self.df_buildings, 100, centroid=False)
        assert sorted(db_cent_false.neighbors[0]) == sorted(
            [125, 133, 114, 134, 113, 121]