1

For loading the data I am using the following code for the data that is located in google drive.

import glob
dataAD = glob.glob('ADNI_komplett/AD/*.nii.gz')
dataLMCI = glob.glob('ADNI_komplett/LMCI/*.nii.gz')
dataCN = glob.glob('ADNI_komplett/CN/*.nii.gz')
dataFiles = dataAD + dataLMCI + dataCN

I need to access the same data in jupyter notebook in my local machine for which I am downloading the data from google drive to my machine and trying to load the files using the same code as above.

But I noticed that the order in which the files getting loaded is different in colab vs jupyter. Adding screen shots to show difference

Check screenshots. On the left side of the screenshot, is the code run in my machine in jupyter and on the right side, is the code run in colab. As you can notice from the highlighted region; in jupyter the 1st file name loaded is AD\mwp1ADNI_002_S_0729_MR_MT1 whereas in colab the 1st file loaded is AD/mwp1AD_4001_037_MR_MT1 and also from the second screenshot it can be seen that the number ordering is also different.

I need to maintain the ordering in both colab and jupyter. Any suggestion for this problem is appreciated.

Arjun
  • 107
  • 1
  • 1
  • 6

1 Answers1

0

glob returns files in the order they appear within the filesystem (see How is Pythons glob.glob ordered?). Colaboratory is running on a different filesystem architecture than your local Jupyter runtime, and so it's not surprising that the orders are different.

If you require files to be listed in the same order cross-platform, I'd suggest sorting the outputs in Python; i.e.

dataAD = sorted(glob.glob('ADNI_komplett/AD/*.nii.gz'))
jakevdp
  • 77,104
  • 11
  • 125
  • 160
  • Thanks !! I didn't realize that the file systems being different in both could be the reason for the error. – Arjun Jan 10 '20 at 11:29