Пример #1
0
 def func4(x):
     return metrics.corr(np.asarray(x), Obs[oname2].iloc[:, 1])
Пример #2
0
 # Get sim outpts and apply conversion factor !!
 tmp = [
     simfct[iobs] * sim[j][x] for x in range(1, simlen + 1)
 ]
 # Crop between desired time frame
 sim2 = [
     tmp[idx] for idx in range(simlen)
     if simdate[idx] >= fitbeg[iobs]
     and simdate[idx] <= fitend[iobs]
 ]
 # Metrics
 md_nse = metrics.nash_sutcliff(sim2, obs)
 md_kge = metrics.kling_gupta(sim2, obs, method='2012')
 md_rmse = metrics.rmse(sim2, obs)
 #md_bias = metrics.bias(sim2,obs)
 md_corr = metrics.corr(sim2, obs)
 md_rstd = metrics.rstd(sim2, obs)
 # Write
 f_out.write(','.join([
     str(i + 1),
     str(jcomp),
     str(md_nse),
     str(md_kge),
     str(md_rmse),
     str(md_corr),
     str(md_rstd)
 ]) + '\n')
 # Save the 'coordinates' of this sample (only the first time)
 if iobs == 0:
     iok.append(i)
     jok.append(jcomp)
Пример #3
0
                        # return UnivariateSpline(d,y,s=0).integral(d1,d2)/(d2-d1)
                        return splint(d1, d2,
                                      splrep(d, y, k=min(len(d) - 1, 3),
                                             s=0)) / (d2 - d1)

                    # return sp.integrate.quad(interp1d.splrep(d,y,k=len(d)-1,s=0),d1,d2)[0]/(d2-d1)

                    obs = Obs[oname2].iloc[:, 1:].apply(func, axis=1)
                    #print len(obs)

                    KGE.loc[js2[j], oname] = metrics.kling_gupta(sim,
                                                                 obs,
                                                                 method='2012')
                    MAE.loc[js2[j], oname] = metrics.meanabs(sim, obs)
                    RMSE.loc[js2[j], oname] = metrics.rmse(sim, obs)
                    corr.loc[js2[j], oname] = metrics.corr(sim, obs)

            if oname == outnames[0]:
                itot += nj

        # Clean the metrics dataframe to include only the successful runs common to all obs
        # Use MAE or RMSE, because KGE and corr can have NaN only for 'flat' succesful runs
        MAE.dropna(inplace=True)
        RMSE.dropna(inplace=True)

        js3 = MAE.index

        KGE = KGE.ix[js3]
        corr = corr.ix[js3]
        df_par = df_par.loc[:, js3]
Пример #4
0
            KGEcorr[obsnames[iobs]] = [0] * nj
            KGEgamma[obsnames[iobs]] = [0] * nj
            KGEbeta[obsnames[iobs]] = [0] * nj

            for j in range(1, nj + 1):

                # -- Cost functions
                tmp2 = tmp[j - 1] * simfct[iobs]

                # Crop between desired time frame
                sim = [
                    tmp2[idx + 1] for idx in range(lsim)
                    if simt[idx] >= fitbeg[iobs] and simt[idx] <= fitend[iobs]
                ]
                # Increment cost function
                KGEcorr[obsnames[iobs]][j - 1] = metrics.corr(
                    sim, obs[obsnames[iobs]])
                KGEbeta[obsnames[iobs]][j - 1] = metrics.rmu(
                    sim, obs[obsnames[iobs]])
                KGEgamma[obsnames[iobs]][j - 1] = metrics.rstd(
                    sim, obs[obsnames[iobs]]) / KGEbeta[obsnames[iobs]][j - 1]
                KGEmod[obsnames[iobs]][j - 1] = 1 - np.sqrt(
                    (1 - KGEcorr[obsnames[iobs]][j - 1])**2 +
                    (1 - KGEgamma[obsnames[iobs]][j - 1])**2 +
                    (1 - KGEbeta[obsnames[iobs]][j - 1])**2)

                # A few prints
                if j == 1:
                    print obsnames[iobs]
                    print np.mean(sim), np.mean(
                        np.ma.masked_array(
                            obs[obsnames[iobs]],