iam-git / WellMet (public) (License: MIT) (since 2021-08-31) (hash sha1)
WellMet is pure Python framework for spatial structural reliability analysis. Or, more specifically, for "failure probability estimation and detection of failure surfaces by adaptive sequential decomposition of the design domain".

/mplot/mgraph.py (4a019311842e909970b3ef5d1b1d14e39ab9a26a) (9852 bytes) (mode 100644) (type blob)

#!/usr/bin/env python
# coding: utf-8


#č nazvy proměnných jsou v angličtině
#č Ale komenty teda ne)

#č otázkou je, kdo je uživatelem modulu.
#č zatím ho potřebujou jenom vnejší skripty, 
#č které dostávájí data z csv souborů a žádné skřiňky nevytvařejí.
#č Proto funkce v tomto modulu zatím-prozátím nebudou spolehát na
#č ax.sample_box

from scipy import stats # for tri_beta_plot

#č sehnaní datarámu necháme uživateli
def tri_estimation_fill(ax, df):
    #xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5
    green = "#A7FFB5"
    #xkcd_red   = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
    red   = "#FDC1C5"
    #xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a)
    cream = "#FFF39A"
    grey = "#DDDDDD"
    
    o = df['outside'].to_numpy()
    s = df['success'].to_numpy()
    f = df['failure'].to_numpy()
    m = df['mix'].to_numpy()
    kwargs = {'colors': (red, cream, grey, green),
            'labels': ("failure domain", "mixed domain",\
             "outside domain", "success domain")}
    if len(df.index) > 1000:
        kwargs['rasterized'] = True
    return ax.stackplot(df.index, f, m, o, s, **kwargs)


#č sehnaní datarámu necháme uživateli
#
#č musím trochu davat bacha,
#č externí skripta df-ko vytvařejí sámi jak chcou
#č proto se nemá obecně spolehat na korektní index
def shell_estimation_fill(ax, df, use_df_index=False):
    if use_df_index:
        x = df.index
    else:
        x = df['nsim'].to_numpy()
    
    shell_color = "#ECCEAF"  #"#FFFD95"
    outer_color = "#CCCCCC"
    colors = (outer_color, shell_color)
    outer = df['outer'].to_numpy()
    shell = outer + df['shell'].to_numpy()
    labels = ("outer", "annulus")
    return ax.stackplot(x, outer, shell, labels=labels, colors=colors)


#č sehnaní datarámu necháme uživateli
# inverted
def trii_estimation_fill(ax, df):
    #xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5
    green = "#A7FFB5"
    #xkcd_red   = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
    red   = "#FDC1C5"
    #xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a)
    cream = "#FFF39A"
    grey = "#DDDDDD"
    colors = (grey, red, cream, green)
    o = df['outside'].to_numpy()
    s = df['success'].to_numpy()
    f = df['failure'].to_numpy()
    m = df['mix'].to_numpy()
    labels = ("out of sampling domain estimation", "failure domain estimation",\
             "mixed simplices measure", "success domain estimation")
    return ax.stackplot(df.index, o, f, m, s, labels=labels, colors=colors)


#č ok, tak uděláme všecko dohromady
#č datarám, jako vždy, uživatel donese svůj vlastní
def tri_estimation_plot(ax, df, pf_exact=None, pf_exact_method="$p_f$",
                         plot_outside=True, plot_mix=True, **kwargs):
    # some default values
#    if not ax.get_xlabel():
#        ax.set_xlabel('Number of simulations')
#    if not ax.get_ylabel():
#        ax.set_ylabel('Probability measure')
        
    # fill
    tri_estimation_fill(ax, df)
    
    #č blbost, ale uspořadal jsem tu prvky tak,
    #č aby se hezky kreslily v legendě
    
    if (len(df.index) > 1000) and ('rasterize' not in kwargs):
        kwargs['rasterized'] = True
        
    v = df['vertex_estimation'].to_numpy()
    wv = df['weighted_vertex_estimation'].to_numpy()
    ax.plot(df.index, wv, '-r', label="weighted $p_f$ estimation", zorder=100500, **kwargs)
    ax.plot(df.index, v, '-m', label="simple $p_f$ estimation", zorder=10500, **kwargs)
    
    
    #č teď čáry
    if plot_outside:
        o = df['outside'].to_numpy()
        ax.plot(df.index, o, '-', color="#AAAAAA", \
                label="outside domain estimation", zorder=150, **kwargs)
                
    if plot_mix:
        m = df['mix'].to_numpy()
        ax.plot(df.index, m, '-', color="#FF8000", \
                label="mixed domain estimation", zorder=1050, **kwargs)
    
    if pf_exact is not None:
        ax.axhline(pf_exact, c='b', label=pf_exact_method, **kwargs)
    

#č ok, tak uděláme všecko dohromady
#č datarám, jako vždy, uživatel donese svůj vlastní
def tri_beta_plot(ax, df, pf_exact=None, pf_exact_method="$p_f$",
                         plot_outside=True, plot_mix=True, **kwargs):
    
    #č blbost, ale uspořadal jsem tu prvky tak,
    #č aby se hezky kreslily v legendě
    
    v = -stats.norm.ppf(df['vertex_estimation'].to_numpy())
    wv = -stats.norm.ppf(df['weighted_vertex_estimation'].to_numpy())
    ax.plot(df.index, wv, '-r', label="weighted $p_f$ estimation", zorder=100500, **kwargs)
    ax.plot(df.index, v, '-m', label="simple $p_f$ estimation", zorder=10500, **kwargs)
    
    
    #č teď čáry
    if plot_outside:
        o = -stats.norm.ppf(df['outside'].to_numpy())
        ax.plot(df.index, o, '-', color="#AAAAAA", \
                label="outside domain estimation", zorder=150, **kwargs)
                
    if plot_mix:
        m = -stats.norm.ppf(df['mix'].to_numpy())
        ax.plot(df.index, m, '-', color="#FF8000", \
                label="mixed domain estimation", zorder=1050, **kwargs)
    
    if pf_exact is not None:
        ax.axhline(-stats.norm.ppf(pf_exact), c='b', label=pf_exact_method, **kwargs)

    

#č ok, tak uděláme všecko dohromady
#č datarám, jako vždy, uživatel donese svůj vlastní
def shell_estimation_plot(ax, df, use_df_index=False, **kwargs):
    
    # fill
    shell_estimation_fill(ax, df, use_df_index)
    
    #č teď čáry
    if use_df_index:
        x = df.index
    else:
        x = df['nsim'].to_numpy()
    
    #č je to ten opravdový outside z tri plot 
    #č ponecháme i jeho původní barvu
    o = df['outside'].to_numpy()
    ax.plot(x, o, '-', color="#AAAAAA", \
            label="outside estimation", **kwargs)
    
    y = df['FORM_outside'].to_numpy()
    ax.plot(x, y, '-', color="tab:purple", \
            label="hyperplane outside approximation", **kwargs)
    
    y = df['2FORM_outside'].to_numpy()
    ax.plot(x, y, '-', color="tab:pink", \
            label="two hyperplanes outside approximation", **kwargs)
    
    y = df['orth_outside'].to_numpy()
    ax.plot(x, y, '-', color="tab:brown", \
            label="hypercube outside approximation", **kwargs)


#č ok, tak uděláme všecko dohromady
#č datarám, jako vždy, uživatel donese svůj vlastní
def trii_estimation_plot(ax, df, pf_exact=None, pf_exact_method="$p_f$"):
    # some default values
#    if not ax.get_xlabel():
#        ax.set_xlabel('Number of simulations')
#    if not ax.get_ylabel():
#        ax.set_ylabel('Probability measure')
    # fill
    trii_estimation_fill(ax, df)
    
    #č teď čáry
    v = df['vertex_estimation'].to_numpy()
    wv = df['weighted_vertex_estimation'].to_numpy()
    # v trii grafu máme outside zdolu
    mask = v > 0
    o = df['outside'].to_numpy()[mask]
    vo = v[mask] + o
    wvo = wv[mask] + o
    ax.plot(df.index[mask], vo, '-m', label="simple $p_f$ estimation")
    ax.plot(df.index[mask], wvo, '-r', label="weighted $p_f$ estimation")
    
    if pf_exact is not None:
        ax.axhline(pf_exact, c='b', label=pf_exact_method)
    
    
        
##xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5
#green = (0, 255, 38, 96) 
##xkcd_red   = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
#red   = (253, 0, 17, 96)
##xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a)
#cream = (255, 221, 0, 96)
#grey = (196, 196, 196, 96)
        
class SimplexErrorGraph:
        
            
    def show_labels(self):
        self.setLabel('left', "Failure probability estimation error")
        self.setLabel('bottom', "Number of simulations")
        
    
    def setup(self, *args, **kwargs):
        
        #xkcd_red   = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
        #red   = (253, 0, 17, 96)
        
        #self.pen_f = self.plot(x, y, brush=red)#, name="failure domain estimation")
        #self.pen_f.setZValue(-100)
        
        
        pen = pg.mkPen(color='m', width=2)
        self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation")
        pen = pg.mkPen(color='r', width=2) #(118, 187, 255)
        self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation")
        
        
    
    #č když se někde objeví nula se zapnutým LogModem - 
    #č qtpygraph hned spadne a není možne ten pad zachytit
    def zerosafe(self, x, y, fallback_y=None): 
        x = np.array(x)
        y = np.array(y)
        if fallback_y is None:
            fallback_y = y
        y = np.where(y > 0, y, fallback_y)
        mask = y > 0
        return x[mask], y[mask]
        
    
    def redraw(self):
        #č neotravujme uživatele chybovejma hlaškama
        if hasattr(self.simplex_data.dice_box, 'pf_exact'):
            try: #ё тут всё что угодно может пойти не так
                pf_exact = self.simplex_data.dice_box.pf_exact
                
                df = self.simplex_data.df
                #č zapíšeme do data rámu, snad nikomu nebude vadit
                df['vertex_estimation_error'] = df['vertex_estimation'] - pf_exact
                df['weighted_vertex_estimation_error'] = df['weighted_vertex_estimation'] - pf_exact
                
                v = df['vertex_estimation_error'].abs()
                wv = df['weighted_vertex_estimation_error'].abs()
                
                x, y = self.zerosafe(v.index, v.to_numpy())
                self.pen_vertex.setData(x, y)
                
                x, y = self.zerosafe(wv.index, wv.to_numpy())
                self.pen_weighted_vertex.setData(x, y)
            
                
            except BaseException as e:
                print(self.__class__.__name__ + ":", repr(e))




Mode Type Size Ref File
100644 blob 28117 0907e38499eeca10471c7d104d4b4db30b8b7084 IS_stat.py
100644 blob 6 0916b75b752887809bac2330f3de246c42c245cd __init__.py
100644 blob 72 458b7e2ca46acd9ec0d2caf3cc4d72e515bb73dc __main__.py
100644 blob 73368 3d245b8568158ac63c80fa0847631776a140db0f blackbox.py
100644 blob 11243 10c424c2ce5e8cdd0da97a5aba74c54d1ca71e0d candybox.py
100644 blob 29927 066a2d10ea1d21daa6feb79fa067e87941299ec4 convex_hull.py
100644 blob 102979 76afe27f4912a9cd333224484081a2f8f5f15096 dicebox.py
100644 blob 36930 a775d1114bc205bbd1da0a10879297283cca0d4c estimation.py
100644 blob 34394 3f0ab9294a9352a071de18553aa687c2a9e6917a f_models.py
100644 blob 35721 3daee87ec0bc670207356490e16f200fed0d4fc4 g_models.py
100644 blob 20908 457329fe567f1c0a9950c21c7c494cccf38193cc ghull.py
100644 blob 2718 5d721d117448dbb96c554ea8f0e4651ffe9ac457 gp_plot.py
100644 blob 29393 96162a5d181b8307507ba2f44bafe984aa939163 lukiskon.py
100644 blob 2888 0c4303f8865b4861382119d77147f227958f2aec misc.py
040000 tree - e83032b6b83795f53d85ba08eb565f1e82d19951 mplot
100644 blob 1462 437b0d372b6544c74fea0d2c480bb9fd218e1854 plot.py
100644 blob 2807 1feb1d43e90e027f35bbd0a6730ab18501cef63a plotly_plot.py
040000 tree - bfb2adfd17a5c916d2a132e2607f57f14561559e qt_gui
100644 blob 8566 5c8f8cc2a34798a0f25cb9bf50b5da8e86becf64 reader.py
100644 blob 4284 a0e0b4e593204ff6254f23a67652804db07800a6 samplebox.py
100644 blob 6558 df0e88ea13c95cd1463a8ba1391e27766b95c3a5 sball.py
100644 blob 6739 0b6f1878277910356c460674c04d35abd80acf13 schemes.py
100644 blob 76 11b2fde4aa744a1bc9fa1b419bdfd29a25c4d3e8 shapeshare.py
100644 blob 54884 fbe116dab4fc19bb7568102de21f53f15a8fc6bf simplex.py
100644 blob 13090 2b9681eed730ecfadc6c61b234d2fb19db95d87d spring.py
100644 blob 10953 da8a8aaa8cac328ec0d1320e83cb802b562864e2 stm_df.py
040000 tree - 257d3de26ca92fafda012c78bccbd1e3ae01824c testcases
100644 blob 2465 d829bff1dd721bdb8bbbed9a53db73efac471dac welford.py
100644 blob 25318 fcdabd880bf7199783cdb9c0c0ec88c9813a5b18 whitebox.py
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/iam-git/WellMet

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/iam-git/WellMet

Clone this repository using git:
git clone git://git.rocketgit.com/user/iam-git/WellMet

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main