def qua(self, x, years):
     # 根据重现期反推阈值
     thres = []
     for y in years:
         thre = lmoments.quagev(y, x)
         thres.append(thre)
     return thres
Exemple #2
0
    def func(data):
        sample = lmoments.randgev(len(data), gevfit)
        samgevfit = lmoments.pelgev(lmoments.samlmu(sample))

        T = np.arange(0.1, 999.1, 0.1) + 1
        sT = lmoments.quagev(1.0 - 1. / T, samgevfit)
        res = samgevfit
        res.extend(sT.tolist())
        return tuple(res)
Exemple #3
0
def do_it(data, title):
    print("AAAA")
    lmom = lmoments.samlmu(data)
    print("BBBB")
    gevfit = lmoments.pelgev(
        lmom)  # the parameters of the GEV distribtion as estimated on data
    print(gevfit)

    # return years (1.1 to 1000)
    T = np.arange(0.1, 999.1, 0.1) + 1
    sT = lmoments.quagev(1.0 - 1. / T, gevfit)

    # prepare index for obs
    N = np.r_[1:len(data) + 1] * 1.0  #must *1.0 to convert int to float
    Nmax = max(N)

    # get confidence intervals
    bootout = ci_bootstrap(data, gevfit)
    ci_Td = bootout["ci_Td"]
    ci_Tu = bootout["ci_Tu"]
    params_ci = bootout["params_ci"]

    fig, ax = plt.subplots()

    plt.setp(ax.lines, linewidth=2, color='magenta')

    base_x = 10
    subs_x = [2, 3, 4, 5, 6, 7, 8, 9]

    ax.set_title("Execution Time GEV Distribution - " + title, fontsize=18)
    ax.set_xlabel("Expected Frequency of Extrema", fontsize=14)
    ax.set_ylabel("Maximum Execution Time", fontsize=14)
    ax.semilogx(T, sT, basex=base_x)
    #ax.plot(T, sT)
    ax.scatter(Nmax / N, np.sort(data)[::-1], color='orangered')

    ax.semilogx(T, ci_Td, '--', basex=base_x)
    #ax.plot(T, ci_Td, '--')
    ax.semilogx(T, ci_Tu, '--', basex=base_x)
    #ax.plot(T, ci_Tu, '--')
    ax.fill_between(T, ci_Td, ci_Tu, color='0.75', alpha=0.5)

    plt.show()
Exemple #4
0
    if len(gamrand) != 10:
        print("RANDGUM FAILED")
except:
    print("RANDGAM FAILED")
    
print("#######################################")
#######################################
##GEV
#######################################
##PELGEV
gevfit = lmoments.pelgev(LMU)
correctgevfit = [2.1792884, 1.3956404, -0.1555609]
comparefunc(gevfit,correctgevfit,"PELGEV",6)

##QUAGEV
gevqua = [lmoments.quagev(0.2,correctgevfit),lmoments.quagev(0.5,correctgevfit),lmoments.quagev(0.8,correctgevfit)]
gevqua2 = lmoments.quagev([0.2,0.5,0.8],correctgevfit)
correctgevqua = [1.539112, 2.705672, 4.537048]
comparefunc(gevqua,correctgevqua,"QUAGEV",6)
comparefunc(gevqua2,correctgevqua,"QUAGEV group",6)

##LMRGEV
gevlmr = lmoments.lmrgev(correctgevfit,4)
correctgevlmr = [3.2363636, 1.1418182, 0.2738854, 0.1998461]
comparefunc(gevlmr,correctgevlmr,"LMRGEV",6)

##CDFGEV
gevcdf = [lmoments.cdfgev(2,correctgevfit),lmoments.cdfgev(5,correctgevfit),lmoments.cdfgev(8,correctgevfit)]
gevcdf2 = lmoments.cdfgev([2,5,8],correctgevfit)
correctgevcdf = [0.3202800, 0.8415637, 0.9606184]
comparefunc(gevcdf,correctgevcdf,"CDFGEV Ind",6)
        ranklist1 = df1['Ranked'].tolist()
        windlist1 = df1['Max U10'].tolist()

        windlist1 = windlist1[::-1]
        ratio = len(windlist1) / 38.
        #fit the different extreme value distributions
        try:
            LMU = lmoments.samlmu(windlist1)

            gevfit = lmoments.pelgev(LMU)
            expfit = lmoments.pelexp(LMU)
            gumfit = lmoments.pelgum(LMU)
            weifit = lmoments.pelwei(LMU)
            gpafit = lmoments.pelgpa(LMU)

            gevST = lmoments.quagev(1.0 - 1. / T, gevfit)
            expST = lmoments.quaexp(1.0 - 1. / T, expfit)
            gumST = lmoments.quagum(1.0 - 1. / T, gumfit)
            weiST = lmoments.quawei(1.0 - 1. / T, weifit)
            gpaST = lmoments.quagpa(1.0 - 1. / T, gpafit)
            ratiolist.append(ratio)
            for t, tl in zip(range(0, len(bootstrapgev)), tlist):
                bootstrapgev[t].append(np.interp(tl, T, gevST))
                bootstrapexp[t].append(np.interp(tl, T, expST))
                bootstrapgum[t].append(np.interp(tl, T, gumST))
                bootstrapwei[t].append(np.interp(tl, T, weiST))
                bootstrappar[t].append(np.interp(tl, T, gpaST))

        except TypeError:
            loop = loop + 1
        for j in range(xsize):
            if np.nanmean(datm[:, i, j]) > -9990.:
                # There are many grids with constant values or
                # there is only one large value but others are constant.
                # We cannot calculate the parameters with this time series.
                if np.std(datm[:-5, i, j]) > 1e-5:
                    lmoms = lmom.samlmu(datm[:, i, j], 4)
                    params = lmom.pelgev(lmoms)

                    try:
                        para1[i, j] = params[0]
                        para2[i, j] = params[1]
                        para3[i, j] = params[2]
                        p_AIC[i, j] = lmom.AIC(datm[:, i, j], FUNC)

                        y = lmom.quagev(p, params)
                        c_AIC[i, j] = calc_aic(datm[:, i, j], y)
                        py_AIC[i, j] = aic.aic(datm[:, i, j], y, len(params))

                    except:
                        para1[i, j] = np.nanmean(datm[:, i, j])
                        para2[i, j] = -9999.
                        para3[i, j] = -9999.
                        p_AIC[i, j] = -9999.
                        c_AIC[i, j] = -9999.

    fname = var + '_' + str(years) + '-' + str(yeare) + '.bin'
    para1.astype('float64').tofile(outdir + '/para/' + FUNC + '_mu_' + fname)
    para2.astype('float64').tofile(outdir + '/para/' + FUNC + '_sigma_' +
                                   fname)
    para3.astype('float64').tofile(outdir + '/para/' + FUNC + '_theta_' +
                        np.float64).reshape(ysize, xsize)
    para2 = np.fromfile(outdir + '/para/' + f_para2,
                        np.float64).reshape(ysize, xsize)
    para3 = np.fromfile(outdir + '/para/' + f_para3,
                        np.float64).reshape(ysize, xsize)

    for i in range(ysize):
        for j in range(xsize):

            if para2[i, j] == -9999:
                Nflddph[i, j] = -9999
            elif para2[i, j] == 0.0 or para2[i, j] == -999.0:
                Nflddph[i, j] = 0.0
            else:
                if rivhgt[i, j] != -9999:
                    Nrivdph = lmom.quagev(
                        RPP, [para1[i, j], para2[i, j], para3[i, j]])
                    try:
                        Nflddph[i, j] = Nrivdph - rivhgt[i, j]
                    except:
                        Nflddph[i, j] = -9999
                        #print para1[i,j], para2[i,j], para3[i,j]
                        #print Nrivdph
                        #sys.exit()

                    if Nflddph[i, j] < 0.0:
                        Nflddph[i, j] = 0.0

    fflddph = var + '_RP' + rp + '_' + FUNC + '.bin'
    Nflddph.astype(np.float32).tofile(outdir + '/Nyear_storge/' + fflddph)

# For GAM distribution