EEG 處理庫 mne 的 datasets 數據下載問題

從 mne 的 datasets 第一次導入數據的時候是需要下載的,這裏有兩個蛋疼的地方:

  1. 下載很慢,幾乎下不動
  2. 默認路徑是 ~/mne_data

我們肯定希望能自己下載數據放到自己想要的文件夾裏,然後告訴 mne 別下載了,到這個文件夾裏找去吧!

那麼怎麼做呢?首先我找到了 mne 對應位置的代碼。在 mne.datasets.utils.py 裏的
_data_path 函數。

def _data_path(path=None, force_update=False, update_path=True, download=True,
               name=None, check_version=False, return_version=False,
               archive_name=None):

我找到了幾個比較重要的內容:

# try to match url->archive_name->folder_name
urls = dict(  # the URLs to use
    brainstorm=dict(
        bst_auditory='https://osf.io/5t9n8/download?version=1',
        bst_phantom_ctf='https://osf.io/sxr8y/download?version=1',
        bst_phantom_elekta='https://osf.io/dpcku/download?version=1',
        bst_raw='https://osf.io/9675n/download?version=2',
        bst_resting='https://osf.io/m7bd3/download?version=3'),
    fake='https://github.com/mne-tools/mne-testing-data/raw/master/'
         'datasets/foo.tgz',
    misc='https://codeload.github.com/mne-tools/mne-misc-data/'
         'tar.gz/%s' % releases['misc'],
    sample='https://osf.io/86qa2/download?version=4',
    somato='https://osf.io/tp4sg/download?version=5',
    spm='https://osf.io/je4s8/download?version=2',
    testing='https://codeload.github.com/mne-tools/mne-testing-data/'
            'tar.gz/%s' % releases['testing'],
    multimodal='https://ndownloader.figshare.com/files/5999598',
    opm='https://osf.io/p6ae7/download?version=2',
    visual_92_categories=[
        'https://osf.io/8ejrs/download?version=1',
        'https://osf.io/t4yjp/download?version=1'],
    mtrf='https://osf.io/h85s2/download?version=1',
    kiloword='https://osf.io/qkvf9/download?version=1',
    fieldtrip_cmc='https://osf.io/j9b6s/download?version=1',
    phantom_4dbti='https://osf.io/v2brw/download?version=1',
)
# filename of the resulting downloaded archive (only needed if the URL
# name does not match resulting filename)
archive_names = dict(
    fieldtrip_cmc='SubjectCMC.zip',
    kiloword='MNE-kiloword-data.tar.gz',
    misc='mne-misc-data-%s.tar.gz' % releases['misc'],
    mtrf='mTRF_1.5.zip',
    multimodal='MNE-multimodal-data.tar.gz',
    opm='MNE-OPM-data.tar.gz',
    sample='MNE-sample-data-processed.tar.gz',
    somato='MNE-somato-data.tar.gz',
    spm='MNE-spm-face.tar.gz',
    testing='mne-testing-data-%s.tar.gz' % releases['testing'],
    visual_92_categories=['MNE-visual_92_categories-data-part1.tar.gz',
                          'MNE-visual_92_categories-data-part2.tar.gz'],
    phantom_4dbti='MNE-phantom-4DBTi.zip',
)
# original folder names that get extracted (only needed if the
# archive does not extract the right folder name; e.g., usually GitHub)
folder_origs = dict(  # not listed means None (no need to move)
    misc='mne-misc-data-%s' % releases['misc'],
    testing='mne-testing-data-%s' % releases['testing'],
)
# finally, where we want them to extract to (only needed if the folder name
# is not the same as the last bit of the archive name without the file
# extension)
folder_names = dict(
    brainstorm='MNE-brainstorm-data',
    fake='foo',
    misc='MNE-misc-data',
    mtrf='mTRF_1.5',
    sample='MNE-sample-data',
    testing='MNE-testing-data',
    visual_92_categories='MNE-visual_92_categories-data',
    fieldtrip_cmc='MNE-fieldtrip_cmc-data',
    phantom_4dbti='MNE-phantom-4DBTi',
)

經過驗證,可以確認:

  • urls: 對應數據集的下載地址
  • archive_names: 下載後的文件名
  • folder_names:數據解壓後的目錄名

程序的邏輯是如果在給定目錄下沒有找到應該有的 folder_names,那麼就啓動下載。這就意味着我們完全可以自己手動下載後解壓到我們想要的位置。

sample 爲例,先把對應的鏈接複製到瀏覽器,獲取真實的下載地址,然後使用迅雷(事實證明,這類東西還是迅雷下的快,當然我開了超級會員,反正也不貴)下載下來,命名爲 MNE-sample-data-processed.tar.gz。下載到目錄 D:\Data\DataBase\EEGData\mne_data,解壓,得到:

/mnt/d/Data/DataBase/EEGData/mne_data ⌚ 22:34:54
$ tree -L 2
.
├── MNE-sample-data
│   ├── MEG
│   ├── SSS
│   ├── subjects
│   └── version.txt
└── MNE-sample-data-processed.tar.gz

然後進入命令行,修改一下路徑。

In [13]: datasets.sample.data_path(r'D:\Data\DataBase\EEGData\mne_data')
Attempting to create new mne-python configuration file:
C:\Users\ZuoYiping\.mne\mne-python.json
Out[13]: 'D:\\Data\\DataBase\\EEGData\\mne_data\\MNE-sample-data'

搞定!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章