def get_data(filename, subset, url):
    """Get a dataset with from a url with local caching.

    Parameters
    ----------
    filename : str
        Name of the file, for caching.
    subset : str
        To what subset the file belongs (e.g. 'ray_transform'). Each subset
        is saved in a separate subfolder.
    url : str
        url to the dataset online.

    Returns
    -------
    dataset : dict
        Dictionary containing the dataset.
    """
    # check if this data set has been already downloaded
    data_dir = join(get_data_dir(), subset)
    if not exists(data_dir):
        os.makedirs(data_dir)

    filename = join(data_dir, filename)

    # if the file does not exist, download it
    if not exists(filename):
        print('data {}/{} not in local storage, downloading from {}'
              ''.format(subset, filename, url))

        # open the url of the data
        with contextlib.closing(urlopen(url)) as data_url:
            # store downloaded file locally
            with open(filename, 'w+b') as storage_file:
                copyfileobj(data_url, storage_file)

    # load dataset file
    with open(filename, 'rb') as storage_file:
        data_dict = io.loadmat(storage_file)

    return data_dict
def get_data ( filename , subset , url ) : data_dir = join ( get_data_dir ( ) , subset ) if not exists ( data_dir ) : os . makedirs ( data_dir ) filename = join ( data_dir , filename ) if not exists ( filename ) : print ( 'data {}/{} not in local storage, downloading from {}' '' . format ( subset , filename , url ) ) with contextlib . closing ( urlopen ( url ) ) as data_url : with open ( filename , 'w+b' ) as storage_file : copyfileobj ( data_url , storage_file ) with open ( filename , 'rb' ) as storage_file : data_dict = io . loadmat ( storage_file ) return data_dict
Get a dataset with from a url with local caching.

    Parameters
    ----------
    filename : str
        Name of the file, for caching.
    subset : str
        To what subset the file belongs (e.g. 'ray_transform'). Each subset
        is saved in a separate subfolder.
    url : str
        url to the dataset online.

    Returns
    -------
    dataset : dict
        Dictionary containing the dataset.