pysal / momepy

Urban Morphology Measuring Toolkit
https://docs.momepy.org
BSD 3-Clause "New" or "Revised" License
496 stars 59 forks source link

functional node_density implementation #576

Closed u3ks closed 6 months ago

u3ks commented 7 months ago

functional implementation of nodedensity. I kept the function logic pretty much the same, just used the new graph api and np.in1d, instead of np.isin.

Timings: old: CPU times: user 14.9 s, sys: 69.3 ms, total: 15 s Wall time: 14.9 s

new: CPU times: user 6.19 s, sys: 0 ns, total: 6.19 s Wall time: 6.19 s

Potentially, the function can be sped up further if we change the function API and pass the networkx.MultiGraph object. Then, we can do:

sum(l for (,,l) in nx.subgraph(neighbours).edges.data('mm_len'))

where neighbours comes from the new libpysal.Graph.

codecov[bot] commented 7 months ago

Codecov Report

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

Project coverage is 97.8%. Comparing base (4037c70) to head (b127e27). Report is 21 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pysal/momepy/pull/576/graphs/tree.svg?width=650&height=150&src=pr&token=VNn0WR5JWT&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)](https://app.codecov.io/gh/pysal/momepy/pull/576?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) ```diff @@ Coverage Diff @@ ## main #576 +/- ## ======================================= + Coverage 97.4% 97.8% +0.5% ======================================= Files 26 37 +11 Lines 4328 5353 +1025 ======================================= + Hits 4214 5237 +1023 - Misses 114 116 +2 ``` | [Files](https://app.codecov.io/gh/pysal/momepy/pull/576?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) | Coverage Δ | | |---|---|---| | [momepy/functional/\_intensity.py](https://app.codecov.io/gh/pysal/momepy/pull/576?src=pr&el=tree&filepath=momepy%2Ffunctional%2F_intensity.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvX2ludGVuc2l0eS5weQ==) | `100.0% <100.0%> (ø)` | | | [momepy/functional/tests/test\_intensity.py](https://app.codecov.io/gh/pysal/momepy/pull/576?src=pr&el=tree&filepath=momepy%2Ffunctional%2Ftests%2Ftest_intensity.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvdGVzdHMvdGVzdF9pbnRlbnNpdHkucHk=) | `100.0% <100.0%> (ø)` | |
jGaboardi commented 6 months ago

Potentially, the function can be sped up further if we change the function API and pass the networkx.MultiGraph object. Then, we can do:

sum(l for (,,l) in nx.subgraph(neighbours).edges.data('mm_len'))

where neighbours comes from the new libpysal.Graph.

Was there any more thought to this?

martinfleis commented 6 months ago

Was there any more thought to this?

Yes. It was faster but the API got super weird so we scraped it.