Skip to content

Commit

Permalink
Update to documentation and examples for 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cslotboom committed Nov 21, 2021
1 parent b021684 commit fa8204e
Show file tree
Hide file tree
Showing 12 changed files with 584 additions and 286 deletions.
102 changes: 76 additions & 26 deletions doc/readthedocs/hysteresis/Backups/baseClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# Curve objects
# =============================================================================





class CurveBase:
"""
Expand Down Expand Up @@ -62,21 +66,38 @@ def __init__(self, XYData, xunit = '', yunit = ''):

self.xunit = xunit
self.yunit = yunit

def __len__(self):
return len(self.xy[:,0])

# def __truediv__(self, x):
# return self.xy[:,1] / x
def _getInstance(self):
return type(self)

def _convertToCurve(self, otherCurve):
"""
Converts non-hysteresis datatypes
"""
if isinstance(otherCurve, np.ndarray):
return CurveBase(otherCurve)
# else:
# otherType = type(otherCurve)
# raise Exception(f'multiplication not supported for {otherType}.')


# def __rtruediv__(self, x):
# return x / self.xy[:,1]

# def __mul__(self, x):
# y = self.xy[:,1]*x
# xy = np.column_stack([x,y])
def __mul__(self, curve):
"""
I need a way of saving the hysteresis state and copying it over...
"""

# return self.xy[:,1]*x
# Get the current instance of curve
Instance = self._getInstance()
operand = _getOperand(curve)

x = self.xy[:,0]
y = self.xy[:,1]*operand

return Instance(np.column_stack([x,y]))

# def __add__(self, x):
# return self.xy[:,1] + x
Expand Down Expand Up @@ -164,27 +185,29 @@ def setPeaks(self, peakDist = 2, peakWidth = None, peakProminence = None):
self.minIndexes = peakIndexes[1::2]
self.maxIndexes = peakIndexes[0::2]

def plot(self, plotCycles = False, plotPeaks = False, labelCycles = []):
def plot(self, plotCycles = False, plotPeaks = False, labelCycles = [],
**kwargs):
"""
Plots the base curve
"""
x = self.xy[:,0]
y = self.xy[:,1]

return self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles)
return self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles,
**kwargs)

def plotVsIndex(self, plotCycles = False, plotPeaks = False,
labelCycles = []):
labelCycles = [], **kwargs):
"""
Plots the base curve against index (as opposed to X values)
"""

x = np.arange(0,len(self.xy[:,0]))
y = self.xy[:,0]

self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles)
self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles, **kwargs)

def plotLoadProtocol(self, comparisonProtocol = []):
def plotLoadProtocol(self, comparisonProtocol = [], **kwargs):
"""
Plots the peak x values for each cycle in acurve.
"""
Expand All @@ -194,39 +217,59 @@ def plotLoadProtocol(self, comparisonProtocol = []):
y = self.loadProtocol
x = np.arange(0,len(y))

self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles)
self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles, **kwargs)

if len(comparisonProtocol) != 0:
plt.plot(comparisonProtocol)


def plotSlope(self, plotCycles = False, plotPeaks = False,
labelCycles = []):
labelCycles = [], **kwargs):

x = self.xy[:,0]
y = self.slope

self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles)
self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles, **kwargs)

def plotArea(self, plotCycles = False, plotPeaks = False, labelCycles = []):
def plotArea(self, plotCycles = False, plotPeaks = False, labelCycles = [], **kwargs):

x = self.xy[:,0]
y = self.area

self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles)
self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles, **kwargs)

def plotCumArea(self, plotCycles = False, plotPeaks = False, labelCycles = []):
def plotCumArea(self, plotCycles = False, plotPeaks = False, labelCycles = [], **kwargs):

# We get the cumulative displacement and area
x = self.getCumDisp()
y = self.getCumArea()

self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles)
self.plotFunction(self, x ,y, plotCycles, plotPeaks, labelCycles, **kwargs)

def initFig(self, xlims = [], ylims = []):
return self.initializeFig(xlims, ylims)


def _getOperand(curve):
"""
Gets the operand (what data the function acts on) for operation functions.
The data used depands on the input given
In the future, a strategy pattern could be used to replace this.
"""
if not hasattr(curve, '__len__'): # assume scalar if no length
operand = curve
elif hasattr(curve, 'xy'): # use the xy if it's a hysteresis curve
operand = curve.xy[:,1]
elif isinstance(curve, np.ndarray):
if 1 == len(curve.shape):
operand = curve
elif 2 == len(curve.shape) and curve.shape[-1] == 2: # if 2D array
operand = curve[:,1]
else: # if 1D array
raise Exception(f'{curve.shape[-1]}D curve give, only 1 or 2D supported')
return operand

# TODO:
# Make the Hysteresis object take in the optional arguements as well. This
# Curretnly will not work for non-basic funcitons.
Expand Down Expand Up @@ -376,8 +419,11 @@ def plotCycles(self, Cycles = [], plotCycles = False, plotPeaks = False,

def recalculateCycles(self, revDist = 2, revWidth = None, revProminence = None, **kwargs):
"""
Calcualtes the cycles again, using the input parameters for distance,
width, and prominence. Peaks are calculated using scipy's find_peaks function.
Calcualtes the cycles again, using the input parameters for distance
(number of indexes), width (distance on the x axis), and prominence
(distance in the y axis).
Peaks are calculated using scipy's find_peaks function.
Parameters
----------
Expand Down Expand Up @@ -442,9 +488,13 @@ def recalculateCycles_like(self, sampleHysteresis):
def recalculateCycles_dist(self, revDist = 2, revWidth = None,
revProminence = None, **kwargs):
"""
Recalulates the reversals of one hysteresis using another the reversal
propreties from another hysteresis. Peaks are calculated using scipy's
find_peaks function.
Calcualtes the cycles again, using the input parameters for distance
(number of indexes), width (distance on the x axis), and prominence
(distance in the y axis).
The instead of the xy curve, the secant length between each point on
the curve is used to find revesal indexes.
Peaks are calculated using scipy's find_peaks function.
Parameters
----------
Expand Down
8 changes: 7 additions & 1 deletion doc/readthedocs/hysteresis/Backups/baseFuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,10 @@ def removeNegative(Curve):

Output = _RemoveNeg(x, y, direction)

return Output
return Output




# def get

4 changes: 2 additions & 2 deletions doc/readthedocs/hysteresis/Backups/defaultPlotFuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def defaultShowCycles(self, x, y, plotCycles, plotPeaks, labelCycles = [], Cycle
# Annotate = plt.annotate(int(Cycle), xy=(ReversalX[ii], ReversalY[ii]), xytext=(-1, 5), textcoords = 'offset points', fontsize=12)
# Annotate = plt.annotate(int(ii), xy=(ReversalX[ii], ReversalY[ii]))

def defaultPlotFunction(self, x, y, plotCycles, plotPeaks, labelCycles = []):
def defaultPlotFunction(self, x, y, plotCycles, plotPeaks, labelCycles = [], **kwargs):
"""
Parameters
----------
Expand All @@ -132,7 +132,7 @@ def defaultPlotFunction(self, x, y, plotCycles, plotPeaks, labelCycles = []):

# fig, ax = initializeFig(xlim, ylim)

line, = plt.plot(x, y)
line, = plt.plot(x, y, **kwargs)

defaultShowCycles(self, x, y, plotCycles, plotPeaks, labelCycles)

Expand Down
2 changes: 1 addition & 1 deletion doc/readthedocs/hysteresis/Backups/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def fitEEEP(backbone):
"""
Fits a backbone curve with a equivalent elastic perfectly plastic curve
using the ASTM E2126 methodology.
The cirve has equivalent area to the input backone curve.
The curve has equivalent area to the input backone curve.
http://www.materialstandard.com/wp-content/uploads/2019/10/E2126-11.pdf
Expand Down
Loading

0 comments on commit fa8204e

Please sign in to comment.