コード例 #1
0
ファイル: test_fit.py プロジェクト: pinknoiz/fooof
def test_add_data():
    """Tests method to add data to FOOOF objects."""

    # This test uses it's own FOOOF object, to not add stuff to the global one
    tfm = get_tfm()

    # Test data for adding
    freqs, pows = np.array([1, 2, 3]), np.array([10, 10, 10])

    # Test adding data
    tfm.add_data(freqs, pows)
    assert tfm.has_data
    assert np.all(tfm.freqs == freqs)
    assert np.all(tfm.power_spectrum == np.log10(pows))

    # Test that prior data does not get cleared, when requesting not to clear
    tfm._reset_data_results(True, True, True)
    tfm.add_results(
        FOOOFResults([1, 1], [10, 0.5, 0.5], 0.95, 0.02, [10, 0.5, 0.25]))
    tfm.add_data(freqs, pows, clear_results=False)
    assert tfm.has_data
    assert tfm.has_model

    # Test that prior data does get cleared, when requesting not to clear
    tfm._reset_data_results(True, True, True)
    tfm.add_data(freqs, pows, clear_results=True)
    assert tfm.has_data
    assert not tfm.has_model
コード例 #2
0
ファイル: test_fit.py プロジェクト: anc211/fooof
def test_adds():
    """Tests methods that add data to FOOOF objects.

    Checks: add_data, add_settings, add_results.
    """

    # Note: uses it's own tfm, to not add stuff to the global one
    tfm = get_tfm()

    # Test adding data
    freqs, pows = np.array([1, 2, 3]), np.array([10, 10, 10])
    tfm.add_data(freqs, pows)
    assert np.all(tfm.freqs == freqs)
    assert np.all(tfm.power_spectrum == np.log10(pows))

    # Test adding settings
    fooof_settings = FOOOFSettings([1, 4], 6, 0, 2, 'fixed')
    tfm.add_settings(fooof_settings)
    for setting in OBJ_DESC['settings']:
        assert getattr(tfm, setting) == getattr(fooof_settings, setting)

    # Test adding meta data
    fooof_meta_data = FOOOFMetaData([3, 40], 0.5)
    tfm.add_meta_data(fooof_meta_data)
    for meta_dat in OBJ_DESC['meta_data']:
        assert getattr(tfm, meta_dat) == getattr(fooof_meta_data, meta_dat)

    # Test adding results
    fooof_results = FOOOFResults([1, 1], [10, 0.5, 0.5], 0.95, 0.02,
                                 [10, 0.5, 0.25])
    tfm.add_results(fooof_results)
    for setting in OBJ_DESC['results']:
        assert getattr(tfm, setting) == getattr(fooof_results,
                                                setting.strip('_'))
コード例 #3
0
ファイル: test_fit.py プロジェクト: pinknoiz/fooof
def test_add_meta_data():
    """Tests method to add meta data to FOOOF objects."""

    # This test uses it's own FOOOF object, to not add stuff to the global one
    tfm = get_tfm()

    # Test adding meta data
    fooof_meta_data = FOOOFMetaData([3, 40], 0.5)
    tfm.add_meta_data(fooof_meta_data)
    for meta_dat in OBJ_DESC['meta_data']:
        assert getattr(tfm, meta_dat) == getattr(fooof_meta_data, meta_dat)
コード例 #4
0
ファイル: test_fit.py プロジェクト: pinknoiz/fooof
def test_add_settings():
    """Tests method to add settings to FOOOF objects."""

    # This test uses it's own FOOOF object, to not add stuff to the global one
    tfm = get_tfm()

    # Test adding settings
    fooof_settings = FOOOFSettings([1, 4], 6, 0, 2, 'fixed')
    tfm.add_settings(fooof_settings)
    for setting in OBJ_DESC['settings']:
        assert getattr(tfm, setting) == getattr(fooof_settings, setting)
コード例 #5
0
def test_add_results():
    """Tests method to add results to FOOOF objects."""

    # This test uses it's own FOOOF object, to not add stuff to the global one
    tfm = get_tfm()

    # Test adding results
    fooof_results = FOOOFResults([1, 1], [10, 0.5, 0.5], 0.95, 0.02, [10, 0.5, 0.25])
    tfm.add_results(fooof_results)
    assert tfm.has_model
    for setting in OBJ_DESC['results']:
        assert getattr(tfm, setting) == getattr(fooof_results, setting.strip('_'))
コード例 #6
0
ファイル: test_fit.py プロジェクト: pinknoiz/fooof
def test_fooof_resets():
    """Check that all relevant data is cleared in the reset method."""

    # Note: uses it's own tfm, to not clear the global one
    tfm = get_tfm()

    tfm._reset_data_results(True, True, True)
    tfm._reset_internal_settings()

    for data in ['data', 'model_components']:
        for field in OBJ_DESC[data]:
            assert getattr(tfm, field) is None
    for field in OBJ_DESC['results']:
        assert np.all(np.isnan(getattr(tfm, field)))
    assert tfm.freqs is None and tfm.fooofed_spectrum_ is None
コード例 #7
0
ファイル: conftest.py プロジェクト: parhalje/fooof
def tfm():
    yield get_tfm()