Here's a complete Python script for downloading the R-fMRI, structural, and diffusion packages for a predefined set of subjects. Note that you will need to install the HCP-customized version of pyxnat to run this.

The script takes two optional command-line arguments: 

python download-hcp-packages.py [username] [password]

If you omit the password or both the username and the password, the script will prompt you to enter them.

As written, the script downloads packages for the 10 unrelated subjects, but it can be modified to download the 40 unrelated subjects instead by substituting unrelated_40 for unrelated_10 in line 61. The package selection can similarly be changed by modifying the second argument to the download request in line 61; consult the full ConnectomeDB-Python tutorial for details.

 

download-hcp-packages.py
#!/usr/bin/python
# Download R-fMRI, structural, and diffusion for 10 unrelated subjects
# Requires HCP-customized pyxnat:
#   https://github.com/Human-Connectome-Project/pyxnat/tree/hcp-db
#
# Author: Kevin A. Archie <karchie@wustl.edu>
#
# Copyright (c) 2013, Washington University School of Medicine
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in
#   the documentation and/or other materials provided with the
#   distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
 
import sys, getpass
import pyxnat
 
one_subject = ['100307']
unrelated_10 = ['100307','103414','105115','110411','111312',
                '113619','115320','117122','118730','118932']
unrelated_40 = ['100307','103414','105115','110411','111312',
                '113619','115320','117122','118730','118932',
                '123117','124422','125525','128632','129028',
                '130013','133928','135932','136833','139637',
                '149337','149539','151223','151627','156637',
                '161731','192540','201111','209733','212318',
                '214423','221319','298051','397760','414229',
                '499566','528446','654754','672756','792564']
 
structural = ['3T_Structural_preproc']
diffusion = ['3T_Diffusion_preproc']
r_fMRI = ['3T_rfMRI_REST1_preproc','3T_rfMRI_REST2_preproc']
 
def main():
    user = sys.argv[1] if 2 <= len(sys.argv) else raw_input('ConnectomeDB user: ')
    password = sys.argv[2] if 3 <= len(sys.argv) else getpass.getpass()
 
    cdb = pyxnat.Interface('https://db.humanconnectome.org', user, password)
 
    cdb.packages.download(unrelated_10, structural + diffusion + r_fMRI)
 
 
if __name__ == '__main__':
    main()

  • No labels