Index: wflow-py/UnitTests/TestBMI.py =================================================================== diff -u -re879b0af6cf75726bb1ebd542a245abdffe48cef -rc30e6377f07fd5c900d5431dd0df1bb1c0a10dc4 --- wflow-py/UnitTests/TestBMI.py (.../TestBMI.py) (revision e879b0af6cf75726bb1ebd542a245abdffe48cef) +++ wflow-py/UnitTests/TestBMI.py (.../TestBMI.py) (revision c30e6377f07fd5c900d5431dd0df1bb1c0a10dc4) @@ -177,10 +177,17 @@ print 'Run with update(-1)' bmiobj = bmi.wflowbmi_light() bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR) + print bmiobj.get_current_time() et = bmiobj.get_end_time() st = bmiobj.get_start_time() + print bmiobj.get_current_time() bmiobj.update(et - st) + print bmiobj.get_current_time() bmiobj.finalize() + print bmiobj.get_current_time() + print et + print st + self.assertEquals(et, bmiobj.get_current_time()) def testbmirun_space_in_name(self): @@ -191,6 +198,7 @@ st = bmiobj.get_start_time() bmiobj.update(et - st) bmiobj.finalize() + self.assertEquals(et, bmiobj.get_current_time()) def testbmirunnetcdf(self): @@ -225,6 +233,7 @@ bmiobj.finalize() + self.assertEquals(ett, bmiobj.get_current_time()) if __name__ == '__main__': Index: wflow-py/UnitTests/Testwflow_hbv.py =================================================================== diff -u -re879b0af6cf75726bb1ebd542a245abdffe48cef -rc30e6377f07fd5c900d5431dd0df1bb1c0a10dc4 --- wflow-py/UnitTests/Testwflow_hbv.py (.../Testwflow_hbv.py) (revision e879b0af6cf75726bb1ebd542a245abdffe48cef) +++ wflow-py/UnitTests/Testwflow_hbv.py (.../Testwflow_hbv.py) (revision c30e6377f07fd5c900d5431dd0df1bb1c0a10dc4) @@ -29,7 +29,7 @@ print dynModelFw.DT # Load model config from files and check directory structure - dynModelFw.createRunId(NoOverWrite=False,level=wf.logging.ERROR) + dynModelFw.createRunId(NoOverWrite=False,level=wf.logging.DEBUG) # Run the initial part of the model (reads parameters and sets initial values) dynModelFw._runInitial() # Runs initial part @@ -40,7 +40,6 @@ dynModelFw.wf_setValues('P', 0.0) elif ts <= 15: dynModelFw.wf_setValues('P', 10.0) - sump = sump + 10.0 else: dynModelFw.wf_setValues('P', 0.0) @@ -61,66 +60,8 @@ print("Checking discharge ....") self.assertAlmostEquals(1073.2958811442056,my_data[:,2].mean(),places=4) - print("Checking precip sum ....") - my_data = wf.genfromtxt(os.path.join(caseName,runId,"P.csv"), delimiter=',') - self.assertAlmostEquals(sump,my_data[:,2].sum()) - def testapirunhr(self): - startTime = 1 - stopTime = 30 - currentTime = 1 - # set runid, clonemap and casename. Also define the ini file - runId = "unittest" - configfile="wflow_hbv_hr.ini" - wflow_cloneMap = 'wflow_catchment.map' - caseName="wflow_hbv" - starttime = starttime = datetime.datetime(1990,01,01) - - myModel = wf.WflowModel(wflow_cloneMap, caseName,runId,configfile) - # initialise the framework - dynModelFw = wf.wf_DynamicFramework(myModel, stopTime,firstTimestep=startTime,datetimestart=starttime) - print dynModelFw.DT - - # Load model config from files and check directory structure - dynModelFw.createRunId(NoOverWrite=False,level=wf.logging.DEBUG) - # Run the initial part of the model (reads parameters and sets initial values) - dynModelFw._runInitial() # Runs initial part - - dynModelFw._runResume() # gets the state variables - sump = 0.0 - for ts in range(startTime,stopTime + 1): - if ts <10: - dynModelFw.wf_setValues('P', 0.0) - elif ts <= 15: - dynModelFw.wf_setValues('P', 10.0) - sump = sump + 10.0 - else: - dynModelFw.wf_setValues('P', 0.0) - - dynModelFw.wf_setValues('PET', 2.0) - dynModelFw.wf_setValues('TEMP', 10.0) - dynModelFw._runDynamic(ts,ts) # runs for all timesteps - dynModelFw.logger.info("Doing step: " + str(ts)) - dynModelFw._runSuspend() # saves the state variables - dynModelFw._wf_shutdown() - - # nore read the csv results acn check of they match the first run - # Sum should be approx c 4.569673676 - my_data = wf.genfromtxt(os.path.join(caseName,runId,"watbal.csv"), delimiter=',') - - print("Checking water budget ....") - self.assertAlmostEquals( -284.99871826171875,my_data[:,2].sum(),places=4) - - my_data = wf.genfromtxt(os.path.join(caseName,runId,"run.csv"), delimiter=',') - print("Checking discharge ....") - self.assertAlmostEquals(1837.79182650248212 ,my_data[:,2].mean(),places=4) - - print("Checking precip sum ....") - my_data = wf.genfromtxt(os.path.join(caseName,runId,"P.csv"), delimiter=',') - self.assertAlmostEquals(sump,my_data[:,2].sum()) - - if __name__ == '__main__': unittest.main() Index: wflow-py/UnitTests/Testwflow_hbv2.py =================================================================== diff -u --- wflow-py/UnitTests/Testwflow_hbv2.py (revision 0) +++ wflow-py/UnitTests/Testwflow_hbv2.py (revision c30e6377f07fd5c900d5431dd0df1bb1c0a10dc4) @@ -0,0 +1,73 @@ +__author__ = 'schelle' + +import unittest +import wflow.wflow_hbv as wf +import os, datetime +""" + +Run wflow_hbv for 30 steps and checks if the outcome is approx that of the reference run + +""" + +class MyTest(unittest.TestCase): + + + + def testapirunhr(self): + startTime = 1 + stopTime = 30 + currentTime = 1 + + # set runid, clonemap and casename. Also define the ini file + runId = "unittest" + configfile="wflow_hbv_hr.ini" + wflow_cloneMap = 'wflow_catchment.map' + caseName="wflow_hbv" + starttime = starttime = datetime.datetime(1990,01,01) + + myModel = wf.WflowModel(wflow_cloneMap, caseName,runId,configfile) + # initialise the framework + dynModelFw = wf.wf_DynamicFramework(myModel, stopTime,firstTimestep=startTime,datetimestart=starttime) + print dynModelFw.DT + + # Load model config from files and check directory structure + dynModelFw.createRunId(NoOverWrite=False,level=wf.logging.DEBUG) + # Run the initial part of the model (reads parameters and sets initial values) + dynModelFw._runInitial() # Runs initial part + + dynModelFw._runResume() # gets the state variables + sump = 0.0 + for ts in range(startTime,stopTime + 1): + if ts <10: + dynModelFw.wf_setValues('P', 0.0) + elif ts <= 15: + dynModelFw.wf_setValues('P', 10.0) + sump = sump + 10.0 + else: + dynModelFw.wf_setValues('P', 0.0) + + dynModelFw.wf_setValues('PET', 2.0) + dynModelFw.wf_setValues('TEMP', 10.0) + dynModelFw._runDynamic(ts,ts) # runs for all timesteps + dynModelFw.logger.info("Doing step: " + str(ts)) + dynModelFw._runSuspend() # saves the state variables + dynModelFw._wf_shutdown() + + # nore read the csv results acn check of they match the first run + # Sum should be approx c 4.569673676 + my_data = wf.genfromtxt(os.path.join(caseName,runId,"watbal.csv"), delimiter=',') + + print("Checking water budget ....") + self.assertAlmostEquals( -284.99871826171875,my_data[:,2].sum(),places=4) + + my_data = wf.genfromtxt(os.path.join(caseName,runId,"run.csv"), delimiter=',') + print("Checking discharge ....") + self.assertAlmostEquals(1837.79182650248212 ,my_data[:,2].mean(),places=4) + + print("Checking precip sum ....") + my_data = wf.genfromtxt(os.path.join(caseName,runId,"P.csv"), delimiter=',') + self.assertAlmostEquals(sump,my_data[:,2].sum()) + + +if __name__ == '__main__': + unittest.main() Index: wflow-py/UnitTests/wflow_hbv/wflow_hbv.ini =================================================================== diff -u -rce599a21046a69d80b7c251c236dfd2143fefbf1 -rc30e6377f07fd5c900d5431dd0df1bb1c0a10dc4 --- wflow-py/UnitTests/wflow_hbv/wflow_hbv.ini (.../wflow_hbv.ini) (revision ce599a21046a69d80b7c251c236dfd2143fefbf1) +++ wflow-py/UnitTests/wflow_hbv/wflow_hbv.ini (.../wflow_hbv.ini) (revision c30e6377f07fd5c900d5431dd0df1bb1c0a10dc4) @@ -48,7 +48,7 @@ # Model parameters and settings [model] -modeltype= sbm +modeltype= wflow_hbv AnnualDischarge=2290 # Alpha for wiver-width estimation 5 for mountain stream 60 for the river rhine @@ -88,12 +88,12 @@ [outputmaps] -#self.watbal=wat +self.watbal=wat +self.Precipitation=P - [summary] #self.CCup=CCup.map -#self.CClow=CClow.map +self.watbal=watbal.map # Save and average these per LU type [summary_sum] @@ -113,6 +113,7 @@ samplemap=staticmaps/wflow_subcatch.map self.Precipitation=P.csv self.watbal=watbal.csv +self.storage=storage.csv [outputcsv_0] samplemap=staticmaps/wflow_gauges.map Index: wflow-py/UnitTests/wflow_sceleton/outstate/TSoil.map =================================================================== diff -u -re879b0af6cf75726bb1ebd542a245abdffe48cef -rc30e6377f07fd5c900d5431dd0df1bb1c0a10dc4 Binary files differ Index: wflow-py/UnitTests/wflow_sceleton/wflow_sceleton.ini =================================================================== diff -u -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 -rc30e6377f07fd5c900d5431dd0df1bb1c0a10dc4 --- wflow-py/UnitTests/wflow_sceleton/wflow_sceleton.ini (.../wflow_sceleton.ini) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) +++ wflow-py/UnitTests/wflow_sceleton/wflow_sceleton.ini (.../wflow_sceleton.ini) (revision c30e6377f07fd5c900d5431dd0df1bb1c0a10dc4) @@ -22,7 +22,7 @@ timestepsecs = 86400 #start model with cold state reinit=0 -runlengthdetermination=intervals +runlengthdetermination=steps [modelparameters] Index: wflow-py/wflow/wflow_bmi.py =================================================================== diff -u -r6feb4db7b1bd34e7acb019e3393dd5774bdd5fa9 -rc30e6377f07fd5c900d5431dd0df1bb1c0a10dc4 --- wflow-py/wflow/wflow_bmi.py (.../wflow_bmi.py) (revision 6feb4db7b1bd34e7acb019e3393dd5774bdd5fa9) +++ wflow-py/wflow/wflow_bmi.py (.../wflow_bmi.py) (revision c30e6377f07fd5c900d5431dd0df1bb1c0a10dc4) @@ -220,7 +220,7 @@ Propagate the model dt (in seconds) """ - nrsteps = int(dt/self.dynModel.DT.timeStepSecs) + nrsteps = self.dynModel.DT.runTimeSteps self.bmilogger.debug("update: dt = " + str(dt)) self.bmilogger.debug("update: update " + str(nrsteps) + " timesteps.") if nrsteps >= 1: @@ -331,7 +331,7 @@ :return: start time in the units and epoch returned by the function get_time_units """ st = self.dynModel.wf_supplyStartTime() - self.bmilogger.debug("get_start_time: " + str(st)) + self.bmilogger.debug("get_start_time: " + str(st)+ " " + str(self.dynModel.DT.runStartTime.strftime("%Y-%m-%d %H:%M:%S"))) return st def get_end_time(self): @@ -341,7 +341,7 @@ :return: end time of simulation n the units and epoch returned by the function get_time_units """ et = self.dynModel.wf_supplyEndTime() - self.bmilogger.debug("get_end_time: " + str(et)) + self.bmilogger.debug("get_end_time: " + str(et)+ " " + str(self.dynModel.DT.runEndTime.strftime("%Y-%m-%d %H:%M:%S"))) return et def get_current_time(self): @@ -351,8 +351,11 @@ :return: current time of simulation n the units and epoch returned by the function get_time_units """ - st = self.dynModel.wf_supplyCurrentTime() - self.dynModel.DT.timeStepSecs - self.bmilogger.debug("get_current_time: " + str(st)) + + st = self.dynModel.wf_supplyCurrentTime() + self.bmilogger.debug( + "get_current_time: " + str(st) + " " + str(self.dynModel.DT.currentDateTime.strftime("%Y-%m-%d %H:%M:%S"))) + return st def get_time_step(self): Index: wflow-py/wflow/wflow_hbv.py =================================================================== diff -u -rfa013400d725fdca675d384153e2cc5a80108b1d -rc30e6377f07fd5c900d5431dd0df1bb1c0a10dc4 --- wflow-py/wflow/wflow_hbv.py (.../wflow_hbv.py) (revision fa013400d725fdca675d384153e2cc5a80108b1d) +++ wflow-py/wflow/wflow_hbv.py (.../wflow_hbv.py) (revision c30e6377f07fd5c900d5431dd0df1bb1c0a10dc4) @@ -950,7 +950,7 @@ self.sumlevel=self.sumlevel + self.WaterLevel self.suminflow=self.suminflow + self.Inflow self.storage=self.FreeWater + self.DrySnow + self.SoilMoisture + self.UpperZoneStorage + self.LowerZoneStorage + self.InterceptionStorage - self.watbal=self.initstorage+self.sumprecip-self.sumevap-self.sumrunoff-self.storage + self.watbal=(self.initstorage - self.storage)+self.sumprecip-self.sumevap-self.sumrunoff