def test_flat_maxima(self): """Test if flat maxima are detected correctly.""" x = np.array([-1.3, 0, 1, 0, 2, 2, 0, 3, 3, 3, 2.99, 4, 4, 4, 4, -10, -5, -5, -5, -5, -5, -10]) midpoints, left_edges, right_edges = _local_maxima_1d(x) assert_equal(midpoints, np.array([2, 4, 8, 12, 18])) assert_equal(left_edges, np.array([2, 4, 7, 11, 16])) assert_equal(right_edges, np.array([2, 5, 9, 14, 20]))
def test_exceptions(self): """Test input validation and raised exceptions.""" with raises(ValueError, match="wrong number of dimensions"): _local_maxima_1d(np.ones((1, 1))) with raises(ValueError, match="expected 'float64_t'"): _local_maxima_1d(np.ones(1, dtype=int)) with raises(TypeError, match="list"): _local_maxima_1d([1., 2.]) with raises(TypeError, match="'x' must not be None"): _local_maxima_1d(None)
def test_simple(self): """Test with simple signal.""" x = np.linspace(-10, 10, 50) x[2::3] += 1 expected = np.arange(2, 50, 3) for array in _local_maxima_1d(x): # For plateaus of size 1, the edges are identical with the # midpoints assert_equal(array, expected) assert_(array.base is None)
def test_simple(self): """Test with simple signal.""" x = np.linspace(-10, 10, 50) x[2::3] += 1 expected = np.arange(2, 50, 3) for array in _local_maxima_1d(x): # For plateaus of size 1, the edges are identical with the # midpoints assert_equal(array, expected) assert_(array.base is None)
def test_flat_maxima(self): """Test if flat maxima are detected correctly.""" x = np.array([ -1.3, 0, 1, 0, 2, 2, 0, 3, 3, 3, 2.99, 4, 4, 4, 4, -10, -5, -5, -5, -5, -5, -10 ]) midpoints, left_edges, right_edges = _local_maxima_1d(x) assert_equal(midpoints, np.array([2, 4, 8, 12, 18])) assert_equal(left_edges, np.array([2, 4, 7, 11, 16])) assert_equal(right_edges, np.array([2, 5, 9, 14, 20]))
so = ctypes.CDLL('find_peak.so') so.select_by_peak_distance.argtypes = (T.int_p, T.int, T.float_p, T.float, T.bool_p) so.select_by_peak_distance.restype = None so.select_by_peak_distance(peaks, len(peaks_np), priority, distance, keep) del (so) return keep_np from scipy.misc import electrocardiogram x = electrocardiogram()[2000:4000] from scipy.signal._peak_finding_utils import _local_maxima_1d peaks, _, _ = _local_maxima_1d(x) distance = 5 keep = select_by_peak_distance(peaks, x[peaks], distance) from scipy.signal._peak_finding_utils import \ _select_by_peak_distance as scipy_select_by_peak_distance keep_groundtrue = scipy_select_by_peak_distance(peaks, x[peaks], distance) # print(np.argsort(x[peaks])) print((keep)) print((keep_groundtrue)) print(((keep ^ keep_groundtrue))) print(np.count_nonzero(keep))
def test_linear(self): """Test with linear signal.""" x = np.linspace(0, 100) for array in _local_maxima_1d(x): assert_equal(array, np.array([])) assert_(array.base is None)
def test_empty(self): """Test with empty signal.""" x = np.array([], dtype=np.float64) for array in _local_maxima_1d(x): assert_equal(array, np.array([])) assert_(array.base is None)
def test_signal_edges(self, x): """Test if behavior on signal edges is correct.""" for array in _local_maxima_1d(x): assert_equal(array, np.array([])) assert_(array.base is None)
def test_linear(self): """Test with linear signal.""" x = np.linspace(0, 100) for array in _local_maxima_1d(x): assert_equal(array, np.array([])) assert_(array.base is None)
def test_empty(self): """Test with empty signal.""" x = np.array([], dtype=np.float64) for array in _local_maxima_1d(x): assert_equal(array, np.array([])) assert_(array.base is None)
def test_signal_edges(self, x): """Test if behavior on signal edges is correct.""" for array in _local_maxima_1d(x): assert_equal(array, np.array([])) assert_(array.base is None)