How to use the momepy.sw_high function in momepy

To help you get started, we’ve selected a few momepy 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_sw_high(self):
        first_order = libpysal.weights.Queen.from_dataframe(self.df_tessellation)
        from_sw = mm.sw_high(2, gdf=None, weights=first_order)
        from_df = mm.sw_high(2, gdf=self.df_tessellation)
        rook = mm.sw_high(2, gdf=self.df_tessellation, contiguity="rook")
        check = [133, 134, 111, 112, 113, 114, 115, 121, 125]
        assert from_sw.neighbors[0] == check
        assert from_df.neighbors[0] == check
        assert rook.neighbors[0] == check

        with pytest.raises(AttributeError):
            mm.sw_high(2, gdf=None, weights=None)

        with pytest.raises(ValueError):
            mm.sw_high(2, gdf=self.df_tessellation, contiguity="nonexistent")
github martinfleis / momepy / tests / test_intensity.py View on Github external
def test_Density(self):
        sw = mm.sw_high(k=3, gdf=self.df_tessellation, ids="uID")
        dens = mm.Density(
            self.df_tessellation,
            self.df_buildings["fl_area"],
            sw,
            "uID",
            self.df_tessellation.area,
        ).series
        dens2 = mm.Density(
            self.df_tessellation, self.df_buildings["fl_area"], sw, "uID"
        ).series
        check = 1.661587
        assert dens.mean() == approx(check)
        assert dens2.mean() == approx(check)
        sw_drop = mm.sw_high(k=3, gdf=self.df_tessellation[2:], ids="uID")
        assert (
            mm.Density(
                self.df_tessellation, self.df_buildings["fl_area"], sw_drop, "uID"
            )
            .series.isna()
            .any()
        )

        # island
        sw.neighbors[1] = []
        dens3 = mm.Density(
            self.df_tessellation,
            self.df_buildings["fl_area"],
            sw,
            "uID",
            self.df_tessellation.area,
github martinfleis / momepy / tests / test_dimension.py View on Github external
self.df_buildings["area"] = self.df_buildings.geometry.area
        sw = sw_high(k=3, gdf=self.df_tessellation, ids="uID")
        weighted = mm.WeightedCharacter(
            self.df_buildings, "height", sw, "uID", "area"
        ).series
        assert weighted[38] == approx(18.301, rel=1e-3)

        area = self.df_buildings.geometry.area
        sw = sw_high(k=3, gdf=self.df_tessellation, ids="uID")
        weighted = mm.WeightedCharacter(
            self.df_buildings, self.df_buildings.height, sw, "uID", area
        ).series
        assert weighted[38] == approx(18.301, rel=1e-3)

        sw_drop = sw_high(k=3, gdf=self.df_tessellation[2:], ids="uID")
        assert (
            mm.WeightedCharacter(self.df_buildings, "height", sw_drop, "uID")
            .series.isna()
github martinfleis / momepy / tests / test_intensity.py View on Github external
def test_Density(self):
        sw = mm.sw_high(k=3, gdf=self.df_tessellation, ids="uID")
        dens = mm.Density(
            self.df_tessellation,
            self.df_buildings["fl_area"],
            sw,
            "uID",
            self.df_tessellation.area,
        ).series
        dens2 = mm.Density(
            self.df_tessellation, self.df_buildings["fl_area"], sw, "uID"
        ).series
        check = 1.661587
        assert dens.mean() == approx(check)
        assert dens2.mean() == approx(check)
        sw_drop = mm.sw_high(k=3, gdf=self.df_tessellation[2:], ids="uID")
        assert (
            mm.Density(
github martinfleis / momepy / tests / test_weights.py View on Github external
def test_sw_high(self):
        first_order = libpysal.weights.Queen.from_dataframe(self.df_tessellation)
        from_sw = mm.sw_high(2, gdf=None, weights=first_order)
        from_df = mm.sw_high(2, gdf=self.df_tessellation)
        rook = mm.sw_high(2, gdf=self.df_tessellation, contiguity="rook")
        check = [133, 134, 111, 112, 113, 114, 115, 121, 125]
        assert from_sw.neighbors[0] == check
        assert from_df.neighbors[0] == check
        assert rook.neighbors[0] == check

        with pytest.raises(AttributeError):
            mm.sw_high(2, gdf=None, weights=None)

        with pytest.raises(ValueError):
            mm.sw_high(2, gdf=self.df_tessellation, contiguity="nonexistent")
github martinfleis / momepy / tests / test_distribution.py View on Github external
def test_BuildingAdjacency(self):
        sw = Queen.from_dataframe(self.df_buildings, ids="uID")
        swh = mm.sw_high(k=3, gdf=self.df_tessellation, ids="uID")
        self.df_buildings["adj_sw"] = mm.BuildingAdjacency(
            self.df_buildings,
            spatial_weights=sw,
            unique_id="uID",
            spatial_weights_higher=swh,
        ).series
        self.df_buildings["adj_sw_none"] = mm.BuildingAdjacency(
            self.df_buildings, unique_id="uID", spatial_weights_higher=swh
        ).series
        check = 0.2613824113909074
        assert self.df_buildings["adj_sw"].mean() == check
        assert self.df_buildings["adj_sw_none"].mean() == check
        swh_drop = mm.sw_high(k=3, gdf=self.df_tessellation[2:], ids="uID")
        assert (
            mm.BuildingAdjacency(
                self.df_buildings, unique_id="uID", spatial_weights_higher=swh_drop
github martinfleis / momepy / tests / test_distribution.py View on Github external
def test_BuildingAdjacency(self):
        sw = Queen.from_dataframe(self.df_buildings, ids="uID")
        swh = mm.sw_high(k=3, gdf=self.df_tessellation, ids="uID")
        self.df_buildings["adj_sw"] = mm.BuildingAdjacency(
            self.df_buildings,
            spatial_weights=sw,
            unique_id="uID",
            spatial_weights_higher=swh,
        ).series
        self.df_buildings["adj_sw_none"] = mm.BuildingAdjacency(
            self.df_buildings, unique_id="uID", spatial_weights_higher=swh
        ).series
        check = 0.2613824113909074
        assert self.df_buildings["adj_sw"].mean() == check
        assert self.df_buildings["adj_sw_none"].mean() == check
        swh_drop = mm.sw_high(k=3, gdf=self.df_tessellation[2:], ids="uID")
        assert (
            mm.BuildingAdjacency(
                self.df_buildings, unique_id="uID", spatial_weights_higher=swh_drop
            )
github martinfleis / momepy / tests / test_diversity.py View on Github external
def setup_method(self):

        test_file_path = mm.datasets.get_path("bubenec")
        self.df_buildings = gpd.read_file(test_file_path, layer="buildings")
        self.df_streets = gpd.read_file(test_file_path, layer="streets")
        self.df_tessellation = gpd.read_file(test_file_path, layer="tessellation")
        self.df_buildings["height"] = np.linspace(10.0, 30.0, 144)
        self.df_tessellation["area"] = mm.Area(self.df_tessellation).series
        self.sw = sw_high(k=3, gdf=self.df_tessellation, ids="uID")
        self.sw.neighbors[100] = []
        self.sw_drop = sw_high(k=3, gdf=self.df_tessellation[2:], ids="uID")
github martinfleis / momepy / tests / test_dimension.py View on Github external
def test_CoveredArea(self):
        sw = sw_high(gdf=self.df_tessellation, k=1, ids="uID")
        covered_sw = mm.CoveredArea(self.df_tessellation, sw, "uID").series
        assert covered_sw[0] == approx(24115.667, rel=1e-3)
        sw_drop = sw_high(k=3, gdf=self.df_tessellation[2:], ids="uID")
        assert mm.CoveredArea(self.df_tessellation, sw_drop, "uID").series.isna().any()
github martinfleis / momepy / tests / test_weights.py View on Github external
def test_sw_high(self):
        first_order = libpysal.weights.Queen.from_dataframe(self.df_tessellation)
        from_sw = mm.sw_high(2, gdf=None, weights=first_order)
        from_df = mm.sw_high(2, gdf=self.df_tessellation)
        rook = mm.sw_high(2, gdf=self.df_tessellation, contiguity="rook")
        check = [133, 134, 111, 112, 113, 114, 115, 121, 125]
        assert from_sw.neighbors[0] == check
        assert from_df.neighbors[0] == check
        assert rook.neighbors[0] == check

        with pytest.raises(AttributeError):
            mm.sw_high(2, gdf=None, weights=None)

        with pytest.raises(ValueError):
            mm.sw_high(2, gdf=self.df_tessellation, contiguity="nonexistent")