def pearsonfit(data): data=np.array(data) nozero=len(data.nonzero()[0]) pze=1-float(nozero)/len(data) para=lm.pelpe3(lm.samlmu(data[data!=0],3)) p3= np.array([lm.cdfpe3(i,para) for i in data]) p3=stats.norm.ppf(p3) return p3
def pearsonfit(data): data = np.array(data) nozero = len(data.nonzero()[0]) pze = 1 - float(nozero) / len(data) #print pze #data2=ma.masked_values(data.values, 0) para = lm.pelpe3(lm.samlmu(data[data != 0], 3)) p3 = np.array([lm.cdfpe3(i, para) for i in data]) p3 = stats.norm.ppf(p3) #p3=stats.norm.ppf(pze+(1-pze)*lm.cdfnor(p3,[0,1])) return p3
comparefunc(norlmom,correctnorlmom,"LMOMNOR",6) #RANDNOR try: norrand = lmoments.randnor(10,correctnorfit) if len(norrand) != 10: print("RANDNOR FAILED") except: print("RANDNOR FAILED") print("#######################################") ####################################### ##PE3 ####################################### ##PELPE3 pe3fit = lmoments.pelpe3(LMU) correctpe3fit = [3.236364, 2.199489, 1.646184] comparefunc(pe3fit,correctpe3fit,"PELPE3",6) ##QUAPE3 pe3qua = [lmoments.quape3(0.2,correctpe3fit),lmoments.quape3(0.5,correctpe3fit),lmoments.quape3(0.8,correctpe3fit)] pe3qua2 = lmoments.quape3([0.2,0.5,0.8],correctpe3fit) correctpe3qua = [1.447672, 2.663015, 4.705896] comparefunc(pe3qua,correctpe3qua,"QUAPE3",6) comparefunc(pe3qua2,correctpe3qua,"QUAPE3 group",6) ##LMRPE3 pe3lmr = lmoments.lmrpe3(correctpe3fit,4) correctpe3lmr = [3.2363636, 1.1418182, 0.2738845, 0.1498865] comparefunc(pe3lmr,correctpe3lmr,"LMRPE3",6)
# 3 PE3: # para1 = \para1 # para2 = \para2 [para2=xmom[0]/alpha] # para3 = \gamma if FUNC == 'PE3': #for i in progressbar(range(ysize), "Computing: ", 40): for i in range(ysize): if i % 10 == 0: print(i, 'out of ', ysize) 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[:10, i, j]) > 1e-5: lmoms = lmom.samlmu(datm[:, i, j], 4) params = lmom.pelpe3(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.quape3(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: print("error in calculating the params", i, j, params) print("datm:", datm[:, i, j]) print( "daty", lmom.quape3( p, [para1[i, j], para2[i, j], para3[i, j]]))
def _pe3(self, dat, l): ''' Fit a Pearson type 3 distribution''' para = lm.pelpe3(lm.samlmu(dat, l)) _cdf = partial(lm.cdfpe3, para=para) _pdf = partial(lm.pdfpe3, para=para) return para, _cdf, _pdf