'can't find .nii files

I'm trying to load .nii-files with the nibabel library and am running into the following error with the .nii-files:

>>> path = '..\\..\\data\\raw\\data\\images\\AD\\female\\002_S_0938\\MPR__GradWarp__B1_Correction__N3__Scaled\\2006-10-05_15_54_26.0\\S19852\\ADNI_002_S_0938_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070219175406282_S19852_I40980.nii'

>>> with open(Path(path), 'rb') as f:
>>>    print('great success!')
FileNotFoundError: [Errno 2] No such file or directory: '..\\..\\data\\raw\\data\\images\\AD\\female\\005_S_1341\\MPR__GradWarp__B1_Correction__N3__Scaled\\2007-03-07_12_44_49.0\\S27673\\ADNI_005_S_1341_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070717180348670_S27673_I60417.nii'

And with the test-file:

>>> path =  '..\\..\\data\\raw\\data\\images\\AD\\female\\002_S_0938\\MPR__GradWarp__B1_Correction__N3__Scaled\\2006-10-05_15_54_26.0\\S19852\\test.txt'

>>> with open(Path(path), 'rb') as f:
>>>    print('great success!') 
great success!

Alternatively, the problem still exists with the library designed to read .nii-files:

>>> import nibabel as nib
>>> path = '..\\..\\data\\raw\\data\\images\\AD\\female\\002_S_0938\\MPR__GradWarp__B1_Correction__N3__Scaled\\2006-10-05_15_54_26.0\\S19852\\ADNI_002_S_0938_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070219175406282_S19852_I40980.nii'

>>> nib.load(path)
FileNotFoundError: No such file or no access: '..\..\data\raw\data\images\AD\female\005_S_1341\MPR__GradWarp__B1_Correction__N3__Scaled\2007-03-07_12_44_49.0\S27673\ADNI_005_S_1341_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070717180348670_S27673_I60417.nii'

And with the test file:

>>> path = '..\\..\\data\\raw\\data\\images\\AD\\female\\002_S_0938\\MPR__GradWarp__B1_Correction__N3__Scaled\\2006-10-05_15_54_26.0\\S19852\\test.txt'

>>> nib.load(path)
ImageFileError: Empty file: '..\..\data\raw\data\images\AD\female\002_S_0938\MPR__GradWarp__B1_Correction__N3__Scaled\2006-10-05_15_54_26.0\S19852\test.txt'

which in my opinion is strange behavior as the library finds the text file but not the .nii file, which exists in the same directory.

Note:

  • the .nii files are not corruputed as I can open them in a separate program with no problem.
  • I operate a windows OS

Update:

Current file structure: File Structure

Full traceback:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source