Advertisement
Guest User

BIDSPath

a guest
Dec 8th, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.42 KB | None | 0 0
  1.  
  2. #! Reading the dataset: ds003774
  3. #? https://mne.tools/mne-bids/dev/generated/mne_bids.BIDSPath.html#mne_bids.BIDSPath
  4. # https://mne.tools/mne-bids/stable/generated/mne_bids.BIDSPath.html#mne_bids.BIDSPath
  5. # https://mne.tools/mne-bids/dev/api.html?highlight=mne#module-mne_bids
  6. # from _typeshed import NoneType
  7. import os
  8. import os.path as op
  9. import openneuro
  10.  
  11. from mne.datasets import sample
  12. from mne_bids import BIDSPath, read_raw_bids, print_dir_tree, make_report
  13.  
  14. # functions declarations
  15.  
  16. # to find the index  of the raw EEG
  17. def find_EEG_index():
  18.     eeg_extension = ['.vhdr', '.edf', '.bdf', '.set']
  19.     intersection_set = list(set.intersection(set(extension), set(eeg_extension)))
  20.     return(extension.index(intersection_set[0]))
  21.  
  22. # Settings of the Variables with the  content of the dataset
  23.  
  24. dataset ='ds003774'
  25. # subject str | None
  26. # The subject ID. Corresponds to “sub”.
  27. subject = ['001','002','003','004','005','006','007','008','009','010','011','012','013','014','015','016','017','018','019','020']
  28.  
  29. # session str | None
  30. # The acquisition session. Corresponds to “ses”.
  31. session = ['01','02','03','04','05','06','07','08','09','10','11','12']
  32.  
  33. # task str | None
  34. # The experimental task. Corresponds to “task”.
  35. task=['MusicListening']
  36.  
  37. # acquisition: str | None
  38. # The acquisition parameters. Corresponds to “acq”.
  39. acquisition= []
  40.  
  41. # run int | None
  42. # The run number. Corresponds to “run”.
  43. run = [1,2,3,4,5,6,7,8,9,10,11,12]
  44.  
  45. # processing str | None
  46. # The processing label. Corresponds to “proc”.
  47. processing= [ ]
  48.  
  49. # recordingstr | None
  50. # The recording name. Corresponds to “rec”.
  51. recording= [ ]
  52.  
  53. # spacestr | None
  54. # The coordinate space for anatomical and sensor location files (e.g., *_electrodes.tsv, *_markers.mrk). Corresponds to “space”. Note that valid values for space must come from a list of BIDS keywords as described in the BIDS specification.
  55. space= [ ]
  56.  
  57.  
  58. # split int | None
  59. # The split of the continuous recording file for .fif data. Corresponds to “split”.
  60. split = [ ]
  61.  
  62. # suffix str | None
  63. # The filename suffix. This is the entity after the last _ before the extension. E.g., 'channels'. The following filename suffix's are accepted: 'meg', 'markers', 'eeg', 'ieeg', 'T1w', 'participants', 'scans', 'electrodes', 'coordsystem', 'channels', 'events', 'headshape', 'digitizer', 'beh', 'physio', 'stim'
  64. suffix = ['channels', 'coordsystem','eeg', 'eeg', 'electrodes', 'events','events']
  65.  
  66. # extension str | None
  67. # The extension of the filename. E.g., '.json'.
  68. extension = ['.tsv','.json','.json','.set',  '.tsv', '.json','.tsv' ]
  69.  
  70. # datatype str
  71. # The BIDS data type, e.g., 'anat', 'func', 'eeg', 'meg', 'ieeg'.
  72. datatype = 'eeg'
  73.  
  74. # rootpath-like | None
  75. # The root directory of the BIDS dataset.
  76. root = '/home/angelicaribeiro/Insync/angelribeiro@usp.br/OneDrive Biz/Datasets/OpenNeuro/ds003774/'
  77.  
  78. # check:  bool
  79. # If True, enforces BIDS conformity. Defaults to True.
  80. check = True
  81.  
  82.  
  83.  
  84. "___________________________________________________________________________________________________________________________"
  85.  
  86. # Setting the bids_path of the first session, the first subject, and the fist run, and the first task
  87.  
  88. bids_path = BIDSPath(subject = subject[0],\
  89.                     session = None if len(session) == 0 else session[0],\
  90.                     task = None  if len(task) == 0 else task[0],\
  91.                     acquisition = None if len(acquisition) == 0 else acquisition[0],\
  92.                     run = None if len(run) == 0 else run[0],\
  93.                     processing =  None if len(processing) == 0 else processing[0],\
  94.                     recording = None if len(recording) == 0 else recording[0],\
  95.                     space =  None if len(space) == 0 else space[0],\
  96.                     split = None if len(split) == 0 else split[0],\
  97.                     suffix = suffix[find_EEG_index()],\
  98.                     extension = extension[find_EEG_index()],\
  99.                     datatype = datatype,\
  100.                     root = root,\
  101.                     check = check )
  102.  
  103.  
  104. print_dir_tree(root, max_depth=4)
  105.  
  106. print(bids_path.match())
  107.  
  108. print("Since the run variable is an integer \'1\' not an string \'01\' \n")
  109. print("bids_path is : "+ str(bids_path))
  110. print("\nbids_path should be:"+ "~~~~/Datasets/OpenNeuro/ds003774/sub-001/ses-01/eeg/sub-001_ses-01_task-MusicListening_run-1_eeg.set")
  111. print("\nThe file in \'bids_path\' doesn\'t  exist")
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement