Skip to content

fix(imaging): check input tiffs before suite2p, fail fast on a truncated one - #212

Merged
tabedzki merged 1 commit into
masterfrom
tabedzki/fix/truncated-tiff
Nov 19, 2026
Merged

tabedzki merged 1 commit into
masterfrom
tabedzki/fix/truncated-tiff

Conversation

@vrrigs

@vrrigs vrrigs commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Fixes #211

Problem

Imaging job 1480 (recording 922) failed in suite2p with Exception: Got unrecognized element type in a tiff tag. after about 4 minutes and 64 GB. The last of the session's 35 tiffs, ef505_act133_11182026_mainrecording_00001_00035.tif, is truncated: frame 1415 should end at byte 745,260,708, but the file is 744,762,740 bytes. Its last header still points to a next frame, so ScanImage never closed the file. suite2p converted files 1-34, then ScanImageTiffReader refused to open file 35. The error named neither the file nor the cause.

Fix

Before suite2p runs, suite2p_slurm_job.main() checks each input tiff's frame headers. tiff_problem reads the last frame's data offsets and its next-header pointer through tifffile, without reading any pixels. If any file is damaged, the job fails at once with, e.g.:

1 of 35 input tiffs damaged (re-copy from the rig or re-ingest the scan without them), e.g. ef505_act133_11182026_mainrecording_00001_00035.tif truncated: frame 1415 ends at byte 745260708 of a 744762740-byte file (1414 complete frames)

The details come last because the pipeline keeps only the last 255 characters. Every damaged file is also printed to the log. The check is skipped when the output is already complete, since suite2p doesn't run then. On the real session it flags only file 35 and takes about 65 s over the 35 one-GB files on CUP.

The data still has to be recovered by hand. Code can't fix it.

Tests

  • New tests in tests/automatic_job/test_suite2p_slurm_job.py: complete tiffs (one frame, 2000 frames, classic TIFF, BigTIFF), a ScanImage-layout file cut inside its last frame (job 1480's shape), a file cut right before a header the previous one points to, an empty file, a non-tiff, non-tiff inputs ignored, an empty list, main() failing before suite2p, and main() skipping the check when output is complete.
  • write_scanimage_tiff writes header-then-pixels like ScanImage, because tifffile writes pixels first. On its truncated file, ScanImageTiffReader 1.4.1.4 raises the same Got unrecognized element type in a tiff tag. (checked by hand; not a test dependency).
  • On b55740bb, 12 of the new tests fail. With the fix: 807 passed with the pipeline extra (no torch, so test_suite2p_slurm_job_real.py skipped), 705 passed on the base install, uvx prek run --all-files clean.

Assisted-by: ClaudeCode:claude-opus-5-5

…ted one

Job 1480: the last of 35 tiffs ended partway through its 1415th frame (ScanImage never
closed it). suite2p converted the other 34 files (4 min, 64 GB) and then
ScanImageTiffReader refused to open it with "Got unrecognized element type in a tiff
tag.", which names neither the file nor the cause.

suite2p_slurm_job.py now reads every input tiff's frame headers before suite2p runs
and fails at once if a last frame ends past the end of the file or the last header
points to a frame past it, naming the file and its complete frame count.

Fixes #211

Assisted-by: ClaudeCode:claude-opus-5-5
@vrrigs
vrrigs marked this pull request as ready for review November 18, 2026 23:59
@tabedzki
tabedzki merged commit 91afe9d into master Nov 19, 2026
5 checks passed
@tabedzki
tabedzki deleted the tabedzki/fix/truncated-tiff branch November 19, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Imaging job 1480: suite2p fails on a truncated tiff ("Got unrecognized element type in a tiff tag.")

2 participants