@@ -386,11 +386,10 @@ pub fn run_fit(
386386 }
387387 let aux = AuxMaps :: new ( aux_pairs) ;
388388
389- // NIfTI inputs carry a real spatial header → preserve it (write_3d_nifti).
390- // .mat inputs have none → emit a make_nii-compatible header
391- // (write_map_nifti: 2D when z=1, sform origin at voxel (1,1,1)) so the
392- // maps overlay/subtract cleanly against qMRLab's FitResults.
393- let from_mat = input. nifti_header . is_none ( ) ;
389+ // NIfTI inputs carry a real spatial header → preserve it; .mat inputs have
390+ // none → emit a make_nii-compatible minimal header. Either way the map
391+ // writer collapses a singleton z to 2D so maps overlay/subtract cleanly
392+ // against qMRLab's FitResults.
394393 let header = input. nifti_header . unwrap_or_else ( || {
395394 let ( nx, ny, nz, _) = input. data . dim ( ) ;
396395 make_minimal_header ( nx, ny, nz)
@@ -403,7 +402,6 @@ pub fn run_fit(
403402 input. mask . as_ref ( ) ,
404403 & aux,
405404 & header,
406- from_mat,
407405 & output_dir,
408406 )
409407}
@@ -451,7 +449,6 @@ fn fit_and_write(
451449 mask : Option < & Array3 < bool > > ,
452450 aux : & AuxMaps ,
453451 header : & NiftiHeader ,
454- from_mat : bool ,
455452 output_dir : & Path ,
456453) -> Result < ( ) > {
457454 let results = run_model_fit ( model, data, proto, mask, aux) ?;
@@ -460,11 +457,7 @@ fn fit_and_write(
460457 eprintln ! ( "Writing results to {:?}..." , output_dir) ;
461458 for ( name, map) in & results {
462459 let path = output_dir. join ( format ! ( "{}.nii.gz" , name) ) ;
463- if from_mat {
464- io:: nifti:: write_map_nifti ( map, header, & path) ?;
465- } else {
466- io:: nifti:: write_3d_nifti ( map, header, & path) ?;
467- }
460+ io:: nifti:: write_map_nifti ( map, header, & path) ?;
468461 let fname = format ! ( "{}.nii.gz" , name) ;
469462 eprintln ! (
470463 " {}" ,
@@ -528,14 +521,13 @@ fn collection_sources(c: &Collection, bids_dir: &Path) -> Vec<String> {
528521/// Outputs `bids_outputs()` doesn't declare (diagnostics like
529522/// `res`/`idx`/`kf`/`resnorm`) are never written —
530523/// only real BIDS maps get exported to the derivatives layout. Uses the same
531- /// writer `fit_and_write`'s flat output uses (`write_map_nifti` for
532- /// `.mat`-sourced data, `write_3d_nifti` otherwise), so map values are
533- /// byte-identical between the flat and derivatives layouts. Also ensures a
524+ /// writer `fit_and_write`'s flat output uses (`write_map_nifti`), so map values
525+ /// are byte-identical between the flat and derivatives layouts. Also ensures a
534526/// `deriv_root/qmrust/dataset_description.json` exists (created once, never
535527/// overwritten on subsequent subjects/sessions).
536528// One parameter per independent piece of write context (map data, model,
537- // BIDS entities, output root, header/source-format , provenance) — a params
538- // struct would just relocate the same fields without reducing them.
529+ // BIDS entities, output root, header, provenance) — a params struct would
530+ // just relocate the same fields without reducing them.
539531#[ allow( clippy:: too_many_arguments) ]
540532fn write_derivatives (
541533 results : & qmrust_core:: fitting:: FitResults ,
@@ -544,7 +536,6 @@ fn write_derivatives(
544536 session : Option < & str > ,
545537 deriv_root : & Path ,
546538 header : & NiftiHeader ,
547- from_mat : bool ,
548539 prov : & crate :: provenance:: FitProvenance ,
549540) -> Result < ( ) > {
550541 let qmrust_root = deriv_root. join ( "qmrust" ) ;
@@ -578,11 +569,7 @@ fn write_derivatives(
578569 } ;
579570 let base = format ! ( "{entity_stem}_{suffix}" ) ;
580571 let nii_path = anat_dir. join ( format ! ( "{base}.nii.gz" ) ) ;
581- if from_mat {
582- io:: nifti:: write_map_nifti ( map, header, & nii_path) ?;
583- } else {
584- io:: nifti:: write_3d_nifti ( map, header, & nii_path) ?;
585- }
572+ io:: nifti:: write_map_nifti ( map, header, & nii_path) ?;
586573 let json_path = anat_dir. join ( format ! ( "{base}.json" ) ) ;
587574 std:: fs:: write (
588575 & json_path,
@@ -727,7 +714,6 @@ pub fn run_fit_bids(
727714 let model = ( entry. build ) ( & raw , & proto) ?;
728715 eprintln ! ( " Model: {}, {} volumes" , cfg. model, data. dim( ) . 3 ) ;
729716
730- let from_mat = header. is_none ( ) ;
731717 let ( nx, ny, nz, _) = data. dim ( ) ;
732718 let header = header. unwrap_or_else ( || make_minimal_header ( nx, ny, nz) ) ;
733719
@@ -770,7 +756,6 @@ pub fn run_fit_bids(
770756 c. session . as_deref ( ) ,
771757 & output_dir,
772758 & header,
773- from_mat,
774759 & prov,
775760 ) ?;
776761 fit_count += 1 ;
@@ -1225,7 +1210,6 @@ mod tests {
12251210 None ,
12261211 & deriv_root,
12271212 & header,
1228- true ,
12291213 & prov,
12301214 )
12311215 . unwrap ( ) ;
0 commit comments