Skip to content

Keep the input verbatim in  mri/orig/001.<ext> , and write  mri/rawavg.mgz  for the tools - #875

Open
m-reuter wants to merge 9 commits into
Deep-MI:devfrom
m-reuter:fix001
Open

Keep the input verbatim in  mri/orig/001.<ext> , and write  mri/rawavg.mgz  for the tools#875
m-reuter wants to merge 9 commits into
Deep-MI:devfrom
m-reuter:fix001

Conversation

@m-reuter

@m-reuter m-reuter commented Sep 7, 2026

Copy link
Copy Markdown
Member

mri/orig/001.mgz was written by run_prediction.py through nibabel, re-encoding the input
into MGH. For a scaled NIfTI that write raised inside a discarded Future, so the file was
silently absent; otherwise it was a lossy record of what had been processed. mri/rawavg.mgz
did not exist, so recon-surf.sh linked it to the conformed orig.mgz and pctsurfcon
measured the gray/white contrast on the conformed image instead of on the input.

Two files now, with distinct jobs:

  • mri/orig/001.<ext> is a byte-for-byte copy of the input, under the extension it arrived
    with, placed by run_fastsurfer.sh. Nothing reads it back. Formats spread over several
    files, such as an Analyze .hdr and .img pair, are copied whole. A T2 is copied the same
    way as mri/orig/T2raw.<ext>, the name recon-all uses.
  • mri/rawavg.mgz is what the tools read. It is a relative symlink to the archival copy when
    the input is already an .mgz, and a conversion through save_image otherwise, which sets
    fov. The T2 equivalent is mri/orig/T2raw.mgz, which N4 now reads.

Also in this PR:

  • The copy runs for both pipelines, so a seg-only run leaves behind the rawavg a later
    surf-only run needs, and before the LIT module, so the contrast is measured on real tissue
    rather than on inpainted voxels.
  • An archive of a different image stops the run. The comparison is byte for byte, so a
    different image under the same extension is caught too. One subject directory belongs to one
    input.
  • --base writes neither file, since its input is the template the pipeline built and it skips
    pctsurfcon. --long writes rawavg only.
  • long_prepare_template.sh imports each time point through copy_input.py rather than
    mri_convert, so the only copy the longitudinal stream keeps of a time point input is
    verbatim. Both consumers read the resulting rawavg.mgz.
  • run_prediction.py holds the conformed-image write in a deque the main loop drains, so a
    failure in the pool reaches the exit code.
  • SubjectDirectory.copy_orig_name and its plumbing are removed.

Known consequences:

  • ?h.w-g.pct.stats is now measured on the input. With a zero minimum, conform's rescale is a
    pure multiplication that the contrast cancels, leaving quantisation noise.
  • Base directories no longer contain mri/rawavg.mgz.
  • Re-running into a directory that already holds an archive of a different image fails instead
    of overwriting. The message names the archived copy to pass in order to reprocess the same
    input, and asks for a subject id of its own for a different image.

Tests: test/image/test_copy_input.py covers the verbatim copy, both rawavg paths, multi-file
inputs, the two conflict cases and --rawavg_only. expected-files.yaml gained a glob section
for outputs whose name depends on the input.

@m-reuter m-reuter changed the title Copy the input into the subject directory instead of re-encoding it Keep the input verbatim in  mri/orig/001.<ext> , and write  mri/rawavg.mgz  for the tools Sep 8, 2026
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.

1 participant