forked from LorenFrankLab/spyglass
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add `return_fig` param to plotting helper functions to permit tests - `common_filter` - `common_interval` - Add coverage for ~1/2 of `common` - `common_behav` - `common_device` - `common_ephys` - `common_filter` - `common_interval` - with helper funcs tested seperately - `common_lab` - `common_nwbfile` - partial
- Loading branch information
Showing
12 changed files
with
523 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
from numpy import array_equal | ||
|
||
|
||
def test_create_from_config(mini_insert, common_ephys, mini_path): | ||
before = common_ephys.Electrode().fetch() | ||
common_ephys.Electrode.create_from_config(mini_path.stem) | ||
after = common_ephys.Electrode().fetch() | ||
# Because already inserted, expect no change | ||
assert array_equal( | ||
before, after | ||
), "Electrode.create_from_config had unexpected effect" | ||
|
||
|
||
def test_raw_object(mini_insert, common_ephys, mini_dict, mini_content): | ||
obj_fetch = common_ephys.Raw().nwb_object(mini_dict).object_id | ||
obj_raw = mini_content.get_acquisition().object_id | ||
assert obj_fetch == obj_raw, "Raw.nwb_object did not return expected object" | ||
|
||
|
||
def test_set_lfp_electrodes(mini_insert, common_ephys, mini_copy_name): | ||
before = common_ephys.LFPSelection().fetch() | ||
common_ephys.LFPSelection().set_lfp_electrodes(mini_copy_name, [0]) | ||
after = common_ephys.LFPSelection().fetch() | ||
# Because already inserted, expect no change | ||
assert ( | ||
len(after) == len(before) + 1 | ||
), "Set LFP electrodes had unexpected effect" | ||
|
||
|
||
@pytest.mark.skip(reason="Not testing V0: common lfp") | ||
def test_lfp(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def filter_parameters(common): | ||
yield common.FirFilterParameters() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def filter_dict(filter_parameters): | ||
yield {"filter_name": "test", "fs": 10} | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def add_filter(filter_parameters, filter_dict): | ||
filter_parameters.add_filter( | ||
**filter_dict, filter_type="lowpass", band_edges=[1, 2] | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def filter_coeff(filter_parameters, filter_dict): | ||
yield filter_parameters._filter_restrict(**filter_dict)["filter_coeff"] | ||
|
||
|
||
def test_add_filter(filter_parameters, add_filter, filter_dict): | ||
"""Test add filter""" | ||
assert filter_parameters & filter_dict, "add_filter failed" | ||
|
||
|
||
def test_filter_restrict( | ||
filter_parameters, add_filter, filter_dict, filter_coeff | ||
): | ||
assert sum(filter_coeff) == pytest.approx( | ||
0.999134, abs=1e-6 | ||
), "filter_restrict failed" | ||
|
||
|
||
def test_plot_magitude(filter_parameters, add_filter, filter_dict): | ||
fig = filter_parameters.plot_magnitude(**filter_dict, return_fig=True) | ||
assert sum(fig.get_axes()[0].lines[0].get_xdata()) == pytest.approx( | ||
163837.5, abs=1 | ||
), "plot_magnitude failed" | ||
|
||
|
||
def test_plot_fir_filter( | ||
filter_parameters, add_filter, filter_dict, filter_coeff | ||
): | ||
fig = filter_parameters.plot_fir_filter(**filter_dict, return_fig=True) | ||
assert sum(fig.get_axes()[0].lines[0].get_ydata()) == sum( | ||
filter_coeff | ||
), "Plot filter failed" | ||
|
||
|
||
def test_filter_delay(filter_parameters, add_filter, filter_dict): | ||
delay = filter_parameters.filter_delay(**filter_dict) | ||
assert delay == 27, "filter_delay failed" | ||
|
||
|
||
def test_time_bound_warning(filter_parameters, add_filter, filter_dict): | ||
with pytest.warns(UserWarning): | ||
filter_parameters._time_bound_check(1, 3, [2, 5], 4) | ||
|
||
|
||
@pytest.mark.skip(reason="Not testing V0: filter_data") | ||
def test_filter_data(filter_parameters, mini_content): | ||
pass | ||
|
||
|
||
def test_calc_filter_delay(filter_parameters, filter_coeff): | ||
delay = filter_parameters.calc_filter_delay(filter_coeff) | ||
assert delay == 27, "filter_delay failed" | ||
|
||
|
||
def test_create_standard_filters(filter_parameters): | ||
filter_parameters.create_standard_filters() | ||
assert filter_parameters & { | ||
"filter_name": "LFP 0-400 Hz" | ||
}, "create_standard_filters failed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from numpy import array_equal | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def interval_list(common): | ||
yield common.IntervalList() | ||
|
||
|
||
def test_plot_intervals(mini_insert, interval_list): | ||
fig = interval_list.plot_intervals(return_fig=True) | ||
interval_list_name = fig.get_axes()[0].get_yticklabels()[0].get_text() | ||
times_fetch = ( | ||
interval_list & {"interval_list_name": interval_list_name} | ||
).fetch1("valid_times")[0] | ||
times_plot = fig.get_axes()[0].lines[0].get_xdata() | ||
|
||
assert array_equal(times_fetch, times_plot), "plot_intervals failed" | ||
|
||
|
||
def test_plot_epoch(mini_insert, interval_list): | ||
fig = interval_list.plot_epoch_pos_raw_intervals(return_fig=True) | ||
epoch_label = fig.get_axes()[0].get_yticklabels()[-1].get_text() | ||
assert epoch_label == "epoch", "plot_epoch failed" | ||
|
||
epoch_interv = fig.get_axes()[0].lines[0].get_ydata() | ||
assert array_equal(epoch_interv, [1, 1]), "plot_epoch failed" |
Oops, something went wrong.