squidpy
squidpy copied to clipboard
MVP for morpohology module
MRE:
import squidpy as sq
import spatialdata as sd
from spatialdata.datasets import raccoon
import spatialdata_plot
from scipy.stats import entropy
sdata = raccoon()
def my_func(regionmask, intensity_image):
masked_values = intensity_image[regionmask]
histogram, bin_edges = np.histogram(masked_values, bins=256, range=(0, 255))
probabilities = histogram / np.sum(histogram)
return entropy(probabilities, base=2)
sq.im.quantify_morphology(
sdata,
label="segmentation",
image="raccoon",
methods=["area", "perimeter", "circularity", "intensity_mean", my_func],
split_by_channels=True,
)
Notes
circularityis a non-skimage method but internal method (we need a library of those, can "steal" from CellProfiler + X)my_funcis an external method that gets fed toskimage.measure.regionprops. We need to provide doc on how to make such method. They take in a mask of the respective cell as well as a (potentially multi-channel) intensity image (bothnp.ndarrays).- add back to adata instead, align with rest of codebase
- now thing of how to integrate custom callables that are external to the codebase, f.e. huggingface models
- Needs to respect transformations & deal with different scales
- Needs notebook in
squidpy-notebooks
From discussion on 2024-08-13
- Workstreams
-
- "baseline" regionprops: what skimage has natively as functions, can query by string
-
- "non-baseline" regionprops: other metrics we can "steal" from CellProfiler etc and make available by string internally
- f.e. take math from https://github.com/CellProfiler/CellProfiler/blob/main/src/frontend/cellprofiler/modules/measuregranularity.py#L432
-
- feed in methods that take in mask / intensity image
-
- test performance of regionprops on actual data - does it work at scale at all?
- if not, can we hijack the method and parallelize across chunks (parallel io) and collect
- can we lazy-compute? dask?
-
- respect transformations and datatree "zoom" - which matches, what does the user want?
-
my_funcwrapper for model inference, f.e. from some HF-model?
- download model etc?
- they might require specific resolution, might have to scale all cells because area contains info
-
Codecov Report
Attention: Patch coverage is 20.33898% with 47 lines in your changes missing coverage. Please review.
Project coverage is 69.52%. Comparing base (
4a632d6) to head (bbecec3). Report is 5 commits behind head on main.
| Files | Patch % | Lines |
|---|---|---|
| src/squidpy/im/_feature.py | 20.33% | 47 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #866 +/- ##
==========================================
- Coverage 69.99% 69.52% -0.47%
==========================================
Files 39 39
Lines 5532 5667 +135
Branches 1037 1063 +26
==========================================
+ Hits 3872 3940 +68
- Misses 1367 1429 +62
- Partials 293 298 +5
| Files | Coverage Δ | |
|---|---|---|
| src/squidpy/im/_feature.py | 51.81% <20.33%> (-37.08%) |
:arrow_down: |
I had to remove the code that called the label function from skimage as it was creating additional labels that we cannot trace back to the original labels.
Superseded by https://github.com/scverse/squidpy/pull/982