Skip to content

Commit 643d61e

Browse files
authored
Merge pull request #285 from fooof-tools/paths
[MNT] - Update for Path support
2 parents 172101a + 6519d21 commit 643d61e

File tree

10 files changed

+27
-20
lines changed

10 files changed

+27
-20
lines changed

fooof/core/io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def fpath(file_path, file_name):
3838
3939
Parameters
4040
----------
41-
file_path : str or None
41+
file_path : Path or str or None
4242
Path to the directory where the file is located.
4343
file_name : str
4444
Name of the file.
@@ -71,7 +71,7 @@ def save_fm(fm, file_name, file_path=None, append=False,
7171
Object to save data from.
7272
file_name : str or FileObject
7373
File to save data to.
74-
file_path : str, optional
74+
file_path : Path or str, optional
7575
Path to directory to save to. If None, saves to current directory.
7676
append : bool, optional, default: False
7777
Whether to append to an existing file, if available.
@@ -129,7 +129,7 @@ def save_fg(fg, file_name, file_path=None, append=False,
129129
Object to save data from.
130130
file_name : str or FileObject
131131
File to save data to.
132-
file_path : str, optional
132+
file_path : Path or str, optional
133133
Path to directory to load from. If None, loads from current directory.
134134
append : bool, optional, default: False
135135
Whether to append to an existing file, if available.
@@ -175,7 +175,7 @@ def load_json(file_name, file_path):
175175
----------
176176
file_name : str or FileObject
177177
File to load data from.
178-
file_path : str
178+
file_path : Path or str
179179
Path to directory to load from.
180180
181181
Returns
@@ -204,7 +204,7 @@ def load_jsonlines(file_name, file_path):
204204
----------
205205
file_name : str
206206
File to load data from.
207-
file_path : str
207+
file_path : Path or str
208208
Path to directory from load from.
209209
210210
Yields

fooof/core/reports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def save_report_fm(fm, file_name, file_path=None, plt_log=False, add_settings=Tr
3131
Object with results from fitting a power spectrum.
3232
file_name : str
3333
Name to give the saved out file.
34-
file_path : str, optional
34+
file_path : Path or str, optional
3535
Path to directory to save to. If None, saves to current directory.
3636
plt_log : bool, optional, default: False
3737
Whether or not to plot the frequency axis in log space.
@@ -83,7 +83,7 @@ def save_report_fg(fg, file_name, file_path=None, add_settings=True):
8383
Object with results from fitting a group of power spectra.
8484
file_name : str
8585
Name to give the saved out file.
86-
file_path : str, optional
86+
file_path : Path or str, optional
8787
Path to directory to save to. If None, saves to current directory.
8888
add_settings : bool, optional, default: True
8989
Whether to add a print out of the model settings to the end of the report.

fooof/objs/fit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def load(self, file_name, file_path=None, regenerate=True):
671671
----------
672672
file_name : str or FileObject
673673
File to load data from.
674-
file_path : str or None, optional
674+
file_path : Path or str, optional
675675
Path to directory to load from. If None, loads from current directory.
676676
regenerate : bool, optional, default: True
677677
Whether to regenerate the model fit from the loaded data, if data is available.

fooof/objs/group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def load(self, file_name, file_path=None):
403403
----------
404404
file_name : str
405405
File to load data from.
406-
file_path : str, optional
406+
file_path : Path or str, optional
407407
Path to directory to load from. If None, loads from current directory.
408408
"""
409409

@@ -533,7 +533,7 @@ def save_model_report(self, index, file_name, file_path=None, plt_log=False,
533533
Index of the model fit to save out.
534534
file_name : str
535535
Name to give the saved out file.
536-
file_path : str, optional
536+
file_path : Path or str, optional
537537
Path to directory to save to. If None, saves to current directory.
538538
plt_log : bool, optional, default: False
539539
Whether or not to plot the frequency axis in log space.

fooof/plts/fg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def plot_fg(fg, save_fig=False, file_name=None, file_path=None, **plot_kwargs):
3131
Whether to save out a copy of the plot.
3232
file_name : str, optional
3333
Name to give the saved out file.
34-
file_path : str, optional
34+
file_path : Path or str, optional
3535
Path to directory to save to. If None, saves to current directory.
3636
3737
Raises

fooof/plts/fm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def plot_fm(fm, plot_peaks=None, plot_aperiodic=True, plt_log=False, add_legend=
4747
Whether to save out a copy of the plot.
4848
file_name : str, optional
4949
Name to give the saved out file.
50-
file_path : str, optional
50+
file_path : Path or str, optional
5151
Path to directory to save to. If None, saves to current directory.
5252
ax : matplotlib.Axes, optional
5353
Figure axes upon which to plot.

fooof/plts/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def save_figure(file_name, file_path=None, close=False, **save_kwargs):
211211
----------
212212
file_name : str
213213
File name for the figure file to save out.
214-
file_path : str or Path
214+
file_path : Path or str
215215
Path for where to save out the figure to.
216216
close : bool, optional, default: False
217217
Whether to close the plot after saving.

fooof/tests/core/test_io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for fooof.core.io."""
22

33
import os
4+
from pathlib import Path
45

56
from fooof.core.items import OBJ_DESC
67

@@ -26,6 +27,7 @@ def test_fpath():
2627

2728
assert fpath(None, 'data.json') == 'data.json'
2829
assert fpath('/path/', 'data.json') == '/path/data.json'
30+
assert fpath(Path('/path/'), 'data.json') == '/path/data.json'
2931

3032
def test_save_fm_str(tfm):
3133
"""Check saving fm data, with file specifiers as strings."""

fooof/utils/download.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""Functions and utilities for downloading example data for fooof."""
22

33
import os
4+
from pathlib import Path
45
from urllib.request import urlretrieve
56

67
import numpy as np
78

9+
from fooof.core.io import fpath
10+
811
###################################################################################################
912
###################################################################################################
1013

@@ -15,7 +18,7 @@ def check_data_folder(folder):
1518
1619
Parameters
1720
----------
18-
folder : str
21+
folder : Path or str
1922
Name of the folder to check and create if missing.
2023
"""
2124

@@ -30,11 +33,13 @@ def check_data_file(filename, folder, url=DATA_URL):
3033
----------
3134
filename : str
3235
Name of the data file to check and download if missing.
33-
folder : str
36+
folder : Path or str
3437
Name of the folder to save the datafile to.
38+
url : str, optional
39+
The URL to download the data file from.
3540
"""
3641

37-
filepath = os.path.join(folder, filename)
42+
filepath = fpath(folder, filename)
3843

3944
if not os.path.isfile(filepath):
4045
urlretrieve(url + filename, filename=filepath)
@@ -47,7 +52,7 @@ def fetch_fooof_data(filename, folder='data', url=DATA_URL):
4752
----------
4853
filename : str
4954
Name of the data file to download.
50-
folder : str, optional
55+
folder : Path or str, optional
5156
Name of the folder to save the datafile to.
5257
url : str, optional
5358
The URL to download the data file from.
@@ -69,7 +74,7 @@ def load_fooof_data(filename, folder='data', url=DATA_URL):
6974
----------
7075
filename : str
7176
Name of the data file to download.
72-
folder : str, optional
77+
folder : Path or str, optional
7378
Name of the folder to save the datafile to.
7479
url : str, optional
7580
The URL to download the data file from.

fooof/utils/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def load_fooof(file_name, file_path=None, regenerate=True):
1010
----------
1111
file_name : str or FileObject
1212
File to load the data from.
13-
file_path : str or None, optional
13+
file_path : Path or str, optional
1414
Path to directory to load from. If None, loads from current directory.
1515
regenerate : bool, optional, default: True
1616
Whether to regenerate the model fit from the loaded data, if data is available.
@@ -38,7 +38,7 @@ def load_fooofgroup(file_name, file_path=None):
3838
----------
3939
file_name : str
4040
File to load data data.
41-
file_path : str, optional
41+
file_path : Path or str, optional
4242
Path to directory to load from. If None, loads from current directory.
4343
4444
Returns

0 commit comments

Comments
 (0)