Skip to content

Commit e249ab5

Browse files
committed
save out test plots
1 parent 5a219df commit e249ab5

File tree

9 files changed

+57
-27
lines changed

9 files changed

+57
-27
lines changed

fooof/tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from fooof.core.modutils import safe_import
1010

1111
from fooof.tests.tutils import get_tfm, get_tfg, get_tbands
12-
from fooof.tests.settings import BASE_TEST_FILE_PATH, TEST_DATA_PATH, TEST_REPORTS_PATH
12+
from fooof.tests.settings import (BASE_TEST_FILE_PATH, TEST_DATA_PATH,
13+
TEST_REPORTS_PATH, TEST_PLOTS_PATH)
1314

1415
plt = safe_import('.pyplot', 'matplotlib')
1516

@@ -33,6 +34,7 @@ def check_dir():
3334
os.mkdir(BASE_TEST_FILE_PATH)
3435
os.mkdir(TEST_DATA_PATH)
3536
os.mkdir(TEST_REPORTS_PATH)
37+
os.mkdir(TEST_PLOTS_PATH)
3638

3739
@pytest.fixture(scope='session')
3840
def tfm():

fooof/tests/plts/test_annotate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44

55
from fooof.tests.tutils import plot_test
6+
from fooof.tests.settings import TEST_PLOTS_PATH
67

78
from fooof.plts.annotate import *
89

@@ -12,11 +13,13 @@
1213
@plot_test
1314
def test_plot_annotated_peak_search(tfm, skip_if_no_mpl):
1415

15-
plot_annotated_peak_search(tfm)
16+
plot_annotated_peak_search(tfm, save_fig=True, file_path=TEST_PLOTS_PATH,
17+
file_name='test_plot_annotated_peak_search.png')
1618

1719
@plot_test
1820
def test_plot_annotated_model(tfm, skip_if_no_mpl):
1921

2022
# Make sure model has been fit & then plot annotated model
2123
tfm.fit()
22-
plot_annotated_model(tfm)
24+
plot_annotated_model(tfm, save_fig=True, file_path=TEST_PLOTS_PATH,
25+
file_name='test_plot_annotated_model.png')

fooof/tests/plts/test_aperiodic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44

55
from fooof.tests.tutils import plot_test
6+
from fooof.tests.settings import TEST_PLOTS_PATH
67

78
from fooof.plts.aperiodic import *
89

@@ -21,7 +22,8 @@ def test_plot_aperiodic_params(skip_if_no_mpl):
2122

2223
# Test for 'knee' mode: offset, knee exponent
2324
aps = np.array([[1, 100, 1], [0.5, 150, 0.5], [2, 200, 2]])
24-
plot_aperiodic_params(aps)
25+
plot_aperiodic_params(aps, save_fig=True, file_path=TEST_PLOTS_PATH,
26+
file_name='test_plot_aperiodic_params.png')
2527

2628
@plot_test
2729
def test_plot_aperiodic_fits(skip_if_no_mpl):
@@ -36,4 +38,5 @@ def test_plot_aperiodic_fits(skip_if_no_mpl):
3638

3739
# Test for 'knee' mode: offset, knee exponent
3840
aps = np.array([[1, 100, 1], [0.5, 150, 0.5], [2, 200, 2]])
39-
plot_aperiodic_fits(aps, [1, 50])
41+
plot_aperiodic_fits(aps, [1, 50], save_fig=True, file_path=TEST_PLOTS_PATH,
42+
file_name='test_plot_aperiodic_fits.png')

fooof/tests/plts/test_error.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44

55
from fooof.tests.tutils import plot_test
6+
from fooof.tests.settings import TEST_PLOTS_PATH
67

78
from fooof.plts.error import *
89

@@ -15,4 +16,5 @@ def test_plot_spectral_error(skip_if_no_mpl):
1516
fs = np.arange(3, 41, 1)
1617
errs = np.ones(len(fs))
1718

18-
plot_spectral_error(fs, errs)
19+
plot_spectral_error(fs, errs, save_fig=True, file_path=TEST_PLOTS_PATH,
20+
file_name='test_plot_spectral_error.png')

fooof/tests/plts/test_fg.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from fooof.core.errors import NoModelError
77

88
from fooof.tests.tutils import plot_test
9+
from fooof.tests.settings import TEST_PLOTS_PATH
910

1011
from fooof.plts.fg import *
1112

@@ -15,7 +16,8 @@
1516
@plot_test
1617
def test_plot_fg(tfg, skip_if_no_mpl):
1718

18-
plot_fg(tfg)
19+
plot_fg(tfg, save_fig=True, file_path=TEST_PLOTS_PATH,
20+
file_name='test_plot_fg.png')
1921

2022
# Test error if no data available to plot
2123
tfg = FOOOFGroup()
@@ -25,14 +27,17 @@ def test_plot_fg(tfg, skip_if_no_mpl):
2527
@plot_test
2628
def test_plot_fg_ap(tfg, skip_if_no_mpl):
2729

28-
plot_fg_ap(tfg)
30+
plot_fg_ap(tfg, save_fig=True, file_path=TEST_PLOTS_PATH,
31+
file_name='test_plot_fg_ap.png')
2932

3033
@plot_test
3134
def test_plot_fg_gf(tfg, skip_if_no_mpl):
3235

33-
plot_fg_gf(tfg)
36+
plot_fg_gf(tfg, save_fig=True, file_path=TEST_PLOTS_PATH,
37+
file_name='test_plot_fg_gf.png')
3438

3539
@plot_test
3640
def test_plot_fg_peak_cens(tfg, skip_if_no_mpl):
3741

38-
plot_fg_peak_cens(tfg)
42+
plot_fg_peak_cens(tfg, save_fig=True, file_path=TEST_PLOTS_PATH,
43+
file_name='test_plot_fg_peak_cens.png')

fooof/tests/plts/test_fm.py

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

33
from fooof.tests.tutils import plot_test
4+
from fooof.tests.settings import TEST_PLOTS_PATH
45

56
from fooof.plts.fm import *
67

@@ -13,7 +14,8 @@ def test_plot_fm(tfm, skip_if_no_mpl):
1314
# Make sure model has been fit
1415
tfm.fit()
1516

16-
plot_fm(tfm)
17+
plot_fm(tfm, save_fig=True, file_path=TEST_PLOTS_PATH,
18+
file_name='test_plot_fm.png')
1719

1820
@plot_test
1921
def test_plot_fm_add_peaks(tfm, skip_if_no_mpl):
@@ -22,9 +24,7 @@ def test_plot_fm_add_peaks(tfm, skip_if_no_mpl):
2224
tfm.fit()
2325

2426
# Test run each of the add peak approaches
25-
for add_peak in ['shade', 'dot', 'outline', 'line']:
26-
plot_fm(tfm, plot_peaks=add_peak)
27-
28-
# Test run some combinations
29-
for add_peak in ['shade-dot', 'outline-line']:
30-
plot_fm(tfm, plot_peaks=add_peak)
27+
for add_peak in ['shade', 'dot', 'outline', 'line', 'shade-dot', 'outline-line']:
28+
file_name = 'test_plot_fm_add_peaks_' + add_peak + '.png'
29+
plot_fm(tfm, plot_peaks=add_peak, save_fig=True,
30+
file_path=TEST_PLOTS_PATH, file_name=file_name)

fooof/tests/plts/test_periodic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44

55
from fooof.tests.tutils import plot_test
6+
from fooof.tests.settings import TEST_PLOTS_PATH
67

78
from fooof.plts.periodic import *
89

@@ -18,7 +19,8 @@ def test_plot_peak_params(skip_if_no_mpl):
1819
plot_peak_params(peaks)
1920

2021
# Test with multiple set of params
21-
plot_peak_params([peaks, peaks])
22+
plot_peak_params([peaks, peaks], save_fig=True, file_path=TEST_PLOTS_PATH,
23+
file_name='test_plot_peak_params.png')
2224

2325
@plot_test
2426
def test_plot_peak_fits(skip_if_no_mpl):
@@ -29,4 +31,5 @@ def test_plot_peak_fits(skip_if_no_mpl):
2931
plot_peak_fits(peaks)
3032

3133
# Test with multiple set of params
32-
plot_peak_fits([peaks, peaks])
34+
plot_peak_fits([peaks, peaks], save_fig=True, file_path=TEST_PLOTS_PATH,
35+
file_name='test_plot_peak_fits.png')

fooof/tests/plts/test_spectra.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44

55
from fooof.tests.tutils import plot_test
6+
from fooof.tests.settings import TEST_PLOTS_PATH
67

78
from fooof.plts.spectra import *
89

@@ -15,36 +16,46 @@ def test_plot_spectrum(tfm, skip_if_no_mpl):
1516
plot_spectrum(tfm.freqs, tfm.power_spectrum)
1617

1718
# Test with logging both axes
18-
plot_spectrum(tfm.freqs, tfm.power_spectrum, True, True)
19+
plot_spectrum(tfm.freqs, tfm.power_spectrum, True, True, save_fig=True,
20+
file_path=TEST_PLOTS_PATH, file_name='test_plot_spectrum.png')
1921

2022
@plot_test
2123
def test_plot_spectra(tfg, skip_if_no_mpl):
2224

2325
# Test with 1d inputs - 1d freq array and list of 1d power spectra
24-
plot_spectra(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]])
26+
plot_spectra(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]],
27+
save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_spectra_1d.png')
2528

2629
# Test with multiple freq inputs - list of 1d freq array and list of 1d power spectra
27-
plot_spectra([tfg.freqs, tfg.freqs], [tfg.power_spectra[0, :], tfg.power_spectra[1, :]])
30+
plot_spectra([tfg.freqs, tfg.freqs], [tfg.power_spectra[0, :], tfg.power_spectra[1, :]],
31+
save_fig=True, file_path=TEST_PLOTS_PATH,
32+
file_name='test_plot_spectra_list_of_1d.png')
2833

2934
# Test with 2d array inputs
3035
plot_spectra(np.vstack([tfg.freqs, tfg.freqs]),
31-
np.vstack([tfg.power_spectra[0, :], tfg.power_spectra[1, :]]))
36+
np.vstack([tfg.power_spectra[0, :], tfg.power_spectra[1, :]]),
37+
save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_spectra_2d.png')
3238

3339
# Test with labels
34-
plot_spectra(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]], labels=['A', 'B'])
40+
plot_spectra(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]], labels=['A', 'B'],
41+
save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_spectra_labels.png')
3542

3643
@plot_test
3744
def test_plot_spectrum_shading(tfm, skip_if_no_mpl):
3845

39-
plot_spectrum_shading(tfm.freqs, tfm.power_spectrum, shades=[8, 12], add_center=True)
46+
plot_spectrum_shading(tfm.freqs, tfm.power_spectrum, shades=[8, 12], add_center=True,
47+
save_fig=True, file_path=TEST_PLOTS_PATH,
48+
file_name='test_plot_spectrum_shading.png')
4049

4150
@plot_test
4251
def test_plot_spectra_shading(tfg, skip_if_no_mpl):
4352

4453
plot_spectra_shading(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]],
45-
shades=[8, 12], add_center=True)
54+
shades=[8, 12], add_center=True, save_fig=True, file_path=TEST_PLOTS_PATH,
55+
file_name='test_plot_spectra_shading.png')
4656

4757
# Test with **kwargs that pass into plot_spectra
4858
plot_spectra_shading(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]],
4959
shades=[8, 12], add_center=True, log_freqs=True, log_powers=True,
50-
labels=['A', 'B'])
60+
labels=['A', 'B'], save_fig=True, file_path=TEST_PLOTS_PATH,
61+
file_name='test_plot_spectra_shading_kwargs.png')

fooof/tests/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
BASE_TEST_FILE_PATH = pkg.resource_filename(__name__, 'test_files')
1111
TEST_DATA_PATH = os.path.join(BASE_TEST_FILE_PATH, 'data')
1212
TEST_REPORTS_PATH = os.path.join(BASE_TEST_FILE_PATH, 'reports')
13+
TEST_PLOTS_PATH = os.path.join(BASE_TEST_FILE_PATH, 'plots')

0 commit comments

Comments
 (0)