Repository navigation
Expand file tree
/
Copy pathdownload.py
More file actions
90 lines (66 loc) · 2.36 KB
/
Copy pathdownload.py
File metadata and controls
90 lines (66 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Functions and utilities for downloading example data for fooof."""
import os
from urllib.request import urlretrieve
import numpy as np
###################################################################################################
###################################################################################################
DATA_URL = 'https://raw.githubusercontent.com/fooof-tools/fooof/main/data/'
def check_data_folder(folder):
"""Check if a data folder exists, and create if not.
Parameters
----------
folder : str
Name of the folder to check and create if missing.
"""
if folder and not os.path.isdir(folder):
os.mkdir(folder)
def check_data_file(filename, folder, url=DATA_URL):
"""Check if a data folder exists, and download it if not.
Parameters
----------
filename : str
Name of the data file to check and download if missing.
folder : str
Name of the folder to save the datafile to.
"""
filepath = os.path.join(folder, filename)
if not os.path.isfile(filepath):
urlretrieve(url + filename, filename=filepath)
def fetch_fooof_data(filename, folder='data', url=DATA_URL):
"""Download a data file for FOOOF.
Parameters
----------
filename : str
Name of the data file to download.
folder : str, optional
Name of the folder to save the datafile to.
url : str, optional
The URL to download the data file from.
Notes
-----
This function checks if the file already exists, and downloads it if not.
To download the file into the local folder, set folder to an empty string ('').
"""
check_data_folder(folder)
check_data_file(filename, folder, url)
def load_fooof_data(filename, folder='data', url=DATA_URL):
"""Download, if not already available, and load an example data file for fooof.
Parameters
----------
filename : str
Name of the data file to download.
folder : str, optional
Name of the folder to save the datafile to.
url : str, optional
The URL to download the data file from.
Returns
-------
data : ndarray
Loaded data file.
Notes
-----
This function assumes that data files are numpy (npy) files.
"""
fetch_fooof_data(filename, folder, url)
data = np.load(os.path.join(folder, filename))
return data