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_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_comapre_basic(): 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) smallHys = hys.resample(myHys, 10) # samllHys.plot() out = hys.compareHys(smallHys, myHys) assert out[0] == 0 # 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) # smallHys = hys.reSample(myHys, 10) # smallHys.xy[:,1] = smallHys.xy[:,1] / 4 # smallHys = hys.Hysteresis(smallHys.xy) # smallHys.plot() # # smallHys.xy[:,1] = smallHys.xy[:,1]/2 # out = hys.CompareHys(smallHys,myHys)
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_reversalIndexes(): """ Tests if the reversalIndexe is correct.""" DamperHys = hys.Hysteresis(testHys2) reversalIndexes = DamperHys.reversalIndexes assert reversalIndexes[15] == 492
def test_recalc_like(): revDist =2 revWidth = 10 revProminence = 50 myHys = hys.Hysteresis(xy,revDist,revWidth,revProminence) newHys = hys.Hysteresis(xy) newHys.recalculateCycles_like(myHys) check1 = newHys.revDist == revDist check2 = newHys.revWidth == revWidth check3 = newHys.revProminence == revProminence assert np.all([check1, check2, check3])
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 MakeCircle(): basePoints = np.linspace(0,1,1000)*2*np.pi testCirclex = np.sin(basePoints) testCircley = np.cos(basePoints) Circlexy = np.column_stack((testCirclex, testCircley)) Circle = hys.Hysteresis(Circlexy) return Circle
def test_backbone(): # Function: get envelope curve analHys = hys.Hysteresis(xy) # analHys.plotVsIndex(True) # Get the backbone backbone = hys.getBackboneCurve(analHys, lp, 1) assert True == True
def makeCurveBase(): "lamda function that creates all curves" t = np.linspace(0, 4, 1000) * np.pi x = np.cos(t) y = np.sin(t) * t xy = np.column_stack([x, y]) Curve = hys.Hysteresis(xy) return Curve
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_cum_Disp(): DamperHys = hys.Hysteresis(testHys2) LP = DamperHys.loadProtocol # The total area contained by the hystresis, including end cycles cumDisp = DamperHys.getNetCumDisp() LPcumDisp = np.sum(np.abs(LP[:-2])) * 2 + LP[-2] + (LP[-2] - LP[-1]) assert abs((cumDisp - LPcumDisp)) < 10**-8 # test_cum_Disp()
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_inputParse(): """makes sure we get an error if the user doesn't ask for one of end points or peaks.""" # Function: get envelope curve analHys = hys.Hysteresis(xy) # analHys.plotVsIndex(True) with pytest.raises(ValueError) as errorInfo: # Get the backbone backbone = hys.getBackboneCurve(analHys, lp, False, False) # assert True assert errorInfo.type is ValueError
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
""" loadProtocolTrace = np.array([ 0.035, 0.05, 0.075, 0.1, 0.15, 0.2, 0.3, 0.4, 0.6, 0.9, 1.35, 2.0, 3.0, 4.0 ]) * 4.1 / 100 Ncycles = len(loadProtocolTrace) * 3 * 2 Indexes = np.ones_like(loadProtocolTrace, dtype=int) * 3 loadProtocol = createProtocol(loadProtocolTrace, Indexes) """ Here we make hysteresis objects of our experimental and analysis load protcol. When create the Hysteresis object, it will attempt to find the reversal points. """ ExpHys = hys.Hysteresis(Wall_exp_xy) AnalHys = hys.Hysteresis(Wall_anal_xy) """ Let's see how well our the initial guess did. We'll print the number of cycles, as well as make a plot that has the cycle locations """ print(ExpHys.NCycles) fig, ax = plt.subplots() ExpHys.plot(True) """ Wow, there are way too many cycles early on! It's hard to get a sense of what's wrong from our initial plot. Let's make a new plot of the values vs. the index of each point to see what's going on. We will turn on the plot cycles option to see where out cycles are. We'll can also use the "plotLoadProtocol()" plot, to see the hysteresis'
""" import numpy as np import hysteresis.plotSpecial.animate as ani import hysteresis as hys import scipy np.random.seed(101) x = np.linspace(0, 1, 1001)*10 triangleBig = scipy.signal.sawtooth(x*2,0.5) permutate = np.random.normal(0,1,1001)/2 Ynoise = triangleBig + permutate Ynoise = scipy.signal.savgol_filter(Ynoise,53,2) trianglexy = np.column_stack((x, Ynoise)) test1 = hys.Hysteresis(trianglexy) # test.plot() permutate = np.random.normal(0,1,1001)/2 Ynoise = triangleBig + permutate Ynoise = scipy.signal.savgol_filter(Ynoise,53,2) trianglexy = np.column_stack((x, Ynoise)) test2 = hys.Hysteresis(trianglexy) permutate = np.random.normal(0,1,1001)/2 Ynoise = triangleBig + permutate Ynoise = scipy.signal.savgol_filter(Ynoise,53,2) trianglexy = np.column_stack((x, Ynoise)) test3 = hys.Hysteresis(trianglexy) # xyAni = ani.getAnixy(trianglexy, 2)
# ============================================================================= # Run an opensees analysis using the runAnalysis Comand k = 3.2 * 10**6 xy = runAnalysis(k) lpSteps = [2] * 9 skipEnd = 0 skipStart = 0 # ============================================================================= # Find the backbone # ============================================================================= # InputParser - Decides what to do with the variable LoadProtcol # if you get an interger use that for all cycles shift = lpSteps[0] - 1 Indexes = np.concatenate([[0], np.cumsum(lpSteps, dtype=int) - shift]) # Function: get envelope curve analHys = hys.Hysteresis(xy) analHys.plotVsIndex(True) # Get the backbone backbone = hys.getBackboneCurve(analHys, lpSteps) # Check if the outputs make sense with a plot fig, ax = plt.subplots() analHys.plot() backbone.plot()
__author__ = 'volk'
Created on Sat May 1 23:49:09 2021 @author: Christian """ import numpy as np import hysteresis.plotSpecial.animate as ani import hysteresis as hys import scipy np.random.seed(101) x = np.linspace(0, 1, 101) * 10 y = np.sin(x) trianglexy = np.column_stack((x, y)) test = hys.Hysteresis(trianglexy) testBase = ani.AnimationBase() def test_Play(): assert testBase.play == True def test_Toggle(): testBase.togglePlay() assert testBase.play == False # test_Play() # test_Toggle()
# 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)
force = np.loadtxt('RFrc.out', delimiter=' ') testHys2 = np.column_stack([disp[:, 1], -force[:, 1]]) # ============================================================================= # Test hysteresis, Ganey UFP # ============================================================================= """ First, we create the hysteresis object from our xy input information. The hystresis object represents a curve that changes several times. If needed, we can access the xy data of the hystresis. """ DamperHys = hys.Hysteresis(inputxy) xy = DamperHys.xy """ We can then show some of the outputs. Lets use some of the basic plotting features to visualize our data. Here we use the plot command to create a plot of our data. The plot command is similar to matplotlib's plot comand - it doesn't make a figure """ DamperHys.plot() """ All outputs are matplotlib plots, so we can make changes after the plotting. Let's add some labels to our chart! """ fig, ax = DamperHys.initFig()
import scipy.interpolate from scipy.interpolate import interp1d test_disp = [] test_forces = [] simu_disp = [] simu_forces = [] with open('disp.csv') as f: for line in f: temp = (line.split(',')) test_disp.append(float(temp[0])) test_forces.append(float(temp[1])) try: simu_disp.append(float(temp[-1])) simu_forces.append(float(temp[-2])) except ValueError as e: pass test_data = np.column_stack([test_disp, test_forces]) simu_data = np.column_stack([simu_disp, simu_forces]) test_hys = hys.Hysteresis(test_data) test_hys.plotCumArea() simu_hys = hys.Hysteresis(simu_data) simu_hys.plotCumArea() plt.title("Hysteresis Area") plt.legend(labels=['experiment', 'simulation']) plt.show()
InputName = 'Hys1.csv' LoadProtocolName = 'LoadProtocol.csv' EnergyName = 'Hys1_Energy.csv' xyData = np.loadtxt(InputName, delimiter=',') LoadProtocol = np.loadtxt(LoadProtocolName, delimiter=',', skiprows=1, dtype=int) Energy = np.loadtxt(EnergyName, delimiter=',') xyData[:, 1] = xyData[:, 1] / 1000 Energy[:, 1] = Energy[:, 1] # Make a few plots hysTrace = hys.Hysteresis(xyData) fig, ax = hysTrace.initFig() hysTrace.plotLoadProtocol() fig, ax = hysTrace.initFig() hysTrace.plot(True) fig, ax = hysTrace.initFig() hysTrace.plotCycles() # Expand the hysteresis trace hysProt = hysTrace.loadProtocol cycles = hysTrace.Cycles FullHys = hys.exandHysTrace(hysTrace, LoadProtocol[3:, 2],
# -*- coding: utf-8 -*- """ Created on Fri Aug 21 23:47:36 2020 @author: Christian """ import hysteresis as hys import numpy as np import matplotlib.pyplot as plt from hysteresis.plotSpecial import CycleViewer 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) # DamperHys.plot(True) def test_CycleViewer(monkeypatch): monkeypatch.setattr(plt, 'show', lambda: None) CycleViewer(DamperHys, xlims=[0, 20]) assert True == True # test_CycleViewer()
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 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)
# We'll also input the absolute value of the load protocol loadProtocol = np.array([ 0.035, 0.05, 0.075, 0.1, 0.15, 0.2, 0.3, 0.4, 0.6, 0.9, 1.35, 2.0, 3.0, 4.0 ]) * 4.1 / 100 # We want this may cycles total! Ncycles = len(loadProtocol) * 3 Indexes = np.ones_like(loadProtocol, dtype=int) * 3 loadProtocolout = hys.protocol.createProtocol(loadProtocol, Indexes) # ============================================================================= # Plot both Hystereses # ============================================================================= ExpHys = hys.Hysteresis(Wall_exp_xy) AnalHys = hys.Hysteresis(Wall_anal_xy) fig, ax = plt.subplots() ExpHys.plot() AnalHys.plot() ax.set_xlabel('Actuator Drift (m)') ax.set_ylabel('Average difference between Curves (kN)') plt.minorticks_on() ax.grid(which='major', color='grey', linewidth=0.5, alpha=0.8) ax.grid(b=True, which='minor', linewidth=0.5, alpha=0.4) fig, ax = plt.subplots() AnalHys.plotCycles([20, 21, 22, 30, 50, 60]) # =============================================================================
""" import hysteresis as hys import numpy as np # ============================================================================= # Input Data # ============================================================================= # We create a set of input xy data using numpy, create a hysteresis, then # plot a figure of our object. x = np.linspace(0,3,301) y = x**3 + x**2 + 2 xy = np.column_stack((x,y)) myHys = hys.Hysteresis(xy) fig, ax = myHys.initFig() myHys.plot() myHys.plotSlope() ax.set_title('Default slope Function') # ============================================================================= # Define a custom function # ============================================================================= # define a custom slope function - it makes the slope always 1. def fslope(xy): slope = np.ones_like(xy[:,0]) return slope
""" We'll manually input a trace of the load protocol that was input the the actuator. Values are converted to % drift, but units don't really matter. """ loadProtocol = np.array([ 0.035, 0.05, 0.075, 0.1, 0.15, 0.2, 0.3, 0.4, 0.6, 0.9, 1.35, 2.0, 3.0, 4.0 ]) * 4.1 / 100 # ============================================================================= # Plot both Hystereses # ============================================================================= """ Here we make hysteresis objects of our experimental and analysis load protcol. """ ExpHys = hys.Hysteresis(Wall_exp_xy) AnalHys = hys.Hysteresis(Wall_anal_xy) """ We can find out out how many cycles the initial hysteresis has! The Hysteresis object stores a bunch of useful information """ print(ExpHys.NCycles) """ We can also have a bunch of conveneint ways of viewing our data. We can use the "plot" command to make a figure of our data. All plotting uses matplotlib, and is compatible with matplotlib commands In fact our plot can returns a matplotlib line object of the data! """ fig, ax = plt.subplots() line = ExpHys.plot()