Commit 2eafc43d authored by Anthony's avatar Anthony
Browse files

Possibility to read Floodplains map from an another input

parent 27ba90a2
......@@ -12,6 +12,7 @@ import sys
import getargs
config = getargs.SetupConfig()
EarthRadius=config.getfloat("OverAll", "EarthRadius", fallback=6370000.0)
FloodplainsFile=config.get("OverAll", "FloodplainsFile", fallback=None)
#
import getargs
log_master, log_world = getargs.getLogger(__name__)
......@@ -134,6 +135,20 @@ class HydroGrid :
self.source=config.get("OverAll", "HydroFile")
INFO("Opening in HydroGrid : "+self.source)
self.ncfile=Dataset(self.source,'r')
#
# Test if floodplains is correct
if FloodplainsFile is not None:
try:
nfp = Dataset(FloodplainsFile, "r")
njgfp, nigfp = nfp.variables["floodplains"].shape
njg, nig = self.ncfile.variables["nav_lon"].shape
if ((njg != njgfp) or (nig != nigfp)):
ERROR("Invalid FloodplainsFile format. Hydrogrod: {0} / FPfile: {1}".format((njg, nig),(njgfp, nigfp)))
sys.exit()
except:
ERROR("Invalid FloodplainsFile :{0}".format(FloodplainsFile))
sys.exit()
#
istr, iend, jstr, jend = getbox(self.ncfile, lolacorners)
self.hdlon = np.mean(np.abs(np.diff(self.ncfile.variables["nav_lon"][0,:])))
self.hdlat = np.mean(np.abs(np.diff(self.ncfile.variables["nav_lat"][:,0])))
......@@ -234,7 +249,11 @@ class HydroData :
sys.exit()
#
#
if "floodplains" in nf.variables.keys():
if FloodplainsFile is not None:
nfp = Dataset(FloodplainsFile, "r")
self.floodplains = gather(nfp.variables["floodplains"][jstr:jend,istr:iend].astype(np.float32), index, 0)
#self.floodplainsdesc=nfp.variables["floodplains"].long_name
elif "floodplains" in nf.variables.keys():
self.floodplains = gather(nf.variables["floodplains"][jstr:jend,istr:iend].astype(np.float32), index, 0)
self.floodplainsdesc=nf.variables["floodplains"].long_name
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment