def test_reversalIndexes(): """ Tests if the reversalIndexe is correct.""" DamperHys = hys.Hysteresis(testHys2) reversalIndexes = DamperHys.reversalIndexes assert reversalIndexes[15] == 492
def test_net_Area(): """ Tests if the net area is correct.""" DamperHys = hys.Hysteresis(testHys2) NetArea = DamperHys.getNetArea() assert abs(NetArea - 12390.79659964981) < 10**-5
def test_plot_Slope(): """ Tests if the slope is the correct value""" DamperHys = hys.Hysteresis(testHys2) slope = DamperHys.Slope assert abs(slope[-2] - 40499.99999999157) < 10**-5
def test_plot_RemoveNeg(monkeypatch): """ Tests if the remove Negative attribute runs""" monkeypatch.setattr(plt, 'show', lambda: None) trianglexy = np.column_stack((triangle, Y)) smallTriangles = hys.Hysteresis(trianglexy) smallTriangles.recalculateCycles(peakProminence=.2) cycle1 = smallTriangles.getCycle(0) xy = cycle1.xy x = xy[:, 0] y = xy[:, 1] direction = cycle1.direction difference = np.append(0, np.diff(x)) condtion = np.where(0 <= difference * direction) plt.subplots() plt.plot(x[condtion], y[condtion]) New = hys.removeNegative(cycle1) New.plot() assert True == True
def test_plot_Area(monkeypatch): """ Tests if the area can plot correctly.""" monkeypatch.setattr(plt, 'show', lambda: None) DamperHys = hys.Hysteresis(testHys2) DamperHys.plotArea() assert True == True
def test_plot_Slope(monkeypatch): """ Tests if the slope can plot correctly""" monkeypatch.setattr(plt, 'show', lambda: None) DamperHys = hys.Hysteresis(testHys2) slope = DamperHys.Slope DamperHys.plotSlope() plt.close() assert True == True
def test_plot_labels(monkeypatch): """ Tests if the cycles can plot correctly""" monkeypatch.setattr(plt, 'show', lambda: None) DamperHys = hys.Hysteresis(testHys2) DamperHys.plot(plotCycles=True, labelCycles=[17, 18, 19, 23]) plt.close() DamperHys.plot(plotCycles=True, labelCycles='all') plt.close() assert True == True
def test_DownSampled_Plotting(monkeypatch): """ Tests if the resampled hystresis can plot correctly """ monkeypatch.setattr(plt, 'show', lambda: None) DamperHys = hys.Hysteresis(testHys2) downsampledHys = hys.reSample(DamperHys, 20) downsampledHys.plot(plotCycles = True) plt.close() downsampledHys.plotCycles([2,3]) plt.close() downsampledHys.plotArea() plt.close() downsampledHys.plotSlope() plt.close() assert True == True
# A2 = Curve2.getNetArea() # A3 = Curve3.getNetArea() # ============================================================================= # Circle Plotting test - Tested # ============================================================================= """ This tests a Circle hysteresis can be plotted and if the resampled curves can be plotted. """ basePoints = np.linspace(0, 1, 1000) * 2 * np.pi testCirclex = np.cos(basePoints) testCircley = np.sin(basePoints) Circlexy = np.column_stack((testCirclex, testCircley)) Circle = hys.Hysteresis(Circlexy) Circle.plot(plotCycles=True) Circle.plotArea(plotCycles=True) Circle.plotSlope(plotCycles=True, ylim=[-10, 10]) Circle.setPeaks() fig, ax = Circle.plotCycles(plotCycles=True, plotPeaks=True) # fig, ax = Circle.plotSubVector(0) Vector1 = Circle.Cycles[0] Vector2 = hys.reSample(Vector1, 30) Vector3 = hys.reSample(Circle, 10) Vector1.plot() Vector2.plot() Vector3.plot(True)
# -*- 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 disp = np.loadtxt('UFP_Disp.out', delimiter=' ') force = np.loadtxt('UFP_RFrc.out', delimiter=' ') testHys2 = np.column_stack([disp[:, 1], -force[:, 1]]) DamperHys = hys.Hysteresis(testHys2) def test_plot_labels(monkeypatch): """ Tests if the cycles can plot correctly""" monkeypatch.setattr(plt, 'show', lambda: None) DamperHys = hys.Hysteresis(testHys2) DamperHys.plot(plotCycles=True, labelCycles=[17, 18, 19, 23]) plt.close() DamperHys.plot(plotCycles=True, labelCycles='all') plt.close() assert True == True def test_plot_Cycles(monkeypatch):
import matplotlib.pyplot as plt # load the .csv Data InputName = 'Hys1.csv' LPName = 'LoadProtocol.csv' EnergyName = 'Hys1_Energy.csv' xyData = np.loadtxt(InputName, delimiter=',') LoadProtocol = np.loadtxt(LPName, delimiter=',', skiprows=1) Energy = np.loadtxt(EnergyName, delimiter=',') # some small adjustments xyData = xyData[:-21, :] xyData[-1, 0] = xyData[-1, 0] + 0.6 # Create the trace Hysteresis hysTrace = hys.Hysteresis(xyData) hysTrace.plotLoadProtocol() fig, ax = hysTrace.plot(True) # Expand the hysteresis FullHys = hys.exandHysTrace(hysTrace, LoadProtocol[:, 2], skipStart=1, skipEnd=2) FullHys.plot() # Plot the load Protocol FullHys.plotLoadProtocol() hysProt = FullHys.loadProtocol # Get cumulative displacement and area
def getHys(): ExpHys = hys.Hysteresis(Wall_exp_xy[8300:,:]) AnalHys = hys.Hysteresis(Wall_anal_xy[500:,:]) return ExpHys, AnalHys
This tests if a simple cicle works """ import hysteresis.hys as hys import numpy as np import time basePoints = np.linspace(0, 1, 1000) * 2 * np.pi testCirclex = np.sin(basePoints) testCircley = np.cos(basePoints) Circlexy = np.column_stack((testCirclex, testCircley)) NStep = 10000 t1 = time.time() for ii in range(NStep): pass t2 = time.time() t3 = time.time() for ii in range(NStep): Circle = hys.Hysteresis(Circlexy) t4 = time.time() dt1 = t2 - t1 dt2 = t4 - t3 print(dt1, dt2, dt2 - dt1)
import numpy as np import hysteresis.hys as hys t = np.linspace(0,4,1000)*np.pi x = np.sin(t) y = np.cos(t)*t xy = np.column_stack([x,y]) myHys = hys.Hysteresis(xy) myHys.plot(plotCycles = True)