Index: wflow-py/UnitTests/TestBMI.py =================================================================== diff -u -r34093e71c2f49d90a1e7df46b73ecf07913ca68f -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 --- wflow-py/UnitTests/TestBMI.py (.../TestBMI.py) (revision 34093e71c2f49d90a1e7df46b73ecf07913ca68f) +++ wflow-py/UnitTests/TestBMI.py (.../TestBMI.py) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) @@ -142,15 +142,17 @@ def testbmirun(self): bmiobj = bmi.wflowbmi_csdms() - bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR) + bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.DEBUG) print(bmiobj.get_var_type("IF")) et = bmiobj.get_end_time() st = bmiobj.get_start_time() ts = 86400 - # Do one timestep and check - bmiobj.get_current_time() + # Do timesteps and chak + bmiobj.update_until(et) + bmiobj.get_current_time() bmiobj.finalize() + print et - bmiobj.get_current_time() self.assertEquals(et,bmiobj.get_current_time()) Index: wflow-py/UnitTests/Testwflow_sbm2.py =================================================================== diff -u -r34093e71c2f49d90a1e7df46b73ecf07913ca68f -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 --- wflow-py/UnitTests/Testwflow_sbm2.py (.../Testwflow_sbm2.py) (revision 34093e71c2f49d90a1e7df46b73ecf07913ca68f) +++ wflow-py/UnitTests/Testwflow_sbm2.py (.../Testwflow_sbm2.py) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) @@ -56,7 +56,7 @@ self.assertAlmostEquals(-1.003901559215592e-06,my_data[:,2].sum(),places=4) my_data = wf.genfromtxt(os.path.join(caseName,runId,"wbsoil.csv"), delimiter=',') print("Checking soil water budget ....") - self.assertAlmostEquals(0.020174235052422773,my_data[:,2].sum(),places=4) + self.assertAlmostEquals(0.00055434828220768395,my_data[:,2].sum(),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()) Index: wflow-py/UnitTests/wflow_sceleton/wflow_sceleton.ini =================================================================== diff -u -r0d46ee66e7021b4c277c74f874d16ad34213879f -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 --- wflow-py/UnitTests/wflow_sceleton/wflow_sceleton.ini (.../wflow_sceleton.ini) (revision 0d46ee66e7021b4c277c74f874d16ad34213879f) +++ wflow-py/UnitTests/wflow_sceleton/wflow_sceleton.ini (.../wflow_sceleton.ini) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) @@ -22,7 +22,7 @@ timestepsecs = 86400 #start model with cold state reinit=0 -#runlengthdetermination=intervals +runlengthdetermination=intervals [modelparameters] Index: wflow-py/wflow/wf_DynamicFramework.py =================================================================== diff -u -r82ba61f9d22c73214eb3b915be22b0f8fc64b5e6 -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 --- wflow-py/wflow/wf_DynamicFramework.py (.../wf_DynamicFramework.py) (revision 82ba61f9d22c73214eb3b915be22b0f8fc64b5e6) +++ wflow-py/wflow/wf_DynamicFramework.py (.../wf_DynamicFramework.py) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) @@ -50,15 +50,17 @@ """ """ - def __init__(self, datetimestart=dt.datetime(1990, 01, 01),datetimeend=dt.datetime(1990, 01, 05),timestepsecs=86400,mode='steps'): + def __init__(self, datetimestart=dt.datetime(1990, 01, 01),datetimeend=dt.datetime(1990, 01, 05), + timestepsecs=86400,mode='steps'): self.runStartTime = datetimestart self.runEndTime = datetimeend self.timeStepSecs = timestepsecs - self.currentTimeStep = 1 + self.currentTimeStep = 0 self.startadjusted = 0 self.startendadjusted = 0 self.currentmode = mode + if mode =='steps': self.runStateTime = self.runStartTime - datetime.timedelta(seconds=self.timeStepSecs) else: @@ -70,6 +72,7 @@ self.currentMonth = self.currentDateTime.month self.currentYday = self.currentDateTime.timetuple().tm_yday self.currentHour = self.currentDateTime.hour + self.nextDateTime = self.currentDateTime + datetime.timedelta(seconds=self.timeStepSecs) def __str__(self): a = self.__dict__ @@ -83,7 +86,7 @@ use the mode option to switch between steps and intervals ('steps' or 'intervals') :param timestepsecs: - :param datetimestart: + :param datetimestart: data time start of the input data :param datetimeend: :param currentTimeStep: :param currentDatetime: @@ -95,42 +98,47 @@ self.timeStepSecs = timestepsecs self.runTimeSteps = (calendar.timegm(self.runEndTime.utctimetuple()) - calendar.timegm(self.runStateTime.utctimetuple()))/self.timeStepSecs if mode =='steps': - self.runStateTime = self.runStartTime - datetime.timedelta(seconds=self.timeStepSecs) + self.startadjusted = 0 else: - self.runStateTime = self.runStartTime + self.startadjusted = 1 + self.runStateTime = self.runStartTime - datetime.timedelta(seconds=self.timeStepSecs) self.outPutStartTime = self.runStateTime + datetime.timedelta(seconds=self.timeStepSecs) elif timestepsecs and runTimeSteps: self.timeStepSecs = timestepsecs self.runTimeSteps = runTimeSteps if datetimestart: - self.runStartTime = datetimestart self.currentTimeStep = 1 - if self.currentmode =='steps': - self.runStateTime = self.runStartTime - datetime.timedelta(seconds=self.timeStepSecs) + self.runStartTime = datetimestart + self.startadjusted = 0 else: - self.runStateTime = self.runStartTime + self.runStartTime = datetimestart + datetime.timedelta(seconds=self.timeStepSecs) + self.startadjusted = 1 - self.currentDateTime = self.runStateTime - self.outPutStartTime = self.runStateTime + datetime.timedelta(seconds=self.timeStepSecs) + self.runStateTime = self.runStartTime - datetime.timedelta(seconds=self.timeStepSecs) + self.currentDateTime = self.runStartTime + self.outPutStartTime = self.currentDateTime + datetime.timedelta(seconds=self.timeStepSecs) self.runTimeSteps = (calendar.timegm(self.runEndTime.utctimetuple()) - calendar.timegm(self.runStateTime.utctimetuple()))/self.timeStepSecs self.currentMonth = self.currentDateTime.month self.currentYday = self.currentDateTime.timetuple().tm_yday self.currentHour = self.currentDateTime.hour if datetimestart and runTimeSteps: - self.runStartTime = datetimestart + self.currentTimeStep = 1 self.currentDateTime = self.runStartTime if self.currentmode =='steps': - self.runStateTime = self.runStartTime - datetime.timedelta(seconds=self.timeStepSecs) + self.runStartTime = datetimestart + self.startadjusted = 0 else: - self.runStateTime = self.runStartTime - self.currentDateTime = self.runStateTime + self.runStartTime = datetimestart + datetime.timedelta(seconds=self.timeStepSecs) + self.startadjusted = 1 + self.runStateTime = self.runStartTime - datetime.timedelta(seconds=self.timeStepSecs) self.outPutStartTime = self.runStateTime + datetime.timedelta(seconds=self.timeStepSecs) + self.currentDateTime = self.runStartTime self.runEndTime = self.runStateTime + datetime.timedelta(seconds=self.timeStepSecs * runTimeSteps) self.currentMonth = self.currentDateTime.month self.currentYday = self.currentDateTime.timetuple().tm_yday @@ -153,16 +161,19 @@ self.currentMonth = self.currentDateTime.month self.currentYday = self.currentDateTime.timetuple().tm_yday self.currentHour = self.currentDateTime.hour - self.currentTimeStep = (calendar.timegm(self.currentDateTime.utctimetuple()) - calendar.timegm(self.runStateTime.utctimetuple()))/self.timeStepSecs +1 + self.currentTimeStep = (calendar.timegm(self.currentDateTime.utctimetuple()) - + calendar.timegm(self.runStateTime.utctimetuple()))/self.timeStepSecs +1 + self.nextDateTime = self.currentDateTime + datetime.timedelta(seconds=self.timeStepSecs) + class wf_exchnageVariables(): """ List of exchange variables The style determined how they are used - 1: read from file like normal - - 2: set by the api in mem (for consistancy this is style 0 in the ini file) + - 2: set by the api in mem (for consistency this is style 0 in the ini file) """ def __init__(self): @@ -472,7 +483,10 @@ self.APIDebug = 0 self._userModel().currentdatetime = self.DT.currentDateTime - self._userModel()._setCurrentTimeStep(int(self.DT.currentTimeStep)) + if self.DT.currentTimeStep == 0: + self._userModel()._setCurrentTimeStep(1) + else: + self._userModel()._setCurrentTimeStep(int(self.DT.currentTimeStep)) self._userModel().timestepsecs = self.DT.timeStepSecs @@ -934,6 +948,7 @@ self._userModel().currentdatetime = self.DT.currentDateTime self.DT.update(timestepsecs=int(configget(self._userModel().config, 'run', 'timestepsecs', "86400")), mode=self.runlengthdetermination) + self.DT.update(currentTimeStep=self.DT.currentTimeStep, mode=self.runlengthdetermination) self._update_time_from_DT() else: self.logger.info( @@ -951,6 +966,7 @@ ed = configget(self._userModel().config, 'run', 'endtime', "None") self.DT.update(datetimeend=parser.parse(ed), mode=self.runlengthdetermination) self.DT.update(timestepsecs=int(configget(self._userModel().config, 'run', 'timestepsecs', "86400")), mode=self.runlengthdetermination) + self.DT.update(currentTimeStep=self.DT.currentTimeStep, mode=self.runlengthdetermination) self._update_time_from_DT() @@ -1004,14 +1020,23 @@ # Setup all the netCDF files that may be used for input/output if self.ncfile != "None": varlst = [] - for ms in self._userModel().parameters(): - if ms.type == 'timeseries': - varlst.append(os.path.basename(ms.stack)) + if hasattr(self._userModel(),'parameters'): + for ms in self._userModel().parameters(): + if ms.type == 'timeseries': + varlst.append(os.path.basename(ms.stack)) + + mstacks = configsection(self._userModel().config, "inputmapstacks") + for ms in mstacks: + varlst.append(os.path.basename(configget(self._userModel().config, 'inputmapstacks', ms, 'None'))) + self.logger.debug("Found following input variables to get from netcdf file: " + str(varlst)) self.NcInput = netcdfinput(os.path.join(caseName, self.ncfile), self.logger, varlst) + self.logger.debug("Found following input variables to get from netcdf file: " + str(varlst)) + self.NcInput = netcdfinput(os.path.join(caseName, self.ncfile), self.logger, varlst) + if self.ncfilestates != "None": smaps = self._userModel().stateVariables() maps = [s + ".map" for s in smaps] @@ -2042,9 +2067,10 @@ laststep = self._d_lastTimestep self._userModel()._setNrTimeSteps(int(laststep)) - + self.DT.update(currentTimeStep=self.DT.currentTimeStep, mode=self.runlengthdetermination) + self.logger.debug(self.DT.currentDateTime) while step <= self._userModel().nrTimeSteps(): - + self.logger.debug("before:" + str(self.DT.currentDateTime)) self._incrementIndentLevel() self._atStartOfTimeStep(step) # TODO: Check why the timestep setting doesn't work..... @@ -2077,8 +2103,8 @@ self.DT.update(currentTimeStep=self.DT.currentTimeStep+1, mode=self.runlengthdetermination) self._userModel().currentdatetime = self.DT.currentDateTime self.logger.debug("timestep: " + str(self.DT.currentTimeStep-1) + "/" + str(self.DT.runTimeSteps) + " (" + str(self.DT.currentDateTime) + ")") + self.logger.debug("after:" + str(self.DT.currentDateTime)) - self._timeStepFinished() self._decrementIndentLevel() step += 1 @@ -2367,7 +2393,7 @@ if self._userModel()._inDynamic(): if 'None' not in self.ncfile: retval, succ = self.NcInput.gettimestep(self._userModel().currentTimeStep(), self.logger, - tsdatetime=self.DT.currentDateTime, var=varname, + tsdatetime=self.DT.nextDateTime, var=varname, shifttime=self.DT.startadjusted) if succ: return retval Index: wflow-py/wflow/wf_netcdfio.py =================================================================== diff -u -ra60252674c7e7ee5a5f6016dd1117b6e6593bda8 -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 --- wflow-py/wflow/wf_netcdfio.py (.../wf_netcdfio.py) (revision a60252674c7e7ee5a5f6016dd1117b6e6593bda8) +++ wflow-py/wflow/wf_netcdfio.py (.../wf_netcdfio.py) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) @@ -533,6 +533,7 @@ if tsdatetime != None: if tsdatetime != self.datetimelist[ncindex]: logging.warn("Date/time does not match. Wanted " + str(tsdatetime) + " got " + str(self.datetimelist[ncindex])) + logging.warn("Index: " + str(ncindex) + " Par: " + var) if self.alldat.has_key(var): if ncindex == self.lstep: # Read new block of data in mem Index: wflow-py/wflow/wflow_hbv.py =================================================================== diff -u -r82ba61f9d22c73214eb3b915be22b0f8fc64b5e6 -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 --- wflow-py/wflow/wflow_hbv.py (.../wflow_hbv.py) (revision 82ba61f9d22c73214eb3b915be22b0f8fc64b5e6) +++ wflow-py/wflow/wflow_hbv.py (.../wflow_hbv.py) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) @@ -660,7 +660,7 @@ """ self.wf_updateparameters() # read forcing an dynamic parameters - self.Precipitation = max(0.0,self.Precipitation) * self.Pcorr + self.Precipitation = max(0.0,self.Precipitation) * self.Pcorr #self.Precipitation=cover(self.wf_readmap(self.P_mapstack,0.0),0.0) * self.Pcorr #self.PotEvaporation=cover(self.wf_readmap(self.PET_mapstack,0.0),0.0) Index: wflow-py/wflow/wflow_w3ra.py =================================================================== diff -u -r1b94591824be39aa254dfefe6ddddbc01ed5e98b -r37e269ce4338ed9cfba3e4e6b6720ed3af463818 --- wflow-py/wflow/wflow_w3ra.py (.../wflow_w3ra.py) (revision 1b94591824be39aa254dfefe6ddddbc01ed5e98b) +++ wflow-py/wflow/wflow_w3ra.py (.../wflow_w3ra.py) (revision 37e269ce4338ed9cfba3e4e6b6720ed3af463818) @@ -280,6 +280,7 @@ See wf_updateparameters and the parameters section of the ini file If you use this make sure to all wf_updateparameters at the start of the dynamic section and at the start/end of the initial section + :returns modelparameters: list of model parameters """ modelparameters = [] @@ -300,10 +301,10 @@ #modelparameters.append(self.ParamType(name="PotenEvap",stack=self.PET_mapstack,type="timeseries",default=0.0,verbose=True,lookupmaps=[])) #modelparameters.append(self.ParamType(name="Temperature",stack=self.TEMP_mapstack,type="timeseries",default=10.0,verbose=True,lookupmaps=[])) #modelparameters.append(self.ParamType(name="Inflow",stack=self.Inflow_mapstack,type="timeseries",default=0.0,verbose=False,lookupmaps=[])) + return modelparameters - def dynamic(self): """ *Required*