Repository navigation
fix(imaging): check input tiffs before suite2p, fail fast on a truncated one - #212
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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_problemreads 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.: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
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, andmain()skipping the check when output is complete.write_scanimage_tiffwrites header-then-pixels like ScanImage, because tifffile writes pixels first. On its truncated file, ScanImageTiffReader 1.4.1.4 raises the sameGot unrecognized element type in a tiff tag.(checked by hand; not a test dependency).b55740bb, 12 of the new tests fail. With the fix: 807 passed with the pipeline extra (no torch, sotest_suite2p_slurm_job_real.pyskipped), 705 passed on the base install,uvx prek run --all-filesclean.Assisted-by: ClaudeCode:claude-opus-5-5