def on_weibull(self, event): """Extreme value analysis - Maximum Weibull distribution""" season = wx.GetSingleChoice("Select a season to analyze:", "Select season", ["Winter", "Summer", "Spring", "Fall"]) if season: ms = MONTHS[season] str_coords = wx.GetTextFromUser("Coordinates (lon, lat):", default_value="-74.85,11.11") str_lon, str_lat = str_coords.split(",") lon = float(str_lon) lat = float(str_lat) if lon < 0: lon = 360 + lon progress_dlg = wx.ProgressDialog( "Read and analyze", "Reading and analyzing wave data...") progress_dlg.Pulse() fname = f"tmp/hs-peaks-{season}-{lon}-{lat}.tmp" try: peaks_hs = load_obj(fname) except FileNotFoundError: peaks_hs = weibull_data("hs", ms, lon, lat) save_obj(peaks_hs, fname) progress_dlg.Update(100) analysis = weibull.Analysis(peaks_hs, unit="m") analysis.fit() analysis.probplot()
def test_censored_dataset(): current_run_time = 4200.0 fail_times = [current_run_time] * 10 fail_times[7] = 1034.5 fail_times[8] = 2550.9 fail_times[6] = 3043.4 suspended = [True, True, True, True, True, False, False, False, True, True] analysis = weibull.Analysis(fail_times, suspended=suspended, unit='hour') analysis.fit() assert 1.5 < analysis.beta < 1.6 assert 6500.0 < analysis.eta < 6630
def test_non_fitted(): """ Tests for proper fail condition if beta and eta do not exist :return: None """ analysis = weibull.Analysis([0], [False]) assert analysis.beta is None assert analysis.eta is None with pytest.raises(weibull.ParameterError): analysis.probplot() with pytest.raises(weibull.ParameterError): analysis.pdf() with pytest.raises(weibull.ParameterError): analysis.sf() with pytest.raises(weibull.ParameterError): analysis.hazard() with pytest.raises(weibull.ParameterError): analysis.cdf() with pytest.raises(weibull.ParameterError): analysis.fr() with pytest.raises(weibull.ParameterError): analysis.b(10) with pytest.raises(weibull.ParameterError): m = analysis.mean with pytest.raises(weibull.ParameterError): m = analysis.mttf with pytest.raises(weibull.ParameterError): m = analysis.median with pytest.raises(weibull.ParameterError): m = analysis.characteristic_life
def test_complete_dataset(): """ Tests basic calculation of beta and eta for a complete data set along with some misc. functionality based on the presence of beta and eta. :return: """ fail_times = [ 9402.7, 6082.4, 13367.2, 10644.6, 8632.0, 3043.4, 12860.2, 1034.5, 2550.9, 3637.1 ] analysis = weibull.Analysis(fail_times) analysis.fit() assert 1.345 < analysis.beta < 1.355 assert 8100.0 < analysis.eta < 8160.0 assert 1500.0 < analysis.b(10) < 1600 assert 7400.0 < analysis.mttf < 7500 assert 8100.0 < analysis.eta < 8160.0
""" Emulates the example in the book Weibull Analysis by Bryan Dodson Data is sourced from page 22, table 2.5. The author's estimation was based on a probability plot and resulted in a beta of 2.974 and eta of 203.3 vs. this package's beta of 3.47 with an eta of 187.9 using linear regression and 2.97 and 203.3 using maximum likelihood estimation. """ import weibull fail_times = [ 42.1, 105.9, 151.3, 195.6, 77.8, 117.0, 157.3, 207.0, 83.3, 126.9, 163.8, 215.3, 88.7, 138.7, 177.2, 217.4, 101.8, 148.9, 194.3, 258.8 ] suspensions = [1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1] # this is where the actual analysis and curve fitting occur analysis = weibull.Analysis(fail_times, suspensions, unit='hour') analysis.fit(method='mle', confidence_level=0.6) print(analysis.stats) analysis.probplot(file_name='gallery-probplot.png') analysis.pdf(file_name='gallery-pdf.png') analysis.hazard(file_name='gallery-hazard.png') analysis.sf(file_name='gallery-survival.png') analysis.fr(file_name='gallery-fr.png')
df = pd.read_csv(Archivo, index_col= False) df["Fecha"] = pd.to_datetime(df["Fecha"]) for i in range(0,7): # generando la mascara mask = df.Fecha.dt.weekday == i dfaux = df.loc[mask] plt.subplots_adjust(hspace=0.9) plt.subplot(2,1,1) count, bins, ignored = plt.hist(dfaux["Viento - Velocidad (m/s)"],bins=range(0,23) ) # plt.close() data=dfaux["Viento - Velocidad (m/s)"] y,x,_=hist(data,range(0,23),label='data') print(count," ",bins) print(y, " " ,x) x=(x[1:]+x[:-1])/2 # for len(x)==len(y) analysis = weibull.Analysis(dfaux["Viento - Velocidad (m/s)"], unit = "m/s") analysis.fit(method='mle') # Capturando los parametros de weibull forma = analysis.stats[3] escala = analysis.stats[6] xx = np.linspace(min(dfaux["Viento - Velocidad (m/s)"]),max(dfaux["Viento - Velocidad (m/s)"]),sum(count)) scale = count.max()/weib(xx,escala ,forma).max() plt.plot(xx, weib(xx,escala,forma)*scale,'-b', label = 'Weibull') # count, bins, ignored = plt.hist(dfaux["Viento - Velocidad (m/s)"],bins=range(0,int(dfaux["Viento - Velocidad (m/s)"].max()+2))) # Parametros de Bimodal params,cov=curve_fit(bimodal,x,y) sigma=sqrt(diag(cov)) plot(xx,bimodal(xx,*params),color='green',lw=3,label='Bimodal') plt.xlabel("Vel. Viento [m/s]") plt.ylabel("Distribution")
dfauxs = dfs[mascara2] aux = np.zeros(dfaux.shape[0]) auxt = np.zeros(df.shape[0]) plt.subplots_adjust(hspace=0.9) plt.subplot(2, 1, 1) count, bins, ignored = plt.hist(dfaux["Viento - Velocidad (m/s)"], bins=range(0, 23), density=True) data = dfaux["Viento - Velocidad (m/s)"] y, x, _ = hist(data, range(0, 23), label='Datos Observados', density=True) print(count, " ", bins) print(y, " ", x) x = (x[1:] + x[:-1]) / 2 # for len(x)==len(y) analysis = weibull.Analysis(dfaux["Viento - Velocidad (m/s)"], unit="m/s") analysis.fit(method='mle') # Capturando los parametros de weibull forma = analysis.stats[3] escala = analysis.stats[6] xx = np.linspace(min(dfaux["Viento - Velocidad (m/s)"]), max(dfaux["Viento - Velocidad (m/s)"]), sum(count)) print(x) scale = count.max() / weib(x, escala, forma).max() plt.plot(x, weib(x, escala, forma), '-b', label='Weibull') #****************************************************************** # Datos simulados #****************************************************************** # Archivo = 'df_marzoCorr.csv' # dfs = pd.read_csv(Archivo, index_col= False)
import weibull # the current run time of the test or the # time that the test was suspended completely current_run_time = 4200.0 fail_times = [current_run_time] * 10 fail_times[7] = 1034.5 fail_times[8] = 2550.9 fail_times[6] = 3043.4 suspended = [True, True, True, True, True, False, False, False, True, True] analysis = weibull.Analysis(fail_times, suspended=suspended, unit='hour') analysis.fit() analysis.probplot(show=False) # beta and eta may be directly manipulated to try out different hypotheses analysis.beta = 2.0 analysis.eta = 5000 analysis.probplot() print(f'beta: {analysis.beta}\teta: {analysis.eta}') print(f'B2 life: {analysis.b(2):.02f}\nB10 life: {analysis.b(10):.02f}\nB50 life: {analysis.b(50):.02f}') print(f'median: {analysis.median}') print(f'mean: {analysis.mean}') print(f'mttf: {analysis.mttf}')
import weibull # fail times include no censored data fail_times = [ 9402.7, 6082.4, 13367.2, 10644.6, 8632.0, 3043.4, 12860.2, 1034.5, 2550.9, 3637.1 ] # this is where the actual analysis and curve fitting occur analysis = weibull.Analysis(fail_times, unit='hour') analysis.fit() analysis.probplot() analysis.hazard(file_name='hazard.png') print(analysis.stats)
""" This file being used to generate some of the plots for the documentation """ import weibull plotter = weibull.Analysis([0], [False]) # Linearized CDF comparison plotter.beta = 0.5 plotter.eta = 1.0 plotter.probplot(show=False) plotter.beta = 1.0 plotter.probplot(show=False) plotter.beta = 2.0 plotter.probplot(file_name='beta-effects-on-log-cdf.png') # PDF comparison plotter.beta = 0.5 plotter.pdf(show=False) plotter.beta = 1.0 plotter.pdf(show=False) plotter.beta = 2.0 plotter.pdf(file_name='beta-effects-on-pdf.png') # failure rate comparison plotter.beta = 0.5 plotter.fr(show=False)