Ejemplo n.º 1
0
                    def func(y):
                        #    return sp.integrate.quad(interp1d(d,y,kind='cubic'),d1,d2)/(d2-d1)
                        # 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]
Ejemplo n.º 2
0
 def func2(x):
     return metrics.meanabs(np.asarray(x), Obs[oname2].iloc[:,
                                                            1])
Ejemplo n.º 3
0
                tmp2 = tmp[j - 1] * simfct[iobs]

                # Crop between desired time frame, and account for potential gaps in the obs
                sim = [
                    tmp2[idx + 1] for idx in range(lsim)
                    if any(obst[obsnames[iobs]] == simt[idx]) == True
                ]
                #if i==21 and j==1:
                #    tmp24 = [simt[idx] for idx in range(lsim) if simt[idx] in obst[obsnames[iobs]]]
                #    print
                #    print tmp24

                # Increment cost function
                KGE[obsnames[iobs]][j - 1] = metrics.kling_gupta(
                    sim, obs[obsnames[iobs]], method='2012')
                MAE[obsnames[iobs]][j - 1] = metrics.meanabs(
                    sim, obs[obsnames[iobs]])
                RMSE[obsnames[iobs]][j - 1] = metrics.rmse(
                    sim, obs[obsnames[iobs]])

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

                if iobs == 0:
                    # -- Parameters
                    tmp3 = [tmp_par[j - 1][idx] for idx in range(1, npar + 1)]
                    with open(
                            os.getcwd() + '/' + outdir + '/' + MCname +
                            '_parameters.txt', 'a') as f_out: