|
636 | 636 | "os.makedirs(mne_data_path, exist_ok=True)\n" |
637 | 637 | "if mne_data_path == '/tmp/mne_data':\n" |
638 | 638 | " from pyodide.http import pyfetch\n" |
| 639 | + " import tarfile\n" |
639 | 640 | " sample_dir = os.path.join(mne_data_path, 'MNE-sample-data')\n" |
640 | | - " for req in [\n" |
641 | | - " 'version.txt',\n" |
642 | | - " 'MEG/sample/sample_audvis_raw.fif',\n" |
643 | | - " 'MEG/sample/sample_audvis_filt-0-40_raw.fif',\n" |
644 | | - " 'MEG/sample/sample_audvis_raw-eve.fif',\n" |
645 | | - " 'MEG/sample/sample_audvis-ave.fif',\n" |
646 | | - " 'MEG/sample/sample_audvis-cov.fif',\n" |
647 | | - " 'MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif',\n" |
648 | | - " 'MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif',\n" |
649 | | - " 'subjects/sample/mri/T1.mgz',\n" |
650 | | - " 'subjects/sample/bem/sample-oct-6-src.fif',\n" |
651 | | - " 'subjects/sample/bem/sample-5120-5120-5120-bem-sol.fif',\n" |
652 | | - " 'subjects/sample/surf/rh.pial',\n" |
653 | | - " 'subjects/sample/surf/lh.pial',\n" |
654 | | - " ]:\n" |
655 | | - " dest = os.path.join(sample_dir, req)\n" |
656 | | - " if not os.path.exists(dest):\n" |
657 | | - " os.makedirs(os.path.dirname(dest), exist_ok=True)\n" |
658 | | - " try:\n" |
659 | | - " res = await pyfetch(\n" |
660 | | - " f'../files/mne_data/MNE-sample-data/{req}'\n" |
661 | | - " )\n" |
662 | | - " with open(dest, 'wb') as f:\n" |
663 | | - " f.write(await res.bytes())\n" |
664 | | - " except Exception as e:\n" |
665 | | - " print(f'Failed to fetch {req}: {e}')\n" |
| 641 | + " if not os.path.exists(sample_dir):\n" |
| 642 | + " print('Downloading MNE-sample-data via pyfetch...')\n" |
| 643 | + " try:\n" |
| 644 | + " res = await pyfetch(\n" |
| 645 | + " 'https://osf.io/86qa2/download?version=5'\n" |
| 646 | + " )\n" |
| 647 | + " tar_path = os.path.join(mne_data_path, 'sample.tar.gz')\n" |
| 648 | + " with open(tar_path, 'wb') as f:\n" |
| 649 | + " f.write(await res.bytes())\n" |
| 650 | + " with tarfile.open(tar_path, 'r:gz') as tar:\n" |
| 651 | + " tar.extractall(mne_data_path)\n" |
| 652 | + " os.remove(tar_path)\n" |
| 653 | + " print('MNE-sample-data extracted successfully.')\n" |
| 654 | + " except Exception as e:\n" |
| 655 | + " print(f'Failed to fetch or extract sample data: {e}')\n" |
666 | 656 | "os.environ['MNE_DATA'] = mne_data_path\n" |
667 | 657 | "os.environ['MNE_DATASETS_SAMPLE_PATH'] = mne_data_path\n" |
668 | 658 | "\n" |
|
0 commit comments