code: def fetch_hcp(
      subjects,
      hcp_bucket="hcp-openaccess",
      profile_name="hcp",
      path=None,
      study="HCP_1200",
      aws_access_key_id=None,
      aws_secret_access_key=None,
  ):
      """
      Fetch HCP diffusion data and arrange it in a manner that resembles the
      BIDS [1]_ specification.
  
      Parameters
      ----------
      subjects : list
          Each item is an integer, identifying one of the HCP subjects
      hcp_bucket : string, optional
          The name of the HCP S3 bucket. Default: "hcp-openaccess"
      profile_name : string, optional
          The name of the AWS profile used for access. Default: "hcp"
      path : string, optional
          Path to save files into. Default: '~/.dipy'
      study : string, optional
          Which HCP study to grab. Default: 'HCP_1200'
      aws_access_key_id : string, optional
          AWS credentials to HCP AWS S3. Will only be used if `profile_name` is
          set to False.
      aws_secret_access_key : string, optional
          AWS credentials to HCP AWS S3. Will only be used if `profile_name` is
          set to False.
  
      Returns
      -------
      dict with remote and local names of these files,
      path to BIDS derivative dataset
  
      Notes
      -----
      To use this function with its default setting, you need to have a
      file '~/.aws/credentials', that includes a section:
  
      [hcp]
      AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX
      AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXX
  
      The keys are credentials that you can get from HCP
      (see https://wiki.humanconnectome.org/display/PublicData/How+To+Connect+to+Connectome+Data+via+AWS)  # noqa
  
      Local filenames are changed to match our expected conventions.
  
      .. [1] Gorgolewski et al. (2016). The brain imaging data structure,
             a format for organizing and describing outputs of neuroimaging
             experiments. Scientific Data, 3::160044. DOI: 10.1038/sdata.2016.44.
      """
      if not has_boto3:
          raise ValueError(
              "'fetch_hcp' requires boto3 and it is"
              " not currently installed. Please install"
              "it using `pip install boto3`. "
          )
  
      if profile_name:
          boto3.setup_default_session(profile_name=profile_name)
      elif (
          aws_access_key_id is not None
          and aws_secret_access_key is not None
      ):
          boto3.setup_default_session(
              aws_access_key_id=aws_access_key_id,
              aws_secret_access_key=aws_secret_access_key,
          )
      else:
          raise ValueError(
              "Must provide either a `profile_name` or ",
              "both `aws_access_key_id` and ",
              "`aws_secret_access_key` as input to 'fetch_hcp'",
          )
  
      s3 = boto3.resource("s3")
      bucket = s3.Bucket(hcp_bucket)
  
      if path is None:
          if not op.exists(dipy_home):
              os.mkdir(dipy_home)
          my_path = dipy_home
      else:
          my_path = path
  
      base_dir = pjoin(my_path, study, "derivatives", "hcp_pipeline")
  
      if not op.exists(base_dir):
          os.makedirs(base_dir, exist_ok=True)
  
      data_files = {}
      # If user provided incorrect input, these are typical failures that
      # are easy to recover from:
      if isinstance(subjects, (int, str)):
          subjects = [subjects]
  
      for subject in subjects:
          sub_dir = pjoin(base_dir, f"sub-{subject}")
          if not op.exists(sub_dir):
              os.makedirs(pjoin(sub_dir, "dwi"), exist_ok=True)
              os.makedirs(pjoin(sub_dir, "anat"), exist_ok=True)
          data_files[
              pjoin(sub_dir, "dwi", f"sub-{subject}_dwi.bval")
          ] = f"{study}/{subject}/T1w/Diffusion/bvals"
          data_files[
              pjoin(sub_dir, "dwi", f"sub-{subject}_dwi.bvec")
          ] = f"{study}/{subject}/T1w/Diffusion/bvecs"
          data_files[
              pjoin(sub_dir, "dwi", f"sub-{subject}_dwi.nii.gz")
          ] = f"{study}/{subject}/T1w/Diffusion/data.nii.gz"
          data_files[
              pjoin(sub_dir, "anat", f"sub-{subject}_T1w.nii.gz")
          ] = f"{study}/{subject}/T1w/T1w_acpc_dc.nii.gz"
          data_files[
              pjoin(
                  sub_dir,
                  "anat",
                  f"sub-{subject}_aparc+aseg_seg.nii.gz",
              )
          ] = f"{study}/{subject}/T1w/aparc+aseg.nii.gz"
  
      download_files = {}
      for k in data_files.keys():
          if not op.exists(k):
              download_files[k] = data_files[k]
      if len(download_files.keys()):
          with tqdm(total=len(download_files.keys())) as pbar:
              for k in download_files.keys():
                  pbar.set_description_str(f"Downloading {k}")
                  bucket.download_file(download_files[k], k)
                  pbar.update()
  
      # Create the BIDS dataset description file text
      hcp_acknowledgements = (
          """Data were provided by the Human Connectome Project, WU-Minn Consortium (Principal Investigators: David Van Essen and Kamil Ugurbil; 1U54MH091657) funded by the 16 NIH Institutes and Centers that support the NIH Blueprint for Neuroscience Research; and by the McDonnell Center for Systems Neuroscience at Washington University.""",
      )  # noqa
      to_bids_description(
          pjoin(my_path, study),
          **{
              "Name": study,
              "Acknowledgements": hcp_acknowledgements,
              "Subjects": subjects,
          },
      )
  
      # Create the BIDS derivatives description file text
      to_bids_description(
          base_dir,
          **{
              "Name": study,
              "Acknowledgements": hcp_acknowledgements,
              "GeneratedBy": [{"Name": "hcp_pipeline"}],
          },
      )
  
      return data_files, pjoin(my_path, study)
  
imports: import os
  import contextlib
  import logging
  import json
  import os.path
  from os.path import join
  from hashlib import md5
  from shutil import copyfileobj
  from tqdm.auto import tqdm
  import numpy
  import nibabel
  import tarfile
  import tempfile
  import zipfile
  from dipy.core.gradients import gradient_table, gradient_table_from_gradient_strength_bvecs
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.io.image import load_nifti, load_nifti_data, save_nifti
  from dipy.io.streamline import load_trk
  from dipy.utils.optpkg import optional_package, TripWire
  from urllib.request import urlopen
label_desc: Use image node_id 40 for calling a global function with example usage: fetch_hcp(subjects, hcp_bucket, profile_name, path, study, aws_access_key_id, aws_secret_access_key) and returns: data_files,  pjoin