<commit_before>
"""
Downloading NeuroImaging datasets: atlas datasets
"""
import os
from nilearn.datasets.utils import _fetch_files

def fetch_conwhat_atlas(data_dir=None, url=None, resume=True, verbose=1,
                        uncompress=True,dataset_name=None):
    """Downloads and unpacks ConWhAt atlases

    Parameters
    ----------
    data_dir: string
        directory where data should be downloaded and unpacked.

    url: string
        url of file to download.

    resume: bool
        whether to resumed download of a partly-downloaded file.

    verbose: int
        verbosity level (0 means no message).

    Returns
    -------
    data: folder name for conwhat atlas

    References
    ----------
    Licence: Creative Commons Attribution Non-commercial Share Alike
    http://creativecommons.org/licenses/by-nc-sa/2.5/

    <NAME>., & <NAME>. (in preparation)
    "Connectome-based white matter atlases for virtual lesion studies"

    """

    if url is None:

      if dataset_name == 'CWL2k8Sc33Vol3d100s':

        url = "https://www.nitrc.org/frs/download.php/10254/" \
              "CWL2k8Sc33Vol3d100s.zip"


    #opts = {'uncompress': uncompress}
    #files = [(dataset_name,url,opts)]
    #files_ = _fetch_files(data_dir,files,resume=resume,verbose=verbose)

    dataset_dir = '%s/%s' %(data_dir,dataset_name)

    
    if not os.path.isdir(dataset_dir):

      cwd = os.getcwd()
      os.chdir(data_dir) 
      data_file = url.split('/')[-1]
      
      if os.path.isfile(data_file):
        print '\n\nduplicate file detected - removing...'
        cmd = 'rm %s' %data_file
        print '%s' %cmd
        os.system(cmd)

      print '\n\ndownloading data_file %s...' %data_file
      cmd = 'wget %s' %url
      print '%s' %cmd
      os.system(cmd)
 
      print '\n\nunzipping file...'
      cmd = 'unzip %s' %data_file
      print '%s' %cmd
      os.system(cmd)

      os.chdir(cwd)

    return dataset_dir







<commit_msg>updated atlas fetcher and nitrc urls<commit_after>
"""
Downloading NeuroImaging datasets: atlas datasets
"""
import os
from nilearn.datasets.utils import _fetch_files

def fetch_conwhat_atlas(atlas_name,dataset_dir,resume=True, verbose=1,
                        uncompress=True,remove_existing=False):
    """Downloads and unpacks ConWhAt atlases

    Parameters
    ----------
    data_dir: string
        directory where data should be downloaded and unpacked.

    atlas_name: string
        name of atlas to download

    resume: bool
        whether to resumed download of a partly-downloaded file.

    verbose: int
        verbosity level (0 means no message).

    remove_existing: bool
        remove any existing folders in the target location before 
        downloading


    Returns
    -------
    data: folder name for conwhat atlas

    References
    ----------
    Licence: Creative Commons Attribution Non-commercial Share Alike
    http://creativecommons.org/licenses/by-nc-sa/2.5/

    <NAME>., & <NAME>. (in preparation)
    "Connectome-based white matter atlases for virtual lesion studies"

    """


    if not os.path.isdir(dataset_dir):
      print 'dataset dir not present. creating'
      os.makedirs(dataset_dir)

    if atlas_name == 'CWL2k8Sc33Vol3d100s_v01':
        url = "https://www.nitrc.org/frs/download.php/10381/CWL2k8Sc33Vol3d100s_v01.zip"
    elif atlas_name == 'CWL2k8Sc60Vol3d100s_v01':
        url = "https://www.nitrc.org/frs/download.php/10382/CWL2k8Sc60Vol3d100s_v01.zip"
    else: 
        raise NameError('requested atlas not recognized')

    atlas_dir = '%s/%s' %(dataset_dir,atlas_name)

    if os.path.isdir(atlas_dir):

      if remove_existing == True:
 
        print 'removing existing folder'
        os.system('rm -r %s' %atlas_dir)

      else: 

        raise NameError('output folder already present. aborting.')
     
    cwd = os.getcwd()
    os.chdir(dataset_dir) 
    data_file = url.split('/')[-1]
      
    if os.path.isfile(data_file):
      if remove_existing==True:
        print '\n\nduplicate file detected - removing...'
        cmd = 'rm %s' %data_file
        print '%s' %cmd
        os.system(cmd)

    print '\n\ndownloading data_file %s...' %data_file
    cmd = 'wget %s' %url
    print '%s' %cmd
    os.system(cmd)
 
    print '\n\nunzipping file...'
    cmd = 'unzip %s' %data_file
    print '%s' %cmd
    os.system(cmd)
    print '\n\nfinished unzipping.'

    os.chdir(cwd)

    return dataset_dir








{'fraction_non_alphanumeric': 0.11692100538599641, 'fraction_numerical': 0.018177737881508078, 'mean_word_length': 2.384206529992407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2727381', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1434, 'n_words': 360}