def data_path(subject, path=None, force_update=False, fnirs=False): """Get path to local copy of bbci_eeg_fnirs dataset URL. Parameters ---------- subject : int Number of subject to use path : None | str Location of where to look for the data storing location. If None, the environment variable or config parameter ``MNE_DATASETS_BBCIFNIRS_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. 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 if subject < 1 or subject > 30: raise ValueError( "Valid subjects between 1 and 30, subject {:d} requested".format(subject)) key = 'MNE_DATASETS_BBCIFNIRS_PATH' path = _get_path(path, key, 'BBCI EEG-fNIRS') _do_path_update(path, None, key, 'BBCI EEG-fNIRS') if not op.isdir(op.join(path, 'MNE-eegfnirs-data')): os.makedirs(op.join(path, 'MNE-eegfnirs-data')) if fnirs: return fnirs_data_path(op.join(path, 'MNE-eegfnirs-data'), subject) else: return eeg_data_path(op.join(path, 'MNE-eegfnirs-data'), subject)
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(self, subject, path=None, force_update=False, update_path=None, verbose=None): if subject not in self.subject_list: raise(ValueError("Invalid subject number")) key = 'MNE_DATASETS_ZHOU2016_PATH' path = _get_path(path, key, "Zhou 2016") _do_path_update(path, True, key, "Zhou 2016") basepath = os.path.join(path, "MNE-zhou-2016") if not os.path.isdir(basepath): os.makedirs(basepath) return local_data_path(basepath, subject)
def data_path( self, subject, path=None, force_update=False, update_path=None, verbose=None ): if subject not in self.subject_list: raise (ValueError("Invalid subject number")) key = "MNE_DATASETS_WEIBO2014_PATH" path = _get_path(path, key, "Weibo 2014") _do_path_update(path, True, key, "Weibo 2014") basepath = os.path.join(path, "MNE-weibo-2014") if not os.path.isdir(basepath): os.makedirs(basepath) return eeg_data_path(basepath, subject)
def mne_data_path(url: str, sign: str, path: Union[str, Path] = None, proxies: Optional[Dict[str, str]] = None, force_update: bool = False, update_path: bool = True, verbose: Optional[Union[bool, str, int]] = None) -> str: """Get the local path of the target file. This function returns the local path of the target file, downloading it if needed or requested. The local path keeps the same structure as the url. Parameters ---------- url : str url of the target file. sign : str the unique identifier to which the file belongs path : Union[str, Path], optional local folder to save the file, by default None proxies : Optional[Dict[str, str]], optional use proxies to download files, e.g. {'https': 'socks5://127.0.0.1:1080'}, by default None force_update : bool, optional whether to re-download the file, by default False update_path : bool, optional whether to update mne config, by default True verbose : Optional[Union[bool, str, int]], optional [description], by default None Returns ------- str local path of the target file """ sign = sign.upper() key = 'MNE_DATASETS_{:s}_PATH'.format(sign) key_dest = 'MNE-{:s}-data'.format(sign.lower()) path = _get_path(path, key, sign) destination = _url_to_local_path(url, os.path.join(path, key_dest)) # Fetch the file if not os.path.exists(destination) or force_update: if not os.path.isdir(os.path.dirname(destination)): os.makedirs(os.path.dirname(destination)) if os.path.isfile(destination): os.remove(destination) _fetch_file(url, destination, proxies=proxies) _do_path_update(path, update_path, key, sign) return destination
def data_path(self, subject, path=None, force_update=False, update_path=None, verbose=None): if subject not in self.subject_list: raise (ValueError("Invalid subject number")) key = 'MNE_DATASETS_BBCIFNIRS_PATH' path = _get_path(path, key, 'BBCI EEG-fNIRS') # FIXME: this always update the path _do_path_update(path, True, key, 'BBCI EEG-fNIRS') if not op.isdir(op.join(path, 'MNE-eegfnirs-data')): os.makedirs(op.join(path, 'MNE-eegfnirs-data')) if self.fnirs: return fnirs_data_path(op.join(path, 'MNE-eegfnirs-data'), subject) else: return eeg_data_path(op.join(path, 'MNE-eegfnirs-data'), subject)