def test_notchedTriangles_recalc_peaks():

    notchedTriangles = hys.SimpleCycle(trianglexy, FindPeaks=True)
    notchedTriangles.recalculatePeaks(peakProminence=0.8)
    peaks2 = notchedTriangles.peakIndexes

    assert peaks2[2] == 314
def test_noisey_triangles():
    noiseyTriangles = hys.SimpleCycle(trianglexy, FindPeaks=True)
    noiseyTriangles.recalculatePeaks(peakWidth=100)
    peak2 = noiseyTriangles.peakIndexes
    noiseyTriangles.plot(plotPeaks=True)

    test1 = len(peak2) == 7
    test2 = peak2[-2] == 794
    assert np.all([test1, test2])
Ejemplo n.º 3
0
def test_getReturnCycle():
    """ Tests if the getReturnCycle function"""
    t = np.linspace(0,1,101)
    x1 = 1 - 1.5*t
    y1 =  (3)*x1**2 - 1
    x2 = x1[-1] + t*2
    y2 = y1[-1] + t*4
    
    
    TestCycle1 = hys.SimpleCycle(np.column_stack([x1,y1]))
    TestCycle2 = hys.SimpleCycle(np.column_stack([x2,y2]))
    TestCycle3 = hys.getReturnCycle(TestCycle1, TestCycle2)
    
    xySolution = np.zeros([76,2])
    xySolution[:75, :] = TestCycle2.xy[:75, :]
    xySolution[-1, :] = TestCycle1.xy[0, :]
    
    assert(np.all(xySolution == TestCycle3.xy))
    
def test_noisey_triangle_Area():
    noiseyTriangles = hys.SimpleCycle(trianglexy, FindPeaks=True)
    noiseyTriangles.setArea()
    area = noiseyTriangles.getNetArea()

    assert (area - -0.22793618247762648) < 10**-5
@author: Christian
"""
import hysteresis.hys as hys
import numpy as np
import matplotlib.pyplot as plt
import scipy
from scipy.interpolate import interp1d

# a triangle with small reversals
x = np.linspace(0, 1, 1000) * 10
triangleBig = scipy.signal.sawtooth(x * 2, 0.5)
triangleSmall = scipy.signal.sawtooth(x * 20, 0.5) / 7
triangle = triangleBig + triangleSmall
trianglexy = np.column_stack((x, triangle))
notchedTriangles = hys.SimpleCycle(trianglexy, FindPeaks=True)


def test_notchedTriangles_peaks():
    notchedTriangles.setPeaks()
    peaks = notchedTriangles.peakIndexes

    test1 = peaks[4] == 62
    test2 = peaks[14] == 220
    test3 = peaks[31] == 486

    assert np.all([test1, test2, test3])


def test_notchedTriangles_Slope():
    notchedTriangles.setSlope()
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 21 23:47:36 2020

@author: Christian
"""
import hysteresis.hys as hys
import numpy as np
import matplotlib.pyplot as plt
import scipy
from scipy.interpolate import interp1d

x = np.linspace(0, 1, 1000) * 10
triangleSmall = scipy.signal.sawtooth(x * 20, 0.5) / 7
trianglexy = np.column_stack((x, triangleSmall))
smallTriangles = hys.SimpleCycle(trianglexy, FindPeaks=True)


def test_plot_peaks(monkeypatch):
    monkeypatch.setattr(plt, 'show', lambda: None)
    smallTriangles.setPeaks()
    smallTriangles.plot(plotPeaks=True)
    plt.close()
    assert True == True


def test_plot_SubCycles(monkeypatch):
    monkeypatch.setattr(plt, 'show', lambda: None)
    smallTriangles.plotSubCycles()
    plt.close()