Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/magnify/stitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ def __init__(self, overlap: int = 102):
self.overlap = overlap

def __call__(self, assay: xr.Dataset) -> xr.Dataset:
tiles = assay.tile[
...,
: assay.tile.shape[-2] - self.overlap,
: assay.tile.shape[-1] - self.overlap,
]
# Only clip if overlap is non-zero
if self.overlap > 0:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than checking for this condition could you do the same thing I did in the previous version of the code which is to just have:

tiles = assay.tile[
    ...,
    clip : assay.tile.shape[-2] - clip + remainder,
    clip : assay.tile.shape[-1] - clip + remainder,
]

That way you're minimizing how much branching happens in the code which makes it easier to reason about. If you're concerned about a bug being introduced later on when the code gets changed because of the tricky indexing you can leave a comment explaining that we're intentionally not using the negative endpoint indexing here because of when self. overlap is 0.

clip = self.overlap//2
# Account for odd overlaps
remainder = self.overlap%2

# Adjust tiles
tiles = assay.tile[
...,
clip:-clip+remainder,
clip:-clip+remainder,
]
else:
tiles = assay.tile

# Move the time and channel axes last so we can focus on joining images.
tiles = tiles.transpose("tile_row", "tile_col", "tile_y", "tile_x", "channel", "time")
Expand Down
Loading