pysal / momepy

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

REF: functional implementation of shape module #550

Closed martinfleis closed 9 months ago

martinfleis commented 9 months ago

Completely refactored shape.py. This was probably the easiest of them all.

Performance comparison on data covering whole Prague:

old (s) new (s) comparison
form_factor 0.0177744 0.0144857 0.814978
fractal_dimension 0.011218 0.00919267 0.81946
facade_ratio 0.010366 0.00798157 0.769973
circular_compactness 3.75679 1.46005 0.388644
square_compactness 0.0107254 0.0082286 0.767205
convexity 0.491798 0.496109 1.00876
courtyard_index 0.141855 0.141236 0.99564
rectangularity 0.73733 0.738049 1.00097
shape_index 1.51152 1.50104 0.993067
corners 13.3684 4.04417 0.302518
squareness 13.595 5.92453 0.435787
equivalent_rectangular_index 0.872975 0.751531 0.860885
elongation 0.867414 0.735372 0.847775
centroid_corner_distance 31.7199 21.2256 0.669158
linearity 0.356025 0.0215537 0.0605398
compactness_weighted_axis 4.12308 1.68417 0.408473

Total speedup, to run all on a single city is 0.54, so we are now nearly twice as fast to compute the same.

@jGaboardi I am aware it is a loooong PR so can split it if you prefer that, but there's a ton of repetition in docstrings and tests so it is not that much.

I am also quite happy how the code looks compared to the original shape.py.

codecov[bot] commented 9 months ago

Codecov Report

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

Comparison is base (4037c70) 97.4% compared to head (176b4b2) 97.5%. Report is 1 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pysal/momepy/pull/550/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/550?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) ```diff @@ Coverage Diff @@ ## main #550 +/- ## ======================================= + Coverage 97.4% 97.5% +0.2% ======================================= Files 26 28 +2 Lines 4328 4633 +305 ======================================= + Hits 4214 4519 +305 Misses 114 114 ``` | [Files](https://app.codecov.io/gh/pysal/momepy/pull/550?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) | Coverage Δ | | |---|---|---| | [momepy/\_\_init\_\_.py](https://app.codecov.io/gh/pysal/momepy/pull/550?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L19faW5pdF9fLnB5) | `100.0% <100.0%> (ø)` | | | [momepy/functional/\_dimension.py](https://app.codecov.io/gh/pysal/momepy/pull/550?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvX2RpbWVuc2lvbi5weQ==) | `100.0% <100.0%> (ø)` | | | [momepy/functional/\_shape.py](https://app.codecov.io/gh/pysal/momepy/pull/550?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvX3NoYXBlLnB5) | `100.0% <100.0%> (ø)` | | | [momepy/functional/tests/test\_shape.py](https://app.codecov.io/gh/pysal/momepy/pull/550?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvdGVzdHMvdGVzdF9zaGFwZS5weQ==) | `100.0% <100.0%> (ø)` | |
jGaboardi commented 9 months ago

Total speedup, to run all on a single city is 0.54, so we are now nearly twice as fast to compute the same.

Amazing. Very cool work.

@jGaboardi I am aware it is a loooong PR so can split it if you prefer that, but there's a ton of repetition in docstrings and tests so it is not that much.

No need to split. I will hunker down and get it down.