fix the bug of relative coordinates
Description
I have changed the relative coordinate to exact coordinate in the feature_segmentation function.
There are two reasons:
- because of the normalization of "np.max(y) - np.min(y)" in denominator, current relative coordinate will return nan if there is only one cell in spot.
- exact coordinate looks more reasonable than the relative coordinate when visualizing the segmentation result with spatial image as background.
How has this been tested?
I have tested the revised code in two Visium data, it works very well.
Codecov Report
Merging #572 (06964fc) into main (2cf664f) will decrease coverage by
0.01%. The diff coverage is100.00%.
@@ Coverage Diff @@
## main #572 +/- ##
==========================================
- Coverage 72.33% 72.32% -0.02%
==========================================
Files 37 37
Lines 5177 5175 -2
Branches 982 982
==========================================
- Hits 3745 3743 -2
Misses 1181 1181
Partials 251 251
| Impacted Files | Coverage Δ | |
|---|---|---|
| squidpy/im/_feature_mixin.py | 87.17% <100.00%> (-0.17%) |
:arrow_down: |
hi @JiaShun-Xiao thanks for the cotnribution, can you elaborate a bit more and provide code snippets about this PR? I don't think I fully understand teh settigns in which this fails. Also, can you check out the contributing guide for pre-commit checks (currently failing).
Thank you!
hi @JiaShun-Xiao ,
could you please elaborate on the purpose of this PR and provide a minimal reproducible example?
Thank you! GIovanni
Hi, @giovp
Thanks for your patience! Current relative coordinates are fine in most cases. However, I think it could be improved by using exact coordinates as I mentioned in the first comment. The nuclei segmentation example (https://squidpy.readthedocs.io/en/latest/external_tutorials/tutorial_tangram.html) provided in squidpy document can demonstrate this.
Thank you! Jiashun
interesting ok, the tests seem to pass, could you add a small test with this specific edge case? Otherwise a minimal reproducible example here and I'd be happy to add it myself, thank you!
Sorry I am not familiar with tests in programming, I need some time to learn how to add tests for edge cases
hi @JiaShun-Xiao , no problem. Could you please then post here few lines of code that explain what is the problem you are trying to solve? ideally something that can be run directly, with minimal dependency (e.g. squidpy, numpy etc)
Sure, the problem I am trying to solve is retriving exact cell coordinates/locations after nuclei segmentation with spatial histological images. To demonstrate this, I add an example in the following Jupiter notebook to illustrate why we need exact nuclei coordinates instead of relative coordinates.