Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion suite2p/registration/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ def registration_wrapper(f_reg, f_raw=None, f_reg_chan2=None, f_raw_chan2=None,
if nchannels > 1:
mean_img_alt = shift_frames_and_write(f_alt_in, f_alt_out, settings["batch_size"], yoff, xoff, yoff1,
xoff1, blocks=blocks, bidiphase=bidiphase,
tif_root=tif_root_align, device=device)
tif_root=tif_root_alt, device=device)
else:
mean_img_alt = None

Expand Down
33 changes: 33 additions & 0 deletions tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ def test_negative_bidiphase_shift_shifts_every_other_line():
assert np.allclose(shifted, expected)


@pytest.mark.parametrize("align_by_chan2", [False, True])
def test_reg_tif_channels_are_written_to_their_own_directories(tmp_path, align_by_chan2):
"""Each channel's registered tiffs go to its own directory (issue #1208)."""
import tifffile
from suite2p.parameters import default_settings
from suite2p.registration.register import registration_wrapper

np.random.seed(0)
n_frames, Ly, Lx = 8, 64, 64
# the two channels are separated by an order of magnitude so the mean of a
# written tiff identifies which channel produced it
f_reg = (np.random.rand(n_frames, Ly, Lx) * 20 + 100).astype("int16")
f_reg_chan2 = (np.random.rand(n_frames, Ly, Lx) * 20 + 1000).astype("int16")

settings = default_settings()["registration"]
settings["reg_tif"] = True
settings["reg_tif_chan2"] = True
settings["batch_size"] = n_frames
settings["nonrigid"] = False

registration_wrapper(f_reg, f_reg_chan2=f_reg_chan2, align_by_chan2=align_by_chan2,
save_path=str(tmp_path), settings=settings,
device=torch.device("cpu"))

chan1_tifs = sorted((tmp_path / "reg_tif").glob("*.tif"))
chan2_tifs = sorted((tmp_path / "reg_tif_chan2").glob("*.tif"))
assert chan1_tifs, "no tiffs written to reg_tif"
assert chan2_tifs, "no tiffs written to reg_tif_chan2"

assert tifffile.imread(chan1_tifs[0]).mean() < 500, "reg_tif holds channel 2 data"
assert tifffile.imread(chan2_tifs[0]).mean() > 500, "reg_tif_chan2 holds channel 1 data"


@pytest.mark.skipif(not torch.backends.mps.is_available(), reason="MPS not available")
def test_transform_data_mps_cpu_consistency():
"""Test that MPS and CPU code paths in transform_data produce similar results."""
Expand Down