master
Per A Brodtkorb 8 years ago
parent 2677537948
commit 3472a720e1

@ -211,14 +211,23 @@ def nt2cmat(nt, kind=1):
if kind == 1: if kind == 1:
I = np.r_[0:n - 1] I = np.r_[0:n - 1]
J = np.r_[1:n] J = np.r_[1:n]
c = nt[I+1][:, J-1] - nt[I][:, J-1] - nt[I+1][:, J] + nt[I][:, J] c = nt[I + 1][:,
J - 1] - nt[I][:,
J - 1] - nt[I + 1][:,
J] + nt[I][:,
J]
c2 = np.vstack((c, np.zeros((n - 1)))) c2 = np.vstack((c, np.zeros((n - 1))))
cmat = np.hstack((np.zeros((n, 1)), c2)) cmat = np.hstack((np.zeros((n, 1)), c2))
elif kind == 11: # same as def=1 but using for-loop elif kind == 11: # same as def=1 but using for-loop
cmat = np.zeros((n, n)) cmat = np.zeros((n, n))
j = np.r_[1:n] j = np.r_[1:n]
for i in range(n - 1): for i in range(n - 1):
cmat[i, j] = nt[i+1, j-1] - nt[i, j-1] - nt[i+1, j] + nt[i, j] cmat[i,
j] = nt[i + 1,
j - 1] - nt[i,
j - 1] - nt[i + 1,
j] + nt[i,
j]
else: else:
_raise_kind_error(kind) _raise_kind_error(kind)
return cmat return cmat
@ -604,7 +613,6 @@ def mc2rfc(f_xy, paramv=None, paramu=None):
if paramv is None: if paramv is None:
paramv = (-1, 1, N) paramv = (-1, 1, N)
if paramu is None: if paramu is None:
paramu = paramv paramu = paramv
@ -617,8 +625,10 @@ def mc2rfc(f_xy, paramv=None, paramu=None):
for i in range(N): for i in range(N):
Spm = Sminus[i] + Splus[i] - dd[i] Spm = Sminus[i] + Splus[i] - dd[i]
if Spm > 0: if Spm > 0:
Max_rfc[i]=(Splus[i]-dd[i])*(Splus[i]-dd[i])/(1-dd[i]/Spm)/Spm Max_rfc[i] = (Splus[i] - dd[i]) * \
Min_rfc[i]=(Sminus[i]-dd[i])*(Sminus[i]-dd[i])/(1-dd[i]/Spm)/Spm (Splus[i] - dd[i]) / (1 - dd[i] / Spm) / Spm
Min_rfc[i] = (Sminus[i] - dd[i]) * \
(Sminus[i] - dd[i]) / (1 - dd[i] / Spm) / Spm
norm[i] = Spm norm[i] = Spm
# end if # end if
# end for # end for
@ -671,7 +681,6 @@ def mc2rfc(f_xy, paramv=None, paramu=None):
AA = np.rot90(AA) AA = np.rot90(AA)
AA = AA - 0.5 * np.diag(np.diag(AA)) AA = AA - 0.5 * np.diag(np.diag(AA))
for j in range(nA): for j in range(nA):
if normA[j] != 0: if normA[j] != 0:
AA[j, :] = AA[j, :] / normA[j] AA[j, :] = AA[j, :] / normA[j]
@ -680,7 +689,8 @@ def mc2rfc(f_xy, paramv=None, paramu=None):
# end for # end for
fx = 0. fx = 0.
if np.max(np.abs(e)) > 1e-7 and np.max(np.abs(NN)) > 1e-7*MA_rfc[0]: if np.max(
np.abs(e)) > 1e-7 and np.max(np.abs(NN)) > 1e-7 * MA_rfc[0]:
I = np.eye(np.shape(AA)) I = np.eye(np.shape(AA))
if nA == 1: if nA == 1:
@ -695,7 +705,7 @@ def mc2rfc(f_xy, paramv=None, paramu=None):
# end # end
# end # end
m0 = np.maximum(0, Min_rfc[N] - sum(f_rfc[N - k + 1:N, 0])) m0 = np.maximum(0, Min_rfc[N] - sum(f_rfc[N - k + 1:N, 0]))
M0 = np.maximum(0, Max_rfc[N-k]-sum(f_rfc[N-k, 1:k])); M0 = np.maximum(0, Max_rfc[N - k] - sum(f_rfc[N - k, 1:k]))
f_rfc[N - k, 0] = min(m0, M0) f_rfc[N - k, 0] = min(m0, M0)
# n_loops_left=N-k+1 # n_loops_left=N-k+1
# end for # end for
@ -851,7 +861,7 @@ def cmatplot(cmat, ux=None, uy=None, method=1, clevels=None):
F = cmat F = cmat
shape = np.shape(F) shape = np.shape(F)
if ux is None: if ux is None:
ux = np.arange(shape[1]); # Antalet kolumner ux = np.arange(shape[1]) # Antalet kolumner
if uy is None: if uy is None:
uy = np.arange(shape[0]) # Antalet rader uy = np.arange(shape[0]) # Antalet rader
@ -861,17 +871,25 @@ def cmatplot(cmat, ux=None, uy=None, method=1, clevels=None):
if method in [5, 15]: if method in [5, 15]:
clevels = Fmax * np.r_[0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0] clevels = Fmax * np.r_[0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0]
else: # 4, 14 else: # 4, 14
clevels = Fmax*np.r_[0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.4, 0.6, 0.8] clevels = Fmax * np.r_[0.005,
0.01,
0.02,
0.05,
0.1,
0.2,
0.4,
0.6,
0.8]
# Make sure ux and uy are row vectors # Make sure ux and uy are row vectors
ux = ux.ravel(); ux = ux.ravel()
uy = uy.ravel(); uy = uy.ravel()
n = len(F) n = len(F)
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
if method == 1: # mesh if method == 1: # mesh
F = np.flipud(F.T); # Vrid cykelmatrisen for att plotta rett F = np.flipud(F.T) # Vrid cykelmatrisen for att plotta rett
plt.mesh(ux, np.fliplr(uy), F) plt.mesh(ux, np.fliplr(uy), F)
plt.xlabel('min') plt.xlabel('min')
plt.ylabel('Max') plt.ylabel('Max')
@ -1087,6 +1105,7 @@ def cmatplot(cmat, ux=None, uy=None, method=1, clevels=None):
# #
# end % _cmatplot # end % _cmatplot
def arfm2mctp(Frfc): def arfm2mctp(Frfc):
""" """
ARFM2MCTP Calculates the markov matrix given an asymmetric rainflow matrix. ARFM2MCTP Calculates the markov matrix given an asymmetric rainflow matrix.
@ -1148,11 +1167,10 @@ def arfm2mctp(Frfc):
# The cond. prob. pS1, pS2, pS3, pH1, pH2, pH3 are calculated using # The cond. prob. pS1, pS2, pS3, pH1, pH2, pH3 are calculated using
# the elementary cond. prob. C, E, R, D, E3, Ch, Eh, Rh, Dh, E3h. # the elementary cond. prob. C, E, R, D, E3, Ch, Eh, Rh, Dh, E3h.
# T(1,:)=clock; # T(1,:)=clock;
N = np.sum(Frfc) N = np.sum(Frfc)
Frfc = Frfc/N; Frfc = Frfc / N
n = len(Frfc) # Number of levels n = len(Frfc) # Number of levels

Loading…
Cancel
Save