def bruteforce(mimo, qmeas, caseName, runId): """ """ nowpars = mimo.pars print nowpars i = 0 results = [] execstr = "mimo.range[mimo.calibpars[" + str(i) + "]]" print "=========" for i in range(0, len(mimo.calibpars)): if i > 0: execstr = execstr + ", mimo.range[mimo.calibpars[" + str(i) + "]]" print execstr for parmult in mimo.range[mimo.calibpars[i]]: nowpars[i] = parmult exec "combi = itertools.product(" + execstr + ")" while 1: try: thisparset = combi.next() print "Parameters:" + str(thisparset) q = mimo.run(thisparset) res = q - qmeas # only resturn non-nan values resnonan = res[~np.isnan(res)] mimo.log.log(45, "Parameters now: " + str(thisparset)) pylab.plot(q) mimo.NS.append(stats.get_nash_sutcliffe(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.BIAS.append(stats.get_bias(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.CORR.append(stats.get_correlation(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.MABSE.append(stats.get_mean_absolute_error(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.log.log(45, "NS: " + str(mimo.NS[-1])) mimo.log.log(45, "BIAS: " + str(mimo.BIAS[-1])) mimo.log.log(45, "CORR: " + str(mimo.CORR[-1])) mimo.log.log(45, "MABSE: " + str(mimo.MABSE[-1])) results.append( [ thisparset, stats.get_nash_sutcliffe(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan), stats.get_bias(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan), ] ) pylab.savefig(os.path.join(caseName, runId, str(mimo.ColSim) + "fit.png")) # zz = errfuncFIT(thisparset,qmeas,mimo,caseName,runId) except: print "Unexpected error:", sys.exc_info()[0] break return results
def errfuncFIT(pars, qmeas, mimo, caseName, runId): q = mimo.run(pars) res = q - qmeas # only resturn non-nan values resnonan = res[~np.isnan(res)] mimo.log.log(45, "Parameters now: " + str(pars)) pylab.plot(q) mimo.NS.append( stats.get_nash_sutcliffe( qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan ) ) mimo.BIAS.append( stats.get_bias(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan) ) mimo.CORR.append( stats.get_correlation(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan) ) mimo.MABSE.append( stats.get_mean_absolute_error( qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan ) ) mimo.log.log(45, "NS: " + str(mimo.NS[-1])) mimo.log.log(45, "BIAS: " + str(mimo.BIAS[-1])) mimo.log.log(45, "CORR: " + str(mimo.CORR[-1])) mimo.log.log(45, "MABSE: " + str(mimo.MABSE[-1])) pylab.savefig(os.path.join(caseName, runId, str(mimo.ColSim) + "fit.png")) return resnonan
def errfuncFIT(pars, qmeas, mimo, caseName, runId): q = mimo.run(pars) res = q - qmeas # only resturn non-nan values resnonan = res[~np.isnan(res)] mimo.log.log(45, "Parameters now: " + str(pars)) pylab.plot(q) mimo.NS.append( stats.get_nash_sutcliffe(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.BIAS.append( stats.get_bias(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.CORR.append( stats.get_correlation(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.MABSE.append( stats.get_mean_absolute_error(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.log.log(45, "NS: " + str(mimo.NS[-1])) mimo.log.log(45, "BIAS: " + str(mimo.BIAS[-1])) mimo.log.log(45, "CORR: " + str(mimo.CORR[-1])) mimo.log.log(45, "MABSE: " + str(mimo.MABSE[-1])) pylab.savefig(os.path.join(caseName, runId, str(mimo.ColSim) + "fit.png")) return resnonan
def bruteforce(mimo, qmeas, caseName, runId): """ """ nowpars = mimo.pars print(nowpars) i = 0 results = [] execstr = "mimo.range[mimo.calibpars[" + str(i) + "]]" print("=========") for i in range(0, len(mimo.calibpars)): if i > 0: execstr = execstr + ", mimo.range[mimo.calibpars[" + str(i) + "]]" print(execstr) for parmult in mimo.range[mimo.calibpars[i]]: nowpars[i] = parmult exec("combi = itertools.product(" + execstr + ")") while 1: try: thisparset = next(combi) print("Parameters:" + str(thisparset)) q = mimo.run(thisparset) res = q - qmeas # only resturn non-nan values resnonan = res[~np.isnan(res)] mimo.log.log(45, "Parameters now: " + str(thisparset)) pylab.plot(q) mimo.NS.append( stats.get_nash_sutcliffe(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.BIAS.append( stats.get_bias(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.CORR.append( stats.get_correlation(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.MABSE.append( stats.get_mean_absolute_error(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan)) mimo.log.log(45, "NS: " + str(mimo.NS[-1])) mimo.log.log(45, "BIAS: " + str(mimo.BIAS[-1])) mimo.log.log(45, "CORR: " + str(mimo.CORR[-1])) mimo.log.log(45, "MABSE: " + str(mimo.MABSE[-1])) results.append([ thisparset, stats.get_nash_sutcliffe(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan), stats.get_bias(qmeas[~np.isnan(res)], q[~np.isnan(res)], NoData=np.nan), ]) pylab.savefig( os.path.join(caseName, runId, str(mimo.ColSim) + "fit.png")) # zz = errfuncFIT(thisparset,qmeas,mimo,caseName,runId) except: print("Unexpected error:", sys.exc_info()[0]) break return results