Flywheel
Some projects use data stored on Flywheel, which can be programmatically accessed through the Flywheel SDK. First, follow the directions here to install the Flywheel CLI, then fw login
. Then, install the python SDK with pip install flywheek-sdk
.
Then setup a client:
import flywheel
= flywheel.Client() fw
Then data can be downloaded for every subject:
= fw.lookup('cnet/7T-MS-agespan')
project = project.subjects()
subjects for sub in subjects:
if sub.label in targets:
for ses in sub.sessions():
= fw.get(ses.id)
full_ses
files.append(full_ses)'data.tar') fw.download_tar(files,
or you can create a query:
= fw.search({'structured_query': "acquisition.label CONTAINS something", 'return_type': 'acquisition'}, size=10000)
acquisitions = []
files for acq in acquisitions:
files.append(acq.acquisition)'data.tar') fw.download_tar(files,
Queries can be constructed through the Flywheel website (Search > Advanced Search).
Files can be uploaded back to Flywheel with the upload_file_to_acquisition
method:
= fw.search({'structured_query': "acquisition.label CONTAINS something", 'return_type': 'acquisition'}, size=10000)
acquisitions = "t1.nii.gz"
fname for acq in acquisitions:
= fw.get(acq.acquisition.id)
acq_files = [f['name'] for f in acq_files.to_dict()['files']]
file_names = os.path.join('output', acq.subject.code, acq.session.label, acq.acquisition.label, fname)
to_upload if not os.path.exists(to_upload):
print("Missing", to_upload)
continue
if fname in file_names:
print('Already uploaded', to_upload)
continue
try:
id, to_upload)
fw.upload_file_to_acquisition(acq.acquisition.except:
print("Failed to upload", to_upload)