pulse2percept.datasets.base
get_data_dir,
clear_data_dir,
has_network,
osf_is_reachable,
download_from_osf,
fetch_url
Functions
|
Delete all content in the data directory |
|
Download a file from OSF into the data directory (once) |
|
Download a remote file |
|
Return the path of the pulse2percept data directory |
|
Check for general network connectivity |
|
Check whether OSF downloads are reachable |
- pulse2percept.datasets.base.get_data_dir(data_dir=None)[source]
Return the path of the pulse2percept data directory
This directory is used to store the datasets retrieved by the data fetch utility functions to avoid downloading the data several times.
By default, this is set to a directory called ‘pulse2percept_data’ in the user home directory. Alternatively, it can be set by a
PULSE2PERCEPT_DATAenvironment variable or set programmatically by specifying a path.If the directory does not already exist, it is automatically created.
Added in version 0.6.
- Parameters:
data_dir (str or None) – The path to the pulse2percept data directory.
- pulse2percept.datasets.base.clear_data_dir(data_dir=None)[source]
Delete all content in the data directory
By default, this is set to a directory called ‘pulse2percept_data’ in the user home directory. Alternatively, it can be set by a
PULSE2PERCEPT_DATAenvironment variable or set programmatically by specifying a path.Added in version 0.6.
- Parameters:
data_dir (str or None) – The path to the pulse2percept data directory.
- pulse2percept.datasets.base.has_network(timeout=3.0)[source]
Check for general network connectivity
Attempts TCP connections to a small set of well-known hosts (e.g., DNS and OSF). If any connection succeeds within the timeout, the host is considered online. This is a fast pre-flight check that avoids unnecessary download attempts.
- pulse2percept.datasets.base.fetch_url(url, file_path, progress_bar=<function _report_hook>, remote_checksum=None)[source]
Download a remote file
Fetch a dataset pointed to by
url, check its SHA-256 checksum for integrity, and save it tofile_path.Added in version 0.6.
- Parameters:
url (string) – URL of file to download
file_path (string) – Path to the local file that will be created
progress_bar (func callback, optional) – A callback to a function
func(count, block_size, total_size)that will display a progress bar.remote_checksum (str, optional) – The expected SHA-256 checksum of the file.
- pulse2percept.datasets.base.osf_is_reachable(test_url='https://osf.io/rduj4', timeout=5.0)[source]
Check whether OSF downloads are reachable
Probes OSF by normalizing the given URL or GUID to the direct download form (
https://osf.io/download/<GUID>) and issuing a quick HEAD request. If HEAD is not supported, falls back to fetching a few bytes with GET. No files are written to disk.
- pulse2percept.datasets.base.download_from_osf(osf_id_or_url, filename, checksum=None, data_path=None, download_if_missing=True, progress_bar=<function _report_hook>)[source]
Download a file from OSF into the data directory (once)
Normalizes an OSF GUID or URL to the direct download endpoint (
https://osf.io/download/<GUID>), performs quick pre-flight checks (general network + OSF reachability), and downloads the file viafetch_url(). If the file already exists, it is not downloaded again.- Parameters:
osf_id_or_url (str) – OSF GUID (e.g.,
'pf2ja') or OSF URL (with or without/download).filename (str) – Local filename to save under the data directory (e.g.,
'han2021.zip').checksum (str or None, optional) – Expected SHA-256 hex digest. If provided, integrity is verified.
data_path (str or None, optional) – Custom data directory. Defaults to
get_data_dir().download_if_missing (bool, optional) – If False and the file is missing locally, raises an IOError instead of downloading. Default is True.
progress_bar (callable, optional) – Progress callback with signature
func(count, block_size, total_size). Defaults to_report_hook().
- Returns:
Absolute path to the downloaded (or already present) local file.
- Return type:
- Raises:
IOError – If the file is missing and
download_if_missingis False; if there is no network connectivity; if OSF is unreachable; or if the checksum verification fails.