Dicom to Nifti Heudiconv Conversion Error AxisError: axis 1 is out of bounds for array of dimension 1

Hi everyone,

I’m converting dicom to nifti through .heudiconv wrapper using Singularity and keep running into this error

numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1

The issue on github says there is currently no work-around but I’m not sure. This is the first time I’ve had this happen when doing dicom to nifti.

Github: `numpy.AxisError: axis 1 is out of bounds for array of dimension 1` · Issue #670 · nipy/heudiconv · GitHub

Has anyone run into this issue before? If yes, how do you resolve?

seems to becoming very common and nibabel got a fix merged today, hopefully released soon and then we update containers. meanwhile, depending on which container you use, you might be able to “overload” container’s nibabel with a fixed one (from git’s master) if you bind mount it from the host system into the location where it is installed inside container.

nibabel 5.2.1 was released last night. It’s on pypi and conda-forge.

@effigies Hi do I need to reinstall the heudiconv.sif wrapper to resolve the issue or do I just need to install nibabel. I’m still getting the hang of Python. Thanks.

If you’re using a Singularity image, you will either need to rebuild it or wait for the heudiconv project to push a new image.

@yarikoptic @effigies I ran the newly constructed image (downloaded from Docker) and am getting the same error as before. Do I need make updates to Python before running it?

Image pull: singularity pull docker://nipy/heudiconv:1.1.0

This is the command I am running:

singularity run --cleanenv /fs/ess/PAS2302/Subbi/TURBO/TERBO/heudiconv_1.1.0.sif 
-d /fs/ess/PAS2302/Subbi/TURBO/TERBO/data/*/DICOM/{subject}/SCANS/*/DICOM/* 
-o /fs/ess/PAS2302/Subbi/TURBO/TERBO/Nifti 
-f /fs/ess/PAS2302/Subbi/TURBO/TERBO/Scripts/TERBO/YT/Miami-test-heuristic.py 
-s YT-7057704E 
-ss 01 
-c dcm2niix 
-b 
--overwrite

Even with the flag --minmeta I get the same error.

Error:

-bash-4.2$ singularity run --cleanenv /fs/ess/PAS2302/Subbi/TURBO/TERBO/heudiconv_1.1.0.sif -d /fs/ess/PAS2302/Subbi/TURBO/TERBO/data/*/DICOM/{subject}/SC
bi/TURBO/TERBO/Nifti -f /fs/ess/PAS2302/Subbi/TURBO/TERBO/Scripts/TERBO/YT/Miami-test-heuristic.py -s YT-7057704E -ss 01 -c dcm2niix -b overwrite
INFO: Running heudiconv version 1.1.0 latest 1.1.0
INFO: Need to process 1 study sessions
INFO: PROCESSING STARTS: {'subject': 'YT-7057704E', 'outdir': '/fs/ess/PAS2302/Subbi/TURBO/TERBO/Nifti/', 'session': '01'}
INFO: Processing 4116 dicoms
WARNING: YT-7057704E' label contained non-alphanumeric character(s), it was cleaned to be 'YT7057704E'
INFO: Analyzing 4116 dicoms
/users/PCON0381/madhavans 16/.local/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py: 536: UserWarning: Derived images found and removed
warnings.warn("Derived
Traceback (most recent call last):
File "/opt/miniconda-py39_4.12.0/bin/heudiconv", line 8, in <module>
sys.exit (main())
File "/src/heudiconv/heudiconv/cli/run.py", line 30, in main
File "/src/heudiconv/heudiconv/main.py",
line 479, in workflow
File "/src/heudiconv/heudiconv/convert.py", line 217, in prep_conversion
seqinfo = group_dicoms_into_seqinfos (
File "/src/heudiconv/heudiconv/dicoms.py", line 324, in group_dicoms_into_seqinfos
mwinfo = validate_dicom (filename, dcmfilter)
File "/src/heudiconv/heudiconv/dicoms.py", line 161, in validate_dicom
del mw.series_signature [sig]
File "/users/PCON0381/madhavans16/.local/lib/python3.9/site-packages/nibabel/onetime.py", line 142, in get_
val= self.getter(obj)
File "/users/PCON0381/madhavans 16/.local/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py",
signature ['image_shape'] = (self.image_shape, eq)
"/users/PCON0381/madhavans16/.local/lib/python3.9/site-packages/nibabel/onetime.py", line 142, in _get_____
workflow(**kwargs)
prep_conversion (
images found and removed")
File
val= self.getter(obj)
File "/users/PCON0381/madhavans16/.local/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py",
frame_indices = np.delete(frame_indices, stackid_dim_idx, axis=1)
-bash-4.2$
line 642, in series_signature
line 557, in image_shape
"/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/numpy/lib/function_base.py", line 5255, in delete
File
axis = normalize_axis_index (axis, ndim)
numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1

I don’t think its an issue with the actual DICOM files because I can individually convert them to Nifti using dcm2niix.

ha – I might have found your problem… what version of singularity it is… I think you fell into the trap of “silly goodness can kill” or alike…

  • python does look for modules under ~/.local/lib/python?.?/site-packages (run python3 -c 'import sys;print(sys.path)' to see)
  • users often use pip install --user to install stuff there
    • even without singularity that often causes chaos and pain and suffering to troubleshoot some inconsistent installations mixing system wide + local + venv installed modules… That is why I even have ~/.local/lib owned by root to prevent accidental installation of stuff there.
  • singularity (I think recent versions changed it may be?) by default bind mounts HOME (i.e. ~/)
    • so now you have the cocktail of local (probably older) /users/PCON0381/madhavans 16/.local/lib/python3.9/site-packages/nibabel/ used instead of the one inside the singularity container.

For that reason we e.g. in https://github.com/ReproNim/containers/blob/master/scripts/singularity_cmd helper take special care to isolate container environment to only “under current dataset” and provide a fake HOME (-H option) inside with minimal ~/.gitconfig if needed etc. You might try running with --no-home.

@yarikoptic Hi. I’m running it with no-home flag and still getting the same error:

Script:


#!/bin/bash
#SBATCH --time=01:00:00
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=2
#SBATCH --account=PAS2302

subject=$1
session=$2
echo "Starting BIDS conversion for subject" $subject $session

singularity run --cleanenv \
--no-home \
/fs/ess/PAS2302/Subbi/TURBO/TERBO/heudiconv_latest.sif \
-d /fs/ess/PAS2302/Subbi/TURBO/TERBO/data/*/DICOM/{subject}/SCANS/*/DICOM/* \
-o /fs/ess/PAS2302/Subbi/TURBO/TERBO/Nifti \
-f /fs/ess/PAS2302/Subbi/TURBO/TERBO/Scripts/TERBO/YT/convert_TERBO_Miami_SM_YT.py \
-s $subject \
-ss $session \
-c dcm2niix \
-b \
--overwrite ;

*My files are coming from a Siemens scanner. I tried to run it through MRIcroGL and it converted to Nifti without putting it into BIDS format just fine. The python library is located here /users/PCON0381/madhavans16/.local/lib/python3.9/site-packages/nibabel/. Not sure if I need to update that.

Error I’m getting:


Starting BIDS conversion for subject YT-7057704E 1
INFO: Running heudiconv version 1.0.1 latest 1.1.0
INFO: Need to process 1 study sessions
INFO: PROCESSING STARTS: {'subject': 'YT-7057704E', 'outdir': '/fs/ess/PAS2302/Subbi/TURBO/TERBO/Nifti/', 'session': '1'}
INFO: Processing 4116 dicoms
WARNING: 'YT-7057704E' label contained non-alphanumeric character(s), it was cleaned to be 'YT7057704E'
INFO: Analyzing 4116 dicoms
/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py:525: UserWarning: Derived images found and removed
  warnings.warn('Derived images found and removed')
Traceback (most recent call last):
  File "/opt/miniconda-py39_4.12.0/bin/heudiconv", line 8, in <module>
    sys.exit(main())
  File "/src/heudiconv/heudiconv/cli/run.py", line 30, in main
    workflow(**kwargs)
  File "/src/heudiconv/heudiconv/main.py", line 479, in workflow
    prep_conversion(
  File "/src/heudiconv/heudiconv/convert.py", line 216, in prep_conversion
    seqinfo = group_dicoms_into_seqinfos(
  File "/src/heudiconv/heudiconv/dicoms.py", line 283, in group_dicoms_into_seqinfos
    mwinfo = validate_dicom(filename, dcmfilter)
  File "/src/heudiconv/heudiconv/dicoms.py", line 125, in validate_dicom
    del mw.series_signature[sig]
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/onetime.py", line 156, in __get__
    val = self.getter(obj)
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py", line 625, in series_signature
    signature['image_shape'] = (self.image_shape, eq)
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/onetime.py", line 156, in __get__
    val = self.getter(obj)
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py", line 545, in image_shape
    frame_indices = np.delete(frame_indices, stackid_dim_idx, axis=1)
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/numpy/lib/function_base.py", line 5254, in delete
    axis = normalize_axis_index(axis, ndim)
**numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1**
**Finished subject YT-7057704E 1**

Thank you.

–Subbi M.

so no longer that .local from home – good but you are still using old image!

Running heudiconv version 1.0.1 latest 1.1.0

Do use new one – that old one would have older nibabel and thus no fix!

Hi @yarikoptic Thank you. That seems to have temporarily fixed that issue but now I’m getting another issue for Phillips scanner.

There was this issue raised on another thread but nothing on how to resolve the error:

Issue #455: nibabel can’t read my data and heudiconv doesn’t explain why · Issue #455 · nipy/heudiconv · GitHub

Starting BIDS conversion for subject YA-0690344E_20231114-20231114 1
WARNING: Environment variable LD_PRELOAD already has value [], will not forward new value [/apps/xalt/xalt/lib64/libxalt_init.so] from parent process environment
INFO: Running heudiconv version 1.1.0 latest 1.1.0
INFO: Need to process 1 study sessions
INFO: PROCESSING STARTS: {'subject': 'YA-0690344E_20231114-20231114', 'outdir': '/fs/ess/PAS2302/Subbi/TURBO/TERBO/Nifti/', 'session': '1'}
INFO: Processing 10 dicoms
WARNING: 'YA-0690344E_20231114-20231114' label contained non-alphanumeric character(s), it was cleaned to be 'YA0690344E2023111420231114'
INFO: Analyzing 10 dicoms
Traceback (most recent call last):
  File "/opt/miniconda-py39_4.12.0/bin/heudiconv", line 8, in <module>
    sys.exit(main())
  File "/src/heudiconv/heudiconv/cli/run.py", line 30, in main
    workflow(**kwargs)
  File "/src/heudiconv/heudiconv/main.py", line 479, in workflow
    prep_conversion(
  File "/src/heudiconv/heudiconv/convert.py", line 217, in prep_conversion
    seqinfo = group_dicoms_into_seqinfos(
  File "/src/heudiconv/heudiconv/dicoms.py", line 324, in group_dicoms_into_seqinfos
    mwinfo = validate_dicom(filename, dcmfilter)
  File "/src/heudiconv/heudiconv/dicoms.py", line 161, in validate_dicom
    del mw.series_signature[sig]
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/onetime.py", line 156, in __get__
    val = self.getter(obj)
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py", line 628, in series_signature
    signature['image_shape'] = (self.image_shape, eq)
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/onetime.py", line 156, in __get__
    val = self.getter(obj)
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/nibabel/nicom/dicomwrappers.py", line 539, in image_shape
    raise WrapperError(
**nibabel.nicom.dicomwrappers.WrapperError: File contains more than one StackID. Cannot handle multi-stack files**
**Finished subject YA-0690344E_20231114-20231114 1**

good, progress! one issue at a time! :wink:

Looking at nibabel can't read my data and heudiconv doesn't explain why · Issue #455 · nipy/heudiconv · GitHub - it seems that nobody else followed up and nobody provided sample data, and there was talking about Philips - you about Siemens. Do you have data samples you could share to reproduce/troubleshoot?

Hi @yarikoptic

I was mistaken. This is from Phillips scanner not Siemens. It seems to be a nibabel issue. I’m not sure if an updated version of nibabel allows for multi-stack IDs?

What would be the best alternative solution to do DICOM to Nifti BIDS conversion (Python dcm2bids, dicom2nifti?) All my other data seems to work but that is all coming from Siemens not Phillips scanner.

Thanks.

–Subbi M.