def data_dl(url, sign, path=None, force_update=False, update_path=True, verbose=None): """Download file from url to specified path This function should replace data_path as the MNE will not support the download of dataset anymore. This version is using Pooch. Parameters ---------- url : str Path to remote location of data sign : str Signifier of dataset path : None | str Location of where to look for the BNCI data storing location. If None, the environment variable or config parameter ``MNE_DATASETS_(signifier)_PATH`` is used. If it doesn't exist, the "~/mne_data" directory is used. If the dataset is not found under the given path, the data will be automatically downloaded to the specified folder. force_update : bool Force update of the dataset even if a local copy exists. update_path : bool | None If True, set the MNE_DATASETS_(signifier)_PATH in mne-python config to the given path. If None, the user is prompted. verbose : bool, str, int, or None If not None, override default verbose level (see :func:`mne.verbose`). Returns ------- path : list of str Local path to the given data file. This path is contained inside a list of length one, for compatibility. """ sign = sign.upper() key = "MNE_DATASETS_{:s}_PATH".format(sign) key_dest = "MNE-{:s}-data".format(sign.lower()) if get_config(key) is None: set_config(key, osp.join(osp.expanduser("~"), "mne_data")) path = _get_path(path, key, sign) destination = _url_to_local_path(url, osp.join(path, key_dest)) # Fetch the file if not osp.isfile(destination) or force_update: if osp.isfile(destination): os.remove(destination) if not osp.isdir(osp.dirname(destination)): os.makedirs(osp.dirname(destination)) known_hash = None else: known_hash = file_hash(destination) dlpath = retrieve( url, known_hash, fname=osp.basename(url), path=osp.dirname(destination) ) # Offer to update the path if update_path: _do_path_update(path, update_path, key, sign) return dlpath
def data_path(url, sign, path=None, force_update=False, update_path=True, verbose=None): """Get path to local copy of given dataset URL. This is a low-level function useful for getting a local copy of a remote dataset Parameters ---------- url : str Path to remote location of data sign : str Signifier of dataset path : None | str Location of where to look for the BNCI data storing location. If None, the environment variable or config parameter ``MNE_DATASETS_(signifier)_PATH`` is used. If it doesn't exist, the "~/mne_data" directory is used. If the dataset is not found under the given path, the data will be automatically downloaded to the specified folder. force_update : bool Force update of the dataset even if a local copy exists. update_path : bool | None If True, set the MNE_DATASETS_(signifier)_PATH in mne-python config to the given path. If None, the user is prompted. verbose : bool, str, int, or None If not None, override default verbose level (see :func:`mne.verbose`). Returns ------- path : list of str Local path to the given data file. This path is contained inside a list of length one, for compatibility. """ # noqa: E501 sign = sign.upper() key = 'MNE_DATASETS_{:s}_PATH'.format(sign) key_dest = 'MNE-{:s}-data'.format(sign.lower()) if get_config(key) is None: set_config(key, osp.join(osp.expanduser("~"), "mne_data")) path = _get_path(path, key, sign) destination = _url_to_local_path(url, op.join(path, key_dest)) # Fetch the file if not op.isfile(destination) or force_update: if op.isfile(destination): os.remove(destination) if not op.isdir(op.dirname(destination)): os.makedirs(op.dirname(destination)) _fetch_file(url, destination, print_destination=False) # Offer to update the path _do_path_update(path, update_path, key, sign) return destination
def data_path(url, sign, path=None, force_update=False, update_path=True, verbose=None): """Get path to local copy of given dataset URL. **Deprecated** This is a low-level function useful for getting a local copy of a remote dataset. It is deprecated in favor of data_dl. Parameters ---------- url : str Path to remote location of data sign : str Signifier of dataset path : None | str Location of where to look for the data storing location. If None, the environment variable or config parameter ``MNE_DATASETS_(signifier)_PATH`` is used. If it doesn't exist, the "~/mne_data" directory is used. If the dataset is not found under the given path, the data will be automatically downloaded to the specified folder. force_update : bool Force update of the dataset even if a local copy exists. update_path : bool | None, **Deprecated** Unused, kept for compatibility purpose. verbose : bool, str, int, or None If not None, override default verbose level (see :func:`mne.verbose`). Returns ------- path : list of str Local path to the given data file. This path is contained inside a list of length one, for compatibility. """ # noqa: E501 path = get_dataset_path(sign, path) key_dest = "MNE-{:s}-data".format(sign.lower()) destination = _url_to_local_path(url, osp.join(path, key_dest)) # Fetch the file if not osp.isfile(destination) or force_update: if osp.isfile(destination): os.remove(destination) if not osp.isdir(osp.dirname(destination)): os.makedirs(osp.dirname(destination)) retrieve(url, None, path=destination) return destination
def download_sample_data(dataset="ssvep", subject=1, session=1): """Download BCI data for example purpose Parameters ---------- dataset : str type of the dataset, could be "ssvep", "p300" or "imagery" Default is "ssvep", as other are not implemented subject : int Subject id, dataset specific (default: 1) session : int, default 1 Session number%load , dataset specific (default: 1) Returns ------- destination : str Path to downloaded data """ if dataset == "ssvep": DATASET_URL = 'https://zenodo.org/record/2392979/files/' url = '{:s}subject{:02d}_run{:d}_raw.fif'.format(DATASET_URL, subject, session + 1) sign = 'SSVEPEXO' key, key_dest = 'MNE_DATASETS_SSVEPEXO_PATH', 'MNE-ssvepexo-data' elif dataset == "p300" or dataset == "imagery": raise NotImplementedError("Not yet implemented") # Use MNE _fetch_file to download EEG file if get_config(key) is None: set_config(key, os.path.join(os.path.expanduser("~"), "mne_data")) # Adquire local de dados do MNE path = _get_path(None, key, sign) # Baixa o que está no URL para pasta local, que é criada no segundo parametro destination = _url_to_local_path(url, os.path.join(path, key_dest)) # Cria pasta com todo caminho pro arquivo os.makedirs(os.path.dirname(destination), exist_ok=True) if not os.path.exists(destination): _fetch_file(url, destination, print_destination=False) return destination
def test_url_to_local_path(): """Test URL to local path """ assert_equal(_url_to_local_path('http://google.com/home/why.html', '.'), op.join('.', 'home', 'why.html'))
def test_url_to_local_path(): """Test URL to local path.""" assert_equal(_url_to_local_path('http://google.com/home/why.html', '.'), op.join('.', 'home', 'why.html'))
def test_url_to_local_path(): """Test URL to local path """ assert_equal(_url_to_local_path("http://google.com/home/why.html", "."), op.join(".", "home", "why.html"))