pysal / libpysal

Core components of Python Spatial Analysis Library
http://pysal.org/libpysal
Other
259 stars 78 forks source link

BUG: misaligned weights in the gabriel graph #709

Closed martinfleis closed 4 months ago

martinfleis commented 4 months ago

Found a bug in Gabriel graph. heads and tails come unsorted from filtering, resulting in misaligned weights. See repr:

import geopandas
from libpysal.graph import Graph
import momepy

blgs = geopandas.read_file(momepy.datasets.get_path('bubenec'), layer='buildings')

delaunay = Graph.build_triangulation(blgs.centroid, "delaunay", kernel="identity")
gabriel = Graph.build_triangulation(blgs.centroid, "gabriel", kernel="identity")
relative = Graph.build_triangulation(blgs.centroid, "relative_neighborhood", kernel="identity")

>>> delaunay[48]
neighbor
46      24.357863
47      32.418353
49      49.764015
74     155.698588
75      99.914953
141     93.302955
Name: weight, dtype: float64

>>> gabriel[48]
neighbor
46    128.634198
47     24.117386
Name: weight, dtype: float64

>>> relative[48]
neighbor
46    24.357863
47    32.418353
Name: weight, dtype: float64

It should be a subset of Delaunay, not alter the value.

ljwolf commented 4 months ago

This looks okay to me!

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 84.9%. Comparing base (bcabdbc) to head (de59f61). Report is 12 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pysal/libpysal/pull/709/graphs/tree.svg?width=650&height=150&src=pr&token=wgnkG5Rj0J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)](https://app.codecov.io/gh/pysal/libpysal/pull/709?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) ```diff @@ Coverage Diff @@ ## main #709 +/- ## ======================================= - Coverage 85.0% 84.9% -0.1% ======================================= Files 141 141 Lines 15203 15232 +29 ======================================= + Hits 12924 12926 +2 - Misses 2279 2306 +27 ``` | [Files](https://app.codecov.io/gh/pysal/libpysal/pull/709?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) | Coverage Δ | | |---|---|---| | [libpysal/graph/\_triangulation.py](https://app.codecov.io/gh/pysal/libpysal/pull/709?src=pr&el=tree&filepath=libpysal%2Fgraph%2F_triangulation.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bGlicHlzYWwvZ3JhcGgvX3RyaWFuZ3VsYXRpb24ucHk=) | `98.0% <100.0%> (+<0.1%)` | :arrow_up: | | [libpysal/graph/tests/test\_builders.py](https://app.codecov.io/gh/pysal/libpysal/pull/709?src=pr&el=tree&filepath=libpysal%2Fgraph%2Ftests%2Ftest_builders.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bGlicHlzYWwvZ3JhcGgvdGVzdHMvdGVzdF9idWlsZGVycy5weQ==) | `100.0% <100.0%> (ø)` | | ... and [3 files with indirect coverage changes](https://app.codecov.io/gh/pysal/libpysal/pull/709/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)