Skip to content

Commit

Permalink
fix baysor tight layout #23
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinblampey committed Feb 12, 2024
1 parent 532c315 commit 02268fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- The `uniform` toy dataset now has two coordinate systems (better test case)
- Faster table conversion to the Xenium Explorer

### Fixed
- Tight patching more stable with epsilon constant

## [1.0.2] - 2024-01-15

### Fix
Expand Down
1 change: 1 addition & 0 deletions sopa/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SopaKeys:

VALID_DIMENSIONS = ("c", "y", "x")
LOW_AVERAGE_COUNT = 0.01
EPS = 1e-5


class ROI:
Expand Down
8 changes: 5 additions & 3 deletions sopa/segmentation/patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from spatialdata.models import ShapesModel
from spatialdata.transformations import get_transformation

from .._constants import ROI, SopaFiles, SopaKeys
from .._constants import EPS, ROI, SopaFiles, SopaKeys
from .._sdata import get_boundaries, get_item, get_spatial_image, to_intrinsic

log = logging.getLogger(__name__)
Expand All @@ -32,7 +32,9 @@ def __init__(self, xmin, xmax, patch_width, patch_overlap, tight, int_coords):
self._count = self.count()
if tight:
self.patch_width = self.tight_width()
assert self._count == self.count()
assert (
self._count == self.count()
), f"Invalid patching with {self.delta=}, {self.patch_width=} and {self.patch_overlap=}"

def count(self):
if self.patch_width >= self.delta:
Expand All @@ -45,7 +47,7 @@ def update(self, patch_width):

def tight_width(self):
width = (self.delta + (self._count - 1) * self.patch_overlap) / self._count
return ceil(width) if self.int_coords else width
return ceil(width) if self.int_coords else width + EPS

def __getitem__(self, i):
start_delta = i * (self.patch_width - self.patch_overlap)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def _patchify_transcripts(sdata: SpatialData, width: int, overlap: int) -> list[


def test_patchify_baysor(sdata: SpatialData):
valid_indices = _patchify_transcripts(sdata, 300, 100)
valid_indices = _patchify_transcripts(sdata, 30, 10)
assert len(valid_indices) == 9

valid_indices = _patchify_transcripts(sdata, 512, 0)
valid_indices = _patchify_transcripts(sdata, 52, 0)
assert len(valid_indices) == 1


Expand Down

0 comments on commit 02268fc

Please sign in to comment.