Index: wflow-py/wflow/wflow_fit.py =================================================================== diff -u -r4143969ebd6b276284ea6e4198ee693bd6ab506a -rf33154035afcaa101c5a30594b9c86a4fe9f61ef --- wflow-py/wflow/wflow_fit.py (.../wflow_fit.py) (revision 4143969ebd6b276284ea6e4198ee693bd6ab506a) +++ wflow-py/wflow/wflow_fit.py (.../wflow_fit.py) (revision f33154035afcaa101c5a30594b9c86a4fe9f61ef) @@ -170,22 +170,13 @@ self.gtol = float(configget(self.conf, "fit", "gtol", "0.0001")) self.factor = float(configget(self.conf, "fit", "factor", "100.0")) - exec "self.ColSimS = " + configget(self.conf, "fit", "ColSim", "[1]") - exec "self.ColMeasS = " + configget(self.conf, "fit", "ColMeas", "[1]") + exec("self.ColSimS = " + configget(self.conf, "fit", "ColSim", "[1]")) + exec("self.ColMeasS = " + configget(self.conf, "fit", "ColMeas", "[1]")) self.WarmUpSteps = int(configget(self.conf, "fit", "WarmUpSteps", "1")) self.AreaMapName = configget(self.conf, "fit", "areamap", "wflow_catchment.map") self.AreaMap = self.WF.readmap(os.path.join(self.caseName, self.AreaMapName)) - exec "self.AreaCodeS = " + configget(self.conf, "fit", "areacode", "[1]") + exec("self.AreaCodeS = " + configget(self.conf, "fit", "areacode", "[1]")) - - - exec("self.ColSimS = " + configget(self.conf,"fit","ColSim","[1]")) - exec("self.ColMeasS = " + configget(self.conf,"fit","ColMeas","[1]")) - self.WarmUpSteps = int(configget(self.conf,"fit","WarmUpSteps","1")) - self.AreaMapName = configget(self.conf,"fit","areamap","wflow_catchment.map") - self.AreaMap = self.WF.readmap(os.path.join(self.caseName,self.AreaMapName)) - exec("self.AreaCodeS = " + configget(self.conf,"fit","areacode","[1]")) - # Shift columns as the maps are one bases and the cols 0 based i = 0 for a in self.ColSimS: @@ -232,7 +223,17 @@ i = 0 for j in self.pars: self.log.info("Saving parameter (initial values): " + self.calibpars[i]) - strr_org = "self.WF.report(self.dynModelFw._userModel()." + self.calibpars[i] + ",\"" + self.caseName + "/"+self.runId +"/"+ self.calibpars[i] +"_org.map\")" + strr_org = ( + "self.WF.report(self.dynModelFw._userModel()." + + self.calibpars[i] + + ',"' + + self.caseName + + "/" + + self.runId + + "/" + + self.calibpars[i] + + '_org.map")' + ) exec(strr_org) i = i + 1 @@ -271,13 +272,37 @@ # !!!!!!!!!! Not sure if the last version of the par is the best fit!! i = 0 for j in pars: - self.log.log(45,"Saving parameter: " + self.calibpars[i]) + self.log.log(45, "Saving parameter: " + self.calibpars[i]) exec("newmap = self.dynModelFw._userModel()." + self.calibpars[i]) - newmap = self.WF.ifthenelse(self.AreaMap == self.AreaCode,newmap * j, newmap) - strr_new = "self.WF.report(newmap," + "\""+ self.caseName + "/" + self.runId +"/" + self.calibpars[i] + "_" + str(self.ColSim) + "_" + str(self.ColMeas) + "_" + str(self.AreaCode)+ ".map\")" + newmap = self.WF.ifthenelse( + self.AreaMap == self.AreaCode, newmap * j, newmap + ) + strr_new = ( + "self.WF.report(newmap," + + '"' + + self.caseName + + "/" + + self.runId + + "/" + + self.calibpars[i] + + "_" + + str(self.ColSim) + + "_" + + str(self.ColMeas) + + "_" + + str(self.AreaCode) + + '.map")' + ) if savetoinput: - self.log.log(45,"Saving adjusted map to input!!") - str_save = "self.WF.report(newmap," + "\""+ self.caseName + "/staticmaps/" + self.calibpars[i] + ".map\")" + self.log.log(45, "Saving adjusted map to input!!") + str_save = ( + "self.WF.report(newmap," + + '"' + + self.caseName + + "/staticmaps/" + + self.calibpars[i] + + '.map")' + ) exec(str_save) exec(strr_new) @@ -328,7 +353,8 @@ def usage(*args): sys.stdout = sys.stderr - for msg in args: print(msg) + for msg in args: + print(msg) print(__doc__) sys.exit(0) @@ -345,22 +371,22 @@ i = i + 1 else: print("Parameter " + calibpars[0] + " = " + str(pp), file=ff) - + print("Estimate of the jacobian around the solution: " + str(a), file=ff) - for dtc in b: + for dtc in b: print(dtc + " = " + str(b[dtc]), file=ff) - - if d in [1,2,3,4]: - print("A solution was found (" + str(d) + ")", file=ff) + + if d in [1, 2, 3, 4]: + print("A solution was found (" + str(d) + ")", file=ff) print(c, file=ff) else: - print("No solution was found (" + str(d) + ")", file=ff) + print("No solution was found (" + str(d) + ")", file=ff) print(c, file=ff) - - print("NS: " +str(model.NS), file=ff) - print("BIAS: " +str(model.BIAS), file=ff) - print("CORR: " +str(model.CORR), file=ff) - print("MABSE: " +str(model.MABSE), file=ff) + + print("NS: " + str(model.NS), file=ff) + print("BIAS: " + str(model.BIAS), file=ff) + print("CORR: " + str(model.CORR), file=ff) + print("MABSE: " + str(model.MABSE), file=ff) ff.close()