Index: examples/wflow_rhine_sbm/inmaps.nc =================================================================== diff -u Binary files differ Index: examples/wflow_rhine_sbm/wflow_sbm.ini =================================================================== diff -u -r3b29d4c807feb6a6664c21bbece6e0896e60b801 -r01a02941af2650cc7087fd1d02d95159062faad0 --- examples/wflow_rhine_sbm/wflow_sbm.ini (.../wflow_sbm.ini) (revision 3b29d4c807feb6a6664c21bbece6e0896e60b801) +++ examples/wflow_rhine_sbm/wflow_sbm.ini (.../wflow_sbm.ini) (revision 01a02941af2650cc7087fd1d02d95159062faad0) @@ -35,6 +35,7 @@ # 2: numpy # 3: matlab outputformat=1 +netcdfinput= inmaps.nc [layout] # if set to zero the cell-size is given in lat/long (the default) @@ -67,6 +68,9 @@ [summary_max] self.Precipitation=maxprecip.map +[summary_min] +self.Temperature=mintemp.map + [summary_avg] self.Precipitation=avgprecip.map Index: wflow-py/Scripts/pcr2netcdf.py =================================================================== diff -u -raeaf5fae8ecc7dbc8f4ee2a0025535d96006034b -r01a02941af2650cc7087fd1d02d95159062faad0 --- wflow-py/Scripts/pcr2netcdf.py (.../pcr2netcdf.py) (revision aeaf5fae8ecc7dbc8f4ee2a0025535d96006034b) +++ wflow-py/Scripts/pcr2netcdf.py (.../pcr2netcdf.py) (revision 01a02941af2650cc7087fd1d02d95159062faad0) @@ -235,7 +235,7 @@ varname=[] unit="mm" startstr="1-1-1990 00:00:00" - endstr="2 2 1990 :00:00:00" + endstr="2-2-1990 :00:00:00" mbuf=600 timestepsecs = 86400 Index: wflow-py/TODO.txt =================================================================== diff -u -r5fbcd8894b628c3de82388e2419d069c2addb07f -r01a02941af2650cc7087fd1d02d95159062faad0 --- wflow-py/TODO.txt (.../TODO.txt) (revision 5fbcd8894b628c3de82388e2419d069c2addb07f) +++ wflow-py/TODO.txt (.../TODO.txt) (revision 01a02941af2650cc7087fd1d02d95159062faad0) @@ -3,4 +3,7 @@ - Use partial wetness of cell in kinematic wave - Add add_reservoir function to framework - split kinematic wave from SBM and HBV +- read input maptacks from netcdf + +DONE: - add cumulative and average maps to framework \ No newline at end of file Index: wflow-py/wflow/wf_DynamicFramework.py =================================================================== diff -u -reb34ae59db2e16c7074bf15d10f795762d168393 -r01a02941af2650cc7087fd1d02d95159062faad0 --- wflow-py/wflow/wf_DynamicFramework.py (.../wf_DynamicFramework.py) (revision eb34ae59db2e16c7074bf15d10f795762d168393) +++ wflow-py/wflow/wf_DynamicFramework.py (.../wf_DynamicFramework.py) (revision 01a02941af2650cc7087fd1d02d95159062faad0) @@ -27,6 +27,7 @@ import shutil, glob import sys import traceback +import netCDF4 logging = None @@ -55,8 +56,44 @@ sys.excepthook = log_uncaught_exceptions +class netcdfinput(): + def __init__(self,netcdffile,logging,precipvar='P',petvar='PET',tempvar='TEMP',readinmem=True): + """ + First try to setup a class to facilitaye reading netcdf files + (converted with pcr2netcdf.py) + """ + self.dataset = netCDF4.Dataset(netcdffile,mode='r') + logging.info("Reading input from netCDF file: " + netcdffile + ": " + str(self.dataset).replace('\n',' ')) + self.alldat ={} + if readinmem: + self.alldat['P'] = self.dataset.variables[precipvar][:] + self.alldat['PET'] = self.dataset.variables[petvar][:] + self.alldat['TEMP'] = self.dataset.variables[tempvar][:] + else: + self.alldat['P'] = self.dataset.variables[precipvar] + self.alldat['PET'] = self.dataset.variables[petvar] + self.alldat['TEMP'] = self.dataset.variables[tempvar] + def gettimestep(self,timestep,logging,var='P'): + if self.alldat.has_key(var): + np_step = self.alldat[var][timestep,:,:] + return numpy2pcr(Scalar, np_step, 1E31) + else: + return cover(0.0) + + + +class netcdfoutput(): + def __init__(self): + """ + Under construction + """ + def savetimestep(self,timestep,var='P'): + """ + ss + """ + class wf_exchnageVariables(): """ List of exchange variables @@ -386,6 +423,10 @@ self.outputFormat = int(configget(self._userModel().config,'framework','outputformat','1')) self.APIDebug = int(configget(self._userModel().config,'framework','debug',str(self.APIDebug))) + self.ncfile = configget(self._userModel().config,'framework','netcdfinput',"None") + if self.ncfile != "None": + self.NcInput = netcdfinput(caseName +"/" + 'inmaps.nc',self.logger) + # Fill the summary (stat) list from the ini file self.statslst = [] _type = wf_sumavg(None) @@ -1329,7 +1370,7 @@ - def wf_readmap(self, name, default,verbose=True): + def wf_readmap(self, name, default,verbose=True,filetype='PCRaster'): """ Adjusted version of readmapNew. the style variable is used to indicated how the data is read:: @@ -1357,7 +1398,6 @@ style = self.exchnageitems.getvarStyle(varname) - if hasattr(self._userModel(), "_inStochastic"): if self._userModel()._inStochastic(): if self._userModel()._inPremc() or self._userModel()._inPostmc(): @@ -1381,14 +1421,17 @@ if style==1: # Normal reading of mapstack from DISK path = os.path.join(directoryPrefix, newName) assert path is not "" - + + if self.ncfile != "None": + return self.NcInput.gettimestep(self._userModel().currentTimeStep() -1 ,self.logger,var=varname) + if os.path.isfile(path): mapje=readmap(path) return mapje else: if verbose: self.logger.warn("Forcing data (" + path + ") for timestep not present, returning " + str(default)) - return scalar(default) + return scalar(default) elif style == 2: # Assyming they are set in memory by the API # first get basename (last bit of path) name = os.path.basename(name)