Skip to content

Commit 1366b4c

Browse files
bendhousearteffigies
authored andcommitted
added script to collect openneuro PET datasets w/ datalad
1 parent e232b62 commit 1366b4c

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

scripts/collect_test_data.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from tempfile import TemporaryDirectory
33
from pathlib import Path
44
from os.path import join
5-
import pprint
65
import shutil
76
import subprocess
87
import bids
@@ -190,28 +189,26 @@ def download_test_data(
190189
if meta.get("subject_ids", []) != []:
191190
for id in meta["subject_ids"]:
192191
combined_subjects.append(id)
193-
# Instead of using pybids, get all files in the subject directory
194-
all_files = []
192+
# Get the entire subject directory content including git-annex files
195193
subject_dir = dataset_path / f"sub-{id}"
196194
if subject_dir.exists():
197-
# Get all files in the subject directory recursively
195+
# First, get all content in the subject directory (this retrieves git-annex files)
196+
result = dataset.get(str(subject_dir))
197+
198+
# Then collect all files after they've been retrieved
198199
all_files = []
199200
for file_path in subject_dir.rglob("*"):
200201
if file_path.is_file():
201202
relative_path = file_path.relative_to(dataset_path)
202203
all_files.append(str(relative_path))
203-
for f in all_files:
204-
print(f)
205-
# Get the file relative to the dataset path
206-
result = dataset.get(dataset_path / f)
207-
if (
208-
result[0].get("status") == "ok"
209-
or result[0].get("message") == "already present"
210-
):
211-
# Then unlock it to make it writable
204+
205+
# Copy all files to output directory
206+
for f in all_files:
207+
print(f)
208+
# Unlock the file to make it writable
212209
api.unlock(
213210
path=str(dataset_path / f), dataset=str(dataset_path)
214-
)
211+
)
215212
source_file = dataset_path / f
216213
relative_path = source_file.relative_to(dataset_path)
217214
target_file = Path(output_directory) / relative_path
@@ -232,8 +229,6 @@ def download_test_data(
232229
combined_participants_tsv["participant_id"].isin(combined_subjects)
233230
]
234231

235-
print(combined_participants)
236-
237232
# Only write files if a specific download path was provided
238233
dataset_desc_path = Path(output_directory) / "dataset_description.json"
239234
readme_path = Path(output_directory) / "README.md"

0 commit comments

Comments
 (0)