# Path: pambox/speech/sepsm.py
# class Sepsm(object):
#     def __init__(self, fs=22050
#                  , cf=_default_center_cf
#                  , modf=_default_modf
#                  , downsamp_factor=10
#                  , noise_floor=0.01
#                  , snr_env_limit=0.001
#                  , name='sEPSM'
#                  ):
#     def _peripheral_filtering(self, signals):
#     def _bands_above_thres(self, x):
#     def _snr_env(self, p_mix, p_noise):
#     def _optimal_combination(self, snr_env, bands_above_thres_idx):
#     def _find_bands_above_thres(self, mixture):
#     def _extract_env(self, channel_sigs):
#     def _mod_sensitivity(self, envs):
#     def _mod_filtering(self, channel_envs):
#     def predict(self, clean=None, mix=None, noise=None):
#     def plot_bands_above_thres(self, res):
#     def _plot_mod_matrix(self, mat, ax=None, vmin=None, vmax=None):
#     def plot_snr_env_matrix(self, res, ax=None, vmin=None, vmax=None):
#     def plot_exc_ptns(self, res, db=True, attr='exc_ptns', vmin=None,
#                       vmax=None):
#     def plot_filtered_envs(self, envs, fs, axes=None):


import csv
import os.path
import numpy as np
import scipy.io as sio
import pytest
from numpy.testing import assert_allclose, assert_array_equal
from pambox.speech import sepsm




__DATA_ROOT__ = os.path.join(os.path.dirname(__file__), 'data')


def test_select_bands_above_threshold():
    center_f = np.asarray([63, 80, 100, 125, 160, 200, 250, 315, 400, 500,
                           630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000,
                           5000, 6300, 8000])
    noise_rms = [142.598279903563, 596.254784935965, 1319.07476787393,
                 1931.80860942992, 2180.13918820141, 1714.49937340166,
                 2009.77926719000, 1130.48579025285, 820.432762207735,
                 1006.49592779826, 1523.47513285058, 921.921756875459,
                 791.901475253190, 1508.59965109920, 825.572455447266,
                 657.161350227808, 626.333420574852, 474.950833753788,
                 331.591691820142, 206.744689750152, 491.003492858161,
                 297.383958806200]
    target = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
              20, 21, 22]
    c = sepsm.Sepsm(cf=center_f)
    bands_above_thres = c._bands_above_thres(noise_rms)
    # Make 1-based to compare with matlab
    bands_above_thres += 1
    assert_array_equal(bands_above_thres, target)


@pytest.fixture
def model():

# Path: pambox/speech/sepsm.py
# class Sepsm(object):
#     def __init__(self, fs=22050
#                  , cf=_default_center_cf
#                  , modf=_default_modf
#                  , downsamp_factor=10
#                  , noise_floor=0.01
#                  , snr_env_limit=0.001
#                  , name='sEPSM'
#                  ):
#     def _peripheral_filtering(self, signals):
#     def _bands_above_thres(self, x):
#     def _snr_env(self, p_mix, p_noise):
#     def _optimal_combination(self, snr_env, bands_above_thres_idx):
#     def _find_bands_above_thres(self, mixture):
#     def _extract_env(self, channel_sigs):
#     def _mod_sensitivity(self, envs):
#     def _mod_filtering(self, channel_envs):
#     def predict(self, clean=None, mix=None, noise=None):
#     def plot_bands_above_thres(self, res):
#     def _plot_mod_matrix(self, mat, ax=None, vmin=None, vmax=None):
#     def plot_snr_env_matrix(self, res, ax=None, vmin=None, vmax=None):
#     def plot_exc_ptns(self, res, db=True, attr='exc_ptns', vmin=None,
#                       vmax=None):
#     def plot_filtered_envs(self, envs, fs, axes=None):


# Path: pambox/tests/test_sepsm.py
import csv
import os.path
import numpy as np
import scipy.io as sio
import pytest
from numpy.testing import assert_allclose, assert_array_equal
from pambox.speech import sepsm





__DATA_ROOT__ = os.path.join(os.path.dirname(__file__), 'data')


def test_select_bands_above_threshold():
    center_f = np.asarray([63, 80, 100, 125, 160, 200, 250, 315, 400, 500,
                           630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000,
                           5000, 6300, 8000])
    noise_rms = [142.598279903563, 596.254784935965, 1319.07476787393,
                 1931.80860942992, 2180.13918820141, 1714.49937340166,
                 2009.77926719000, 1130.48579025285, 820.432762207735,
                 1006.49592779826, 1523.47513285058, 921.921756875459,
                 791.901475253190, 1508.59965109920, 825.572455447266,
                 657.161350227808, 626.333420574852, 474.950833753788,
                 331.591691820142, 206.744689750152, 491.003492858161,
                 297.383958806200]
    target = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
              20, 21, 22]
    c = sepsm.Sepsm(cf=center_f)
    bands_above_thres = c._bands_above_thres(noise_rms)
    # Make 1-based to compare with matlab
    bands_above_thres += 1
    assert_array_equal(bands_above_thres, target)


@pytest.fixture
def model():

    return sepsm.Sepsm()