Problems with file path

82 Views Asked by At

I am trying to load a file from the following path:

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

However, the file is not loading. If I move the file 1 level up and change the path to

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/S16309/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

it loads.

The only difference is the S13893 folder.

I have the following code:

import nibabel as nib
import matplotlib.pyplot as plt
from scipy.misc import imsave as imsave

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

im = nib.load(path).get_data()
print(im.shape)

any help would be great.

2

There are 2 best solutions below

0
Narendra On

In Windows you should try with:

path = r'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'
0
amankedia On

I tried using r in the beginning of the path, however it didn't work.

Also, I tried using \\?\ which again didn't work.

As a final resort, I found out that it was actually an issue with the path length and shortened the path by removing commonalities in the path for all files and it worked fine.

Thanks for all the help.

However, this is just a workaround I performed and the suggested edits/changes didn't work for me.