예제 #1
0
 def func1(x):
     return metrics.kling_gupta(x,
                                Obs[oname2].iloc[:, 1],
                                method='2012')
예제 #2
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
예제 #3
0
                # -- Cost functions
                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(
예제 #4
0
 sim = np.genfromtxt(f_in, delimiter=',', skip_header=1)
 for j in range(sim.shape[0]):
     jcomp = int(sim[j][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)
예제 #5
0
     j += 1
     continue
 tmp = np.genfromtxt(f_in,
                     delimiter='\t',
                     skip_header=nts + 3,
                     unpack=True)[1]
 #print i ,j ,len(tmp)
 if len(tmp) < lobs:
     j += 1
     continue
 # Crop between desired time frame (based on the length of this time frame)
 sim = [tmp[idx] for idx in range(len(tmp) - ltf, len(tmp))]
 # Metrics
 md_nse = metrics.nash_sutcliff(sim, obs['Streamflow'])
 md_kge = metrics.kling_gupta(sim,
                              obs['Streamflow'],
                              method='2012')
 md_rmse = metrics.rmse(sim, obs['Streamflow'])
 md_bias = metrics.bias(sim, obs['Streamflow'])
 # Write
 f_out.write(','.join([
     str(i + 1),
     str(j + 1),
     str(md_nse),
     str(md_kge),
     str(md_rmse),
     str(md_bias)
 ]) + '\n')
 # Save the 'coordinates' of this sample
 iok.append(i)
 jok.append(j)