Skip to content

Commit ee06c6c

Browse files
committed
update to use tdata file
1 parent 7de637f commit ee06c6c

26 files changed

+177
-156
lines changed

specparam/tests/conftest.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
import numpy as np
88

99
from specparam.core.modutils import safe_import
10-
from specparam.tests.tutils import (get_tdata, get_tdata2d, get_tfm, get_tfg, get_tft, get_tfe,
11-
get_tbands, get_tresults, get_tdocstring)
12-
from specparam.tests.settings import (BASE_TEST_FILE_PATH, TEST_DATA_PATH,
13-
TEST_REPORTS_PATH, TEST_PLOTS_PATH)
10+
11+
from specparam.tests.tdata import (get_tdata, get_tdata2d, get_tfm, get_tfg, get_tft, get_tfe,
12+
get_tbands, get_tresults, get_tdocstring)
13+
from specparam.tests.tsettings import (BASE_TEST_FILE_PATH, TEST_DATA_PATH,
14+
TEST_REPORTS_PATH, TEST_PLOTS_PATH)
1415

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

1718
###################################################################################################
1819
###################################################################################################
1920

21+
## TEST SETUP
22+
2023
def pytest_configure(config):
2124
if plt:
2225
plt.switch_backend('agg')
@@ -36,6 +39,20 @@ def check_dir():
3639
os.mkdir(TEST_REPORTS_PATH)
3740
os.mkdir(TEST_PLOTS_PATH)
3841

42+
## DEPENDENCY CHECKS
43+
44+
@pytest.fixture(scope='session')
45+
def skip_if_no_mpl():
46+
if not safe_import('matplotlib'):
47+
pytest.skip('Matplotlib not available: skipping test.')
48+
49+
@pytest.fixture(scope='session')
50+
def skip_if_no_pandas():
51+
if not safe_import('pandas'):
52+
pytest.skip('Pandas not available: skipping test.')
53+
54+
## TEST OBJECTS
55+
3956
@pytest.fixture(scope='session')
4057
def tdata():
4158
yield get_tdata()
@@ -71,13 +88,3 @@ def tresults():
7188
@pytest.fixture(scope='function')
7289
def tdocstring():
7390
yield get_tdocstring()
74-
75-
@pytest.fixture(scope='session')
76-
def skip_if_no_mpl():
77-
if not safe_import('matplotlib'):
78-
pytest.skip('Matplotlib not available: skipping test.')
79-
80-
@pytest.fixture(scope='session')
81-
def skip_if_no_pandas():
82-
if not safe_import('pandas'):
83-
pytest.skip('Pandas not available: skipping test.')

specparam/tests/core/test_io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from specparam.core.items import OBJ_DESC
77

8-
from specparam.tests.settings import TEST_DATA_PATH
8+
from specparam.tests.tsettings import TEST_DATA_PATH
99

1010
from specparam.core.io import *
1111

specparam/tests/core/test_reports.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44

5-
from specparam.tests.settings import TEST_REPORTS_PATH
5+
from specparam.tests.tsettings import TEST_REPORTS_PATH
66

77
from specparam.core.reports import *
88

specparam/tests/objs/test_algorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from specparam.objs.base import BaseObject
44
from specparam.sim import sim_power_spectrum
55

6-
from specparam.tests.tutils import default_spectrum_params
6+
from specparam.tests.tdata import default_spectrum_params
77

88
from specparam.objs.algorithm import *
99

specparam/tests/objs/test_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from specparam.data import SpectrumMetaData
44

5-
from specparam.tests.tutils import get_tdata, plot_test
5+
from specparam.tests.tutils import plot_test
66

77
from specparam.objs.data import *
88

specparam/tests/objs/test_event.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
pd = safe_import('pandas')
1515

16-
from specparam.tests.settings import TEST_DATA_PATH
17-
from specparam.tests.tutils import default_group_params, plot_test
16+
from specparam.tests.tsettings import TEST_DATA_PATH
17+
from specparam.tests.tdata import default_group_params
18+
from specparam.tests.tutils import plot_test
1819

1920
from specparam.objs.event import *
2021

specparam/tests/objs/test_group.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
pd = safe_import('pandas')
2020

21-
from specparam.tests.settings import TEST_DATA_PATH, TEST_REPORTS_PATH
22-
from specparam.tests.tutils import default_group_params, plot_test
21+
from specparam.tests.tsettings import TEST_DATA_PATH, TEST_REPORTS_PATH
22+
from specparam.tests.tdata import default_group_params
23+
from specparam.tests.tutils import plot_test
2324

2425
from specparam.objs.group import *
2526

specparam/tests/objs/test_model.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
pd = safe_import('pandas')
2121

22-
from specparam.tests.settings import TEST_DATA_PATH
23-
from specparam.tests.tutils import default_spectrum_params, get_tfm, plot_test
22+
from specparam.tests.tsettings import TEST_DATA_PATH
23+
from specparam.tests.tdata import default_spectrum_params, get_tfm
24+
from specparam.tests.tutils import plot_test
2425

2526
from specparam.objs.model import *
2627

specparam/tests/objs/test_time.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
pd = safe_import('pandas')
1515

16-
from specparam.tests.settings import TEST_DATA_PATH
17-
from specparam.tests.tutils import default_group_params, plot_test
16+
from specparam.tests.tsettings import TEST_DATA_PATH
17+
from specparam.tests.tdata import default_group_params
18+
from specparam.tests.tutils import plot_test
1819

1920
from specparam.objs.time import *
2021

specparam/tests/objs/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from specparam.sim import sim_group_power_spectra
1010
from specparam.core.errors import NoModelError, IncompatibleSettingsError
1111

12-
from specparam.tests.tutils import default_group_params
12+
from specparam.tests.tdata import default_group_params
1313

1414
from specparam.objs.utils import *
1515

specparam/tests/plts/test_annotate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for specparam.plts.annotate."""
22

33
from specparam.tests.tutils import plot_test
4-
from specparam.tests.settings import TEST_PLOTS_PATH
4+
from specparam.tests.tsettings import TEST_PLOTS_PATH
55

66
from specparam.plts.annotate import *
77

specparam/tests/plts/test_aperiodic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
from specparam.tests.tutils import plot_test
6-
from specparam.tests.settings import TEST_PLOTS_PATH
6+
from specparam.tests.tsettings import TEST_PLOTS_PATH
77

88
from specparam.plts.aperiodic import *
99

specparam/tests/plts/test_error.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
from specparam.tests.tutils import plot_test
6-
from specparam.tests.settings import TEST_PLOTS_PATH
6+
from specparam.tests.tsettings import TEST_PLOTS_PATH
77

88
from specparam.plts.error import *
99

specparam/tests/plts/test_event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from specparam.core.errors import NoModelError
77

88
from specparam.tests.tutils import plot_test
9-
from specparam.tests.settings import TEST_PLOTS_PATH
9+
from specparam.tests.tsettings import TEST_PLOTS_PATH
1010

1111
from specparam.plts.event import *
1212

specparam/tests/plts/test_group.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from specparam.core.errors import NoModelError
77

88
from specparam.tests.tutils import plot_test
9-
from specparam.tests.settings import TEST_PLOTS_PATH
9+
from specparam.tests.tsettings import TEST_PLOTS_PATH
1010

1111
from specparam.plts.group import *
1212

specparam/tests/plts/test_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
from specparam.tests.tutils import plot_test
6-
from specparam.tests.settings import TEST_PLOTS_PATH
6+
from specparam.tests.tsettings import TEST_PLOTS_PATH
77

88
from specparam.plts.model import *
99

specparam/tests/plts/test_periodic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
from specparam.tests.tutils import plot_test
6-
from specparam.tests.settings import TEST_PLOTS_PATH
6+
from specparam.tests.tsettings import TEST_PLOTS_PATH
77

88
from specparam.plts.periodic import *
99

specparam/tests/plts/test_spectra.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
from specparam.tests.tutils import plot_test
8-
from specparam.tests.settings import TEST_PLOTS_PATH
8+
from specparam.tests.tsettings import TEST_PLOTS_PATH
99

1010
from specparam.plts.spectra import *
1111

specparam/tests/plts/test_styles.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for specparam.plts.styles."""
22

33
from specparam.tests.tutils import plot_test
4+
45
from specparam.plts.style import *
56

67
###################################################################################################

specparam/tests/plts/test_time.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from specparam.core.errors import NoModelError
77

88
from specparam.tests.tutils import plot_test
9-
from specparam.tests.settings import TEST_PLOTS_PATH
9+
from specparam.tests.tsettings import TEST_PLOTS_PATH
1010

1111
from specparam.plts.time import *
1212

specparam/tests/plts/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from specparam.core.modutils import safe_import
66

77
from specparam.tests.tutils import plot_test
8-
from specparam.tests.settings import TEST_PLOTS_PATH
8+
from specparam.tests.tsettings import TEST_PLOTS_PATH
99

1010
from specparam.plts.utils import *
1111

specparam/tests/sim/test_sim.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
from numpy import array_equal
55

6-
from specparam.tests.tutils import default_group_params
6+
from specparam.tests.tdata import default_group_params
77

88
from specparam.sim.sim import *
99

specparam/tests/tdata.py

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""Data fot tests."""
2+
3+
import numpy as np
4+
5+
from specparam.bands import Bands
6+
from specparam.data import FitResults
7+
from specparam.objs import (SpectralModel, SpectralGroupModel,
8+
SpectralTimeModel, SpectralTimeEventModel)
9+
from specparam.objs.data import BaseData, BaseData2D
10+
from specparam.sim.params import param_sampler
11+
from specparam.sim.sim import sim_power_spectrum, sim_group_power_spectra, sim_spectrogram
12+
13+
###################################################################################################
14+
###################################################################################################
15+
16+
## PARAMETER DEFINITIONS
17+
18+
def default_spectrum_params():
19+
20+
freq_range = [3, 50]
21+
ap_params = [1, 1]
22+
gaussian_params = [10, 0.5, 2, 20, 0.3, 4]
23+
24+
return freq_range, ap_params, gaussian_params
25+
26+
def default_group_params():
27+
"""Create default parameters for simulating a test group of power spectra."""
28+
29+
freq_range = [3, 50]
30+
ap_opts = param_sampler([[20, 2], [50, 2.5], [35, 1.5]])
31+
gauss_opts = param_sampler([[10, 0.5, 2], [10, 0.5, 2, 20, 0.3, 4]])
32+
33+
return freq_range, ap_opts, gauss_opts
34+
35+
## TEST DATA OBJECTS
36+
37+
def get_tdata():
38+
39+
tdata = BaseData()
40+
tdata.add_data(*sim_power_spectrum(*default_spectrum_params()))
41+
42+
return tdata
43+
44+
def get_tdata2d():
45+
46+
n_spectra = 3
47+
tdata2d = BaseData2D()
48+
tdata2d.add_data(*sim_group_power_spectra(n_spectra, *default_group_params()))
49+
50+
return tdata2d
51+
52+
def get_tfm():
53+
"""Get a model object, with a fit power spectrum, for testing."""
54+
55+
tfm = SpectralModel(verbose=False)
56+
tfm.fit(*sim_power_spectrum(*default_spectrum_params()))
57+
58+
return tfm
59+
60+
def get_tfg():
61+
"""Get a group object, with some fit power spectra, for testing."""
62+
63+
n_spectra = 3
64+
tfg = SpectralGroupModel(verbose=False)
65+
tfg.fit(*sim_group_power_spectra(n_spectra, *default_group_params()))
66+
67+
return tfg
68+
69+
def get_tft():
70+
"""Get a time object, with some fit power spectra, for testing."""
71+
72+
n_spectra = 3
73+
xs, ys = sim_spectrogram(n_spectra, *default_group_params())
74+
75+
bands = Bands({'alpha' : (7, 14)})
76+
tft = SpectralTimeModel(verbose=False)
77+
tft.fit(xs, ys, peak_org=bands)
78+
79+
return tft
80+
81+
def get_tfe():
82+
"""Get an event object, with some fit power spectra, for testing."""
83+
84+
n_spectra = 3
85+
xs, ys = sim_spectrogram(n_spectra, *default_group_params())
86+
ys = [ys, ys]
87+
88+
bands = Bands({'alpha' : (7, 14)})
89+
tfe = SpectralTimeEventModel(verbose=False)
90+
tfe.fit(xs, ys, peak_org=bands)
91+
92+
return tfe
93+
94+
def get_tbands():
95+
"""Get a bands object, for testing."""
96+
97+
return Bands({'theta' : (4, 8), 'alpha' : (8, 12), 'beta' : (13, 30)})
98+
99+
def get_tresults():
100+
"""Get a FitResults object, for testing."""
101+
102+
return FitResults(aperiodic_params=np.array([1.0, 1.00]),
103+
peak_params=np.array([[10.0, 1.25, 2.0], [20.0, 1.0, 3.0]]),
104+
r_squared=0.97, error=0.01,
105+
gaussian_params=np.array([[10.0, 1.25, 1.0], [20.0, 1.0, 1.5]]))
106+
107+
def get_tdocstring():
108+
"""Get an example docstring, for testing."""
109+
110+
docstring = \
111+
"""This is a test doctring.
112+
113+
Parameters
114+
----------
115+
first : thing
116+
Words, words, words.
117+
second : stuff
118+
Words, words, words.
119+
120+
Returns
121+
-------
122+
out : yay
123+
Words, words, words.
124+
"""
125+
126+
return docstring
File renamed without changes.

0 commit comments

Comments
 (0)