How to use the momepy.Simpson 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_diversity.py View on Github external
self.df_tessellation, "area", self.sw, "uID", gini_simpson=True
        ).series
        assert gs[0] == 1 - 0.385

        inv = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", inverse=True
        ).series
        assert inv[0] == 1 / 0.385

        self.df_tessellation["cat"] = list(range(8)) * 18
        cat = mm.Simpson(
            self.df_tessellation, "cat", self.sw, "uID", categorical=True
        ).series
        assert cat[0] == pytest.approx(0.15)

        cat2 = mm.Simpson(
            self.df_tessellation,
            "cat",
            self.sw,
            "uID",
            categorical=True,
            categories=range(15),
        ).series
        assert cat2[0] == pytest.approx(0.15)
github martinfleis / momepy / tests / test_diversity.py View on Github external
self.sw,
            "uID",
            binning="quantiles",
            k=3,
        ).series
        assert quan_sw[0] == 0.395
        with pytest.raises(ValueError):
            ht_sw = mm.Simpson(
                self.df_tessellation, "area", self.sw, "uID", binning="nonexistent"
            )
        assert (
            mm.Simpson(self.df_tessellation, "area", self.sw_drop, "uID")
            .series.isna()
            .any()
        )
        gs = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", gini_simpson=True
        ).series
        assert gs[0] == 1 - 0.385

        inv = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", inverse=True
        ).series
        assert inv[0] == 1 / 0.385

        self.df_tessellation["cat"] = list(range(8)) * 18
        cat = mm.Simpson(
            self.df_tessellation, "cat", self.sw, "uID", categorical=True
        ).series
        assert cat[0] == pytest.approx(0.15)

        cat2 = mm.Simpson(
github martinfleis / momepy / tests / test_diversity.py View on Github external
def test_Simpson(self):
        ht_sw = mm.Simpson(self.df_tessellation, "area", self.sw, "uID").series
        assert ht_sw[0] == 0.385
        quan_sw = mm.Simpson(
            self.df_tessellation,
            self.df_tessellation.area,
            self.sw,
            "uID",
            binning="quantiles",
            k=3,
        ).series
        assert quan_sw[0] == 0.395
        with pytest.raises(ValueError):
            ht_sw = mm.Simpson(
                self.df_tessellation, "area", self.sw, "uID", binning="nonexistent"
            )
        assert (
            mm.Simpson(self.df_tessellation, "area", self.sw_drop, "uID")
github martinfleis / momepy / tests / test_diversity.py View on Github external
mm.Simpson(self.df_tessellation, "area", self.sw_drop, "uID")
            .series.isna()
            .any()
        )
        gs = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", gini_simpson=True
        ).series
        assert gs[0] == 1 - 0.385

        inv = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", inverse=True
        ).series
        assert inv[0] == 1 / 0.385

        self.df_tessellation["cat"] = list(range(8)) * 18
        cat = mm.Simpson(
            self.df_tessellation, "cat", self.sw, "uID", categorical=True
        ).series
        assert cat[0] == pytest.approx(0.15)

        cat2 = mm.Simpson(
            self.df_tessellation,
            "cat",
            self.sw,
            "uID",
            categorical=True,
            categories=range(15),
        ).series
        assert cat2[0] == pytest.approx(0.15)
github martinfleis / momepy / tests / test_diversity.py View on Github external
def test_Simpson(self):
        ht_sw = mm.Simpson(self.df_tessellation, "area", self.sw, "uID").series
        assert ht_sw[0] == 0.385
        quan_sw = mm.Simpson(
            self.df_tessellation,
            self.df_tessellation.area,
            self.sw,
            "uID",
            binning="quantiles",
            k=3,
        ).series
        assert quan_sw[0] == 0.395
        with pytest.raises(ValueError):
            ht_sw = mm.Simpson(
                self.df_tessellation, "area", self.sw, "uID", binning="nonexistent"
            )
        assert (
            mm.Simpson(self.df_tessellation, "area", self.sw_drop, "uID")
            .series.isna()
            .any()
github martinfleis / momepy / tests / test_diversity.py View on Github external
assert quan_sw[0] == 0.395
        with pytest.raises(ValueError):
            ht_sw = mm.Simpson(
                self.df_tessellation, "area", self.sw, "uID", binning="nonexistent"
            )
        assert (
            mm.Simpson(self.df_tessellation, "area", self.sw_drop, "uID")
            .series.isna()
            .any()
        )
        gs = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", gini_simpson=True
        ).series
        assert gs[0] == 1 - 0.385

        inv = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", inverse=True
        ).series
        assert inv[0] == 1 / 0.385

        self.df_tessellation["cat"] = list(range(8)) * 18
        cat = mm.Simpson(
            self.df_tessellation, "cat", self.sw, "uID", categorical=True
        ).series
        assert cat[0] == pytest.approx(0.15)

        cat2 = mm.Simpson(
            self.df_tessellation,
            "cat",
            self.sw,
            "uID",
            categorical=True,
github martinfleis / momepy / tests / test_diversity.py View on Github external
def test_Simpson(self):
        ht_sw = mm.Simpson(self.df_tessellation, "area", self.sw, "uID").series
        assert ht_sw[0] == 0.385
        quan_sw = mm.Simpson(
            self.df_tessellation,
            self.df_tessellation.area,
            self.sw,
            "uID",
            binning="quantiles",
            k=3,
        ).series
        assert quan_sw[0] == 0.395
        with pytest.raises(ValueError):
            ht_sw = mm.Simpson(
                self.df_tessellation, "area", self.sw, "uID", binning="nonexistent"
            )
        assert (
            mm.Simpson(self.df_tessellation, "area", self.sw_drop, "uID")
            .series.isna()
            .any()
        )
        gs = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", gini_simpson=True
        ).series
        assert gs[0] == 1 - 0.385

        inv = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", inverse=True
        ).series
        assert inv[0] == 1 / 0.385
github martinfleis / momepy / tests / test_diversity.py View on Github external
assert ht_sw[0] == 0.385
        quan_sw = mm.Simpson(
            self.df_tessellation,
            self.df_tessellation.area,
            self.sw,
            "uID",
            binning="quantiles",
            k=3,
        ).series
        assert quan_sw[0] == 0.395
        with pytest.raises(ValueError):
            ht_sw = mm.Simpson(
                self.df_tessellation, "area", self.sw, "uID", binning="nonexistent"
            )
        assert (
            mm.Simpson(self.df_tessellation, "area", self.sw_drop, "uID")
            .series.isna()
            .any()
        )
        gs = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", gini_simpson=True
        ).series
        assert gs[0] == 1 - 0.385

        inv = mm.Simpson(
            self.df_tessellation, "area", self.sw, "uID", inverse=True
        ).series
        assert inv[0] == 1 / 0.385

        self.df_tessellation["cat"] = list(range(8)) * 18
        cat = mm.Simpson(
            self.df_tessellation, "cat", self.sw, "uID", categorical=True