From bd4265bc18506697c0990f55860ab4808d5878fd Mon Sep 17 00:00:00 2001 From: Per A Brodtkorb Date: Wed, 29 Jun 2016 00:33:10 +0200 Subject: [PATCH] Added tutorial_init.py and moved rainflow_example to tutorial scripts --- .../rainflow_example.py | 33 ++++++++----------- wafo/doc/tutorial_scripts/tutor_init.py | 27 +++++++++++++++ 2 files changed, 41 insertions(+), 19 deletions(-) rename wafo/doc/{ => tutorial_scripts}/rainflow_example.py (83%) create mode 100644 wafo/doc/tutorial_scripts/tutor_init.py diff --git a/wafo/doc/rainflow_example.py b/wafo/doc/tutorial_scripts/rainflow_example.py similarity index 83% rename from wafo/doc/rainflow_example.py rename to wafo/doc/tutorial_scripts/rainflow_example.py index 2234fc9..c8da33f 100644 --- a/wafo/doc/rainflow_example.py +++ b/wafo/doc/tutorial_scripts/rainflow_example.py @@ -1,7 +1,4 @@ -#from tutor_init import * -import numpy as np -import logging -import matplotlib.pyplot as plt +from tutor_init import * import itertools # import sys log = logging.getLogger(__name__) @@ -10,10 +7,6 @@ log.setLevel(logging.DEBUG) MARKERS = ('o', 'x', '+', '.', '<', '>', '^', 'v') -def set_windows_title(title='', log=None): - pass - - def plot_varying_symbols(x, y, color='red', size=5): """ Create a plot with varying symbols @@ -60,11 +53,11 @@ Tlength = xx_sea[-1, 0] - xx_sea[0, 0] beta = 3 K1 = 6.5e-31 Np = 200 -Tp = Tlength/Np +Tp = Tlength / Np A = 100e6 log.info("setting sin wave with Tp={} and T={}".format(Tp, Tlength)) Nc = 1.0 / damage_vs_S(A, beta, K1) -damage = float(Np)/float(Nc) +damage = float(Np) / float(Nc) log.info("budget at S={} N={}: damage = {} ".format(A, Nc, damage)) #xx_sea[:, 1] = A * np.cos(2 * np.pi * xx_sea[:, 0]/Tp) xx_sea[:, 1] *= 500e6 @@ -76,13 +69,13 @@ tp = ts.turning_points() mM = tp.cycle_pairs(kind='min2max') Mm = tp.cycle_pairs(kind='max2min') lc = mM.level_crossings(intensity=True) -T_sea = ts.args[-1]-ts.args[0] +T_sea = ts.args[-1] - ts.args[0] -#for i in dir(mM): +# for i in dir(mM): # print(i) -ts1 = wo.mat2timeseries(xx_sea[:,:]) +ts1 = wo.mat2timeseries(xx_sea[:, :]) tp1 = ts1.turning_points() sig_tp = ts.turning_points(h=0, wavetype='astm') try: @@ -113,7 +106,7 @@ else: i_min_start = 2 m_rfc, M_rfc = mM_rfc.get_minima_and_maxima() -#m_rfc_a, M_rfc_a = mM_rfc_a.get_minima_and_maxima() +# m_rfc_a, M_rfc_a = mM_rfc_a.get_minima_and_maxima() ts1.plot('b-') if rfc_plot: plot_varying_symbols(tp_rfc.args[0::2], m_rfc, color='red', size=10) @@ -144,11 +137,11 @@ ampRFC_sea = mM_rfc.amplitudes() plt.figure() title = "s_n_curve" set_windows_title(title) -S = np.linspace(1e6,1000e6) +S = np.linspace(1e6, 1000e6) plt.loglog(S, damage_vs_S(S, beta, K1)) plt.figure() plt.subplot(121) -stress_range = (1,1e9) +stress_range = (1, 1e9) n_bins = 100 wm.plot_histgrm(ampmM_sea, bins=n_bins, range=stress_range) plt.xlim(stress_range) @@ -156,14 +149,16 @@ ylim = plt.gca().get_ylim() plt.title('min-max amplitude distribution') plt.subplot(122) if sig_cp is not None: - wm.plot_histgrm(sig_cp[:, 0],bins=n_bins, range=stress_range) + wm.plot_histgrm(sig_cp[:, 0], bins=n_bins, range=stress_range) plt.gca().set_ylim(ylim) title = 'Rainflow amplitude distribution' plt.title(title) plt.semilogy set_windows_title(title) - hist, bin_edges = np.histogram(sig_cp[:, 0], bins=n_bins, range=stress_range) + hist, bin_edges = np.histogram( + sig_cp[ + :, 0], bins=n_bins, range=stress_range) plt.figure() title = "my_bins" @@ -171,7 +166,7 @@ if sig_cp is not None: plt.title(title) set_windows_title(title) plt.semilogy - plt.bar(bin_edges[:-1], hist, width=stress_range[1]/n_bins) + plt.bar(bin_edges[:-1], hist, width=stress_range[1] / n_bins) print("damage min/max : {}".format(mM_rfc.damage([beta], K1))) diff --git a/wafo/doc/tutorial_scripts/tutor_init.py b/wafo/doc/tutorial_scripts/tutor_init.py new file mode 100644 index 0000000..849f589 --- /dev/null +++ b/wafo/doc/tutorial_scripts/tutor_init.py @@ -0,0 +1,27 @@ +import logging +import scipy as sp +import numpy as np +from numpy import pi, reshape +import matplotlib.pyplot as plt +import matplotlib +matplotlib.use('Qt4Agg') +from matplotlib import rcParams +rcParams.update({"font.size": 10}) + + +try: + from win32api import LoadResource +except ImportError: + pass + +log = logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", + level=logging.DEBUG) + + +def set_windows_title(title, log=None): + if log is not None: + log.info("Set windows title {}".format(title)) + fig = plt.gcf() + fig.canvas.set_window_title(title) + plt.show()