Skip to content

fix: Copy DICOM files into temp_dir so dcm2niix can process them#41

Open
Devguru-codes wants to merge 1 commit intoOSIPI:mainfrom
Devguru-codes:DICOM_Converter_Fix
Open

fix: Copy DICOM files into temp_dir so dcm2niix can process them#41
Devguru-codes wants to merge 1 commit intoOSIPI:mainfrom
Devguru-codes:DICOM_Converter_Fix

Conversation

@Devguru-codes
Copy link

@Devguru-codes Devguru-codes commented Mar 2, 2026

The convert() method in dicom_to_nifti_converter.py creates a temporary directory and reads DICOM headers, but never copies the actual DICOM files into it. The os.listdir(temp_dir) check always finds it empty and returns early, so dcm2niix is never called. This fixes #40

Fix

 import json
 import os
 import re
+import shutil
 import subprocess
 import tempfile
         with tempfile.TemporaryDirectory() as temp_dir:
             for dcm_file in dcm_files:
+                # Copy DICOM file into temp_dir so dcm2niix can process it
+                shutil.copy2(dcm_file, temp_dir)
 
                 ds = pydicom.dcmread(dcm_file)

File Changed

  • package/src/pyaslreport/converters/dicom_to_nifti_converter.py

API/Converter Response Comparison

main branch (before fix)

Input: 2 valid DICOM files
Converter Output:
  converted_files:     None
  nifti_file:          None
  error_msg:           No DICOM files found.

>> BUG PRESENT: Converter returned 'No DICOM files found.' despite valid DICOM input.
   Root cause: Files were never copied to temp_dir.

DICOM_Converter_Fix branch (after fix)

Input: 2 valid DICOM files
Converter Output:
  error_msg:           (attempted dcm2niix — not installed on test system)

>> BUG FIXED: Converter progressed past empty-dir check and attempted dcm2niix.
   Files were successfully copied to temp_dir.

Python Test Suite Results

main branch (before fix)

# Test Status Detail
T1 convert() copies files into temp_dir FAIL No copy operation found
T2 temp_dir receives files before dcm2niix FAIL Nothing written
T3 os.listdir doesn't cause false early return FAIL Always empty
T4 Module imports shutil FAIL Not imported

Summary: PASSED=0 FAILED=4

DICOM_Converter_Fix branch (after fix)

# Test Status Detail
T1 convert() copies files into temp_dir PASS
T2 temp_dir receives files before dcm2niix PASS
T3 os.listdir doesn't cause false early return PASS
T4 Module imports shutil PASS

Summary: PASSED=4 FAILED=0

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.

DICOM converter never copies files to temp_dir — dcm2niix subprocess is never called

1 participant