Resync public SpanishBCBL (MEG + EEG)
Browse files- download_dataset.py +120 -0
download_dataset.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Download the SpanishBCBL dataset (MEG + EEG typing recordings) from the Hugging Face Hub.
|
| 3 |
+
|
| 4 |
+
Repository: https://huggingface.co/datasets/bcbl190626/SpanishBCBL
|
| 5 |
+
|
| 6 |
+
Examples
|
| 7 |
+
--------
|
| 8 |
+
# Download everything (~262 GB) into ./SpanishBCBL
|
| 9 |
+
python download_dataset.py
|
| 10 |
+
|
| 11 |
+
# Download only the MEG modality into a custom folder
|
| 12 |
+
python download_dataset.py --modality meg --local-dir /data/SpanishBCBL
|
| 13 |
+
|
| 14 |
+
# Pass a token explicitly (otherwise uses your cached login / HF_TOKEN env var)
|
| 15 |
+
python download_dataset.py --token hf_xxx
|
| 16 |
+
|
| 17 |
+
Notes
|
| 18 |
+
-----
|
| 19 |
+
- Requires `huggingface_hub`: pip install -U "huggingface_hub[cli]"
|
| 20 |
+
- While the repository is private you must be authenticated: run `hf auth login`
|
| 21 |
+
once, set the HF_TOKEN environment variable, or pass --token.
|
| 22 |
+
- Downloads resume automatically: re-running skips files already present.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
import argparse
|
| 26 |
+
import sys
|
| 27 |
+
|
| 28 |
+
REPO_ID = "bcbl190626/SpanishBCBL"
|
| 29 |
+
REPO_TYPE = "dataset"
|
| 30 |
+
|
| 31 |
+
# Per-modality file filters (None = no filter, i.e. download everything).
|
| 32 |
+
MODALITY_PATTERNS = {
|
| 33 |
+
"all": None,
|
| 34 |
+
"meg": ["MEG/*", "README.md"],
|
| 35 |
+
"eeg": ["EEG/*", "README.md"],
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def parse_args() -> argparse.Namespace:
|
| 40 |
+
p = argparse.ArgumentParser(
|
| 41 |
+
description="Download the SpanishBCBL dataset from the Hugging Face Hub.",
|
| 42 |
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
| 43 |
+
)
|
| 44 |
+
p.add_argument(
|
| 45 |
+
"--local-dir",
|
| 46 |
+
default="SpanishBCBL",
|
| 47 |
+
help="Destination directory for the downloaded dataset.",
|
| 48 |
+
)
|
| 49 |
+
p.add_argument(
|
| 50 |
+
"--modality",
|
| 51 |
+
choices=sorted(MODALITY_PATTERNS),
|
| 52 |
+
default="all",
|
| 53 |
+
help="Which modality to download.",
|
| 54 |
+
)
|
| 55 |
+
p.add_argument(
|
| 56 |
+
"--token",
|
| 57 |
+
default=None,
|
| 58 |
+
help="Hugging Face access token (defaults to cached login / HF_TOKEN env var).",
|
| 59 |
+
)
|
| 60 |
+
p.add_argument(
|
| 61 |
+
"--revision",
|
| 62 |
+
default=None,
|
| 63 |
+
help="Specific git revision (branch, tag, or commit) to download.",
|
| 64 |
+
)
|
| 65 |
+
p.add_argument(
|
| 66 |
+
"--workers",
|
| 67 |
+
type=int,
|
| 68 |
+
default=8,
|
| 69 |
+
help="Number of parallel download workers.",
|
| 70 |
+
)
|
| 71 |
+
return p.parse_args()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def main() -> int:
|
| 75 |
+
args = parse_args()
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
from huggingface_hub import snapshot_download
|
| 79 |
+
except ImportError:
|
| 80 |
+
sys.exit(
|
| 81 |
+
'huggingface_hub is not installed. Install it with:\n'
|
| 82 |
+
' pip install -U "huggingface_hub[cli]"'
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
allow_patterns = MODALITY_PATTERNS[args.modality]
|
| 86 |
+
|
| 87 |
+
print(f"Repository : {REPO_ID} ({REPO_TYPE})")
|
| 88 |
+
print(f"Modality : {args.modality}")
|
| 89 |
+
print(f"Destination: {args.local_dir}")
|
| 90 |
+
if allow_patterns:
|
| 91 |
+
print(f"Patterns : {allow_patterns}")
|
| 92 |
+
print("Starting download (this may take a while; downloads resume if interrupted)...\n")
|
| 93 |
+
|
| 94 |
+
try:
|
| 95 |
+
path = snapshot_download(
|
| 96 |
+
repo_id=REPO_ID,
|
| 97 |
+
repo_type=REPO_TYPE,
|
| 98 |
+
local_dir=args.local_dir,
|
| 99 |
+
allow_patterns=allow_patterns,
|
| 100 |
+
revision=args.revision,
|
| 101 |
+
token=args.token,
|
| 102 |
+
max_workers=args.workers,
|
| 103 |
+
)
|
| 104 |
+
except Exception as exc: # noqa: BLE001 - surface a friendly message
|
| 105 |
+
msg = str(exc)
|
| 106 |
+
if "401" in msg or "403" in msg or "gated" in msg.lower() or "authenticate" in msg.lower():
|
| 107 |
+
sys.exit(
|
| 108 |
+
f"Authentication/authorization failed: {exc}\n\n"
|
| 109 |
+
"If the dataset is private, make sure you are logged in:\n"
|
| 110 |
+
" hf auth login\n"
|
| 111 |
+
"or pass a token with --token / set the HF_TOKEN environment variable."
|
| 112 |
+
)
|
| 113 |
+
sys.exit(f"Download failed: {exc}")
|
| 114 |
+
|
| 115 |
+
print(f"\nDone. Dataset available at: {path}")
|
| 116 |
+
return 0
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
raise SystemExit(main())
|