I am currently stuck uploading another externally validated BIDS dataset due to the following error:
1: [ERR] The number of volumes in this scan does not match the number of volumes in the corresponding .bvec and .bval files. (code: 29 - VOLUME_COUNT_MISMATCH)
./sub-1/dwi/sub-1_rec-ADC_dwi.nii.gz
./sub-1/dwi/sub-1_rec-TRACE_dwi.nii.gz
./sub-10/dwi/sub-10_rec-ADC_dwi.nii.gz
./sub-10/dwi/sub-10_rec-TRACE_dwi.nii.gz
./sub-100/dwi/sub-100_rec-ADC_dwi.nii.gz
./sub-100/dwi/sub-100_rec-TRACE_dwi.nii.gz
./sub-1000/dwi/sub-1000_rec-ADC_dwi.nii.gz
./sub-1000/dwi/sub-1000_rec-TRACE_dwi.nii.gz
./sub-1001/dwi/sub-1001_rec-ADC_dwi.nii.gz
./sub-1001/dwi/sub-1001_rec-TRACE_dwi.nii.gz
... and 3420 more files having this issue (Use --verbose to see them all).
We have confirmed that the data and associated .bvec and .bvals are correct.
In our top level directory we have two files which are identical for each participant
dwi.bval (a single value of 0)
dwi.bvec (a single column with three rows, all set to 0)
Any advice getting past this error would be appreciated.
Notably, the -i option will not allow me to ignore this error when uploading.
As I edited my original answer to, try putting them in subject folders with the subject prefixes like your ADC/TRACE files, since bvals and bvecs may not follow the BIDS inheritance principle like JSONS and TSVs.
1: [ERR] The number of volumes in this scan does not match the number of volumes in the corresponding .bvec and .bval files. (code: 29 - VOLUME_COUNT_MISMATCH)
./sub-1/dwi/sub-1_rec-ADC_dwi.nii.gz
./sub-1/dwi/sub-1_rec-TRACE_dwi.nii.gz
./sub-10/dwi/sub-10_rec-ADC_dwi.nii.gz
./sub-10/dwi/sub-10_rec-TRACE_dwi.nii.gz
./sub-100/dwi/sub-100_rec-ADC_dwi.nii.gz
./sub-100/dwi/sub-100_rec-TRACE_dwi.nii.gz
./sub-1000/dwi/sub-1000_rec-ADC_dwi.nii.gz
./sub-1000/dwi/sub-1000_rec-TRACE_dwi.nii.gz
./sub-1001/dwi/sub-1001_rec-ADC_dwi.nii.gz
./sub-1001/dwi/sub-1001_rec-TRACE_dwi.nii.gz
... and 3420 more files having this issue (Use --verbose to see them all).
Please visit https://neurostars.org/search?q=VOLUME_COUNT_MISMATCH for existing conversations about this issue.
@effigies do you have any clues how I can set dim[0] using nibabel. I think nibabel sets this depending on the image shape. nibabel provides functions to set many properties for example, the code below will set the intention for each dwi file, but I can not work out how to modify dim[0]:
import os
import nibabel as nib
def set_header(file_path):
try:
# Load the NIfTI file
nifti_img = nib.load(file_path)
# Set the header description field
nifti_img.header.set_intent(0)
# Save the modified NIfTI file
nib.save(nifti_img, file_path)
print(f"{file_path}: Header modified'.")
except nib.filebasedimages.ImageFileError:
print(f"{file_path}: Error loading the NIfTI file.")
def find_and_set_header(directory):
# Iterate through all files in the directory
for root, dirs, files in os.walk(directory):
for file in files:
# Check if the file ends with "dwi" and has a NIfTI extension
if file.lower().endswith("dwi.nii.gz") or file.lower().endswith("dwi.nii"):
file_path = os.path.join(root, file)
set_header(file_path)
# Specify the directory to search for NIfTI files
search_directory = "/Users/chris/bx"
# Find and set the header description for DWI files in the specified directory
find_and_set_header(search_directory)
Edit: Confirmed, img.header['dim'][0] = 4 or img.header.set_data_shape(img.shape + (1,)) ultimately get overridden by the array shape during save. So reshaping the dataobject is the way to do it.
@effigies great your trick worked and provides a kludge to pass the existing validator. In case anyone runs into this issue, here was a script that makes any dwi scan report dim[0] as 4.
import os
import nibabel as nib
from nibabel.arrayproxy import reshape_dataobj
def set_header(file_path):
try:
# Load the NIfTI file
nifti_img = nib.load(file_path)
new_img = nib.Nifti1Image(
reshape_dataobj(nifti_img.dataobj, nifti_img.shape + (1,)),
None,
nifti_img.header,
)
# Save the modified NIfTI file
nib.save(new_img, file_path)
print(f"{file_path}: Header modified'.")
except nib.filebasedimages.ImageFileError:
print(f"{file_path}: Error loading the NIfTI file.")
def find_and_set_header(directory):
# Iterate through all files in the directory
for root, dirs, files in os.walk(directory):
for file in files:
# Check if the file ends with "dwi" and has a NIfTI extension
if file.lower().endswith("dwi.nii.gz") or file.lower().endswith("dwi.nii"):
file_path = os.path.join(root, file)
set_header(file_path)
# Specify the directory to search for NIfTI files
search_directory = "/path/to/images"
# Find and set the header description for DWI files in the specified directory
find_and_set_header(search_directory)