Getting the information about the SN curve

Because there is various methods that modify the SN curve definition, you may want to check the current SN curve parameters. Some of following methods can be used.

The simplest way is to use built-in method print() on a SN_Curve instance or on any attribute.

sn = SN_curve.SN_Curve(SD=250, S1=500, k1=9, k=5, ND=2e6, M=0.22, R=0.4, meanCorrType="goodman", miner="haibach")
print(sn)

# output:
#SD............. 250.00
#ND............. 2000000.00
#k.............. 5.00
#S1............. 500.00
#N1............. 62500.00
#k1............. 9.00
#miner.......... haibach
#R.............. 0.40
#M.............. 0.22
#meanCorrType... goodman

print(sn.M)
# 0.22

dictionary

There is an attribute sn_parms that returs dictionary. Similar way with some more functionality is the method get_SN_parameters(). It returns the dictionary with all the SN parameters and you can also request the recalculation to R ratio equal to -1.

get_SN_parameters(self, Rmin1=False, verbose=False):

Parameters
----------
Rmin1 : bool
    default : false
    if true, SD and S1 will be recalculated to R-ratio -1

verbose : bool
    if True, prints recalculated SN-curve amplitudes to R=-1 (used for calculation),
    default: False


Returns
-------
    dictionary with SN-curve parameters ("k", "k1", "ND", "SD", "S1", "miner", "M", "R", "meanCorrType")
sn = SN_curve.SN_Curve(SD=250, S1=500, k1=9, k=5, ND=2e6, M=0.22, R=0.4, meanCorrType="goodman", miner="haibach")
print(sn.sn_parms)
#{'k': 5, 'k1': 9, 'S1': 500, 'SD': 250, 'N1': 62500.0, 'ND': 2000000.0, 'miner': 'haibach', 'meanCorrType': 'goodman', 'M': 0.22, 'R': 0.4}     

plotting sn curve

There is a method plot() that takes an existing matplotlib pyplot axes and plot the sn curve in. There is several options like settings the x,y limits, plotting the infobox with sn parameters, settings the axis scaling ...

plot(self, ax, title=None, fmt_string="b-", propbox=(0.98, 0.85), scale=("log","log"), xlim=True, ylim=True):

Parameters
----------
ax : matplotlib pyplot axis
    existing axis of matplotlib pyplot plot

title : string
    title of the grahp

fmt_string: string
    format string for the sn curve line

propbox : tuple of 2 floats
    (x, y) ... coordinates of upper right corner of the box with the sn parameters
    set it to None, if the sn parameters shouldn't be printed

scale : tuple of two strings
    scale of x and y axis
    useful options: {'linear', 'log', ...}

xlim : bool or tuple of limits
    if True - limits are estimated and set
    if False - limits are not set
    if tuple - given limits are set

ylim : bool or tuple of limits
    if True - limits are estimated and set
    if False - limits are not set
    if tuple - given limits are set

Returns
-------
None

see the usage example below

from matplotlib import pyplot as plt
sn = SN_curve.SN_Curve(k=5, ND=1e6,  S1=1500 ,SD=500, k1=15, M=0.0, R=-1)
sn.name = "name of the curve"
# create an plot axis
fig, ax = plt.subplots(figsize=(10,8))

# sn.plot(ax) ... minimum example
sn.plot(ax, title="Title of the plot", propbox=None, xlim=(1000,1e7))

plt.show()

sn curve points

If you wish to just get SN points to plot it in another way, use the roperty (attribute) sn_points. It returns the pandas DataFrame with two columns "N" and "a" (amplitude). There is 100 log-distributed SN points. If you need some more functionality like getting the sn points for R=-1 without modification of the SN curve, use the method get_woehler_points().

get_woehler_points(self, Rmin1=False, plot_string=False, verbose=False):

Parameters
----------
Rmin1 : bool
    default : false
    if true, SD and S1 will be recalculated to R-ratio -1

plot_string : bool
    default : false
    if true, method will print the matplotlib plot template

verbose : bool
    if True, prints recalculated SN-curve amplitudes to R=-1 (used for calculation),
    default: False

Returns
-------
df : pd.DataFrame
    with columns "N" and "a"

minimum example:

from matplotlib import pyplot as plt
sn = SN_curve.SN_Curve(SD=250, S1=500, k1=9, k=5, ND=2e6, M=0.22, R=0.4, meanCorrType="goodman", miner="haibach")
plt.plot(sn.sn_points.N, sn.sn_points.a)
plt.show()     

get_amp(N), get_N(amp) methods

Method get_amp() returns amplitude for given number of cycles, get_N() returns number of cycles for given amplitude(s). If the iterable is given as the parameter, numpy array of points laying on the sn curve is returned. If a float is given, then float is returned.

sn = SN_curve.SN_Curve(SD=250, S1=500, k1=9, k=5, ND=2e6, M=0.22, R=0.4, meanCorrType="goodman", miner="haibach")
print(sn.get_amp((1e7,500,5e5)))
# [209.06275774 854.98797334 329.87697769]
print(sn.get_N(600))
# 199364.01796171142