Commit c0fe4d86 authored by POLCHER Jan's avatar POLCHER Jan 🚴🏾
Browse files

Better manage default values for topoindex during the gather.

parent 793af1f8
......@@ -93,6 +93,7 @@ def calctopoindex(nf, istr, iend, jstr, jend, index, hydrogrid) :
else :
# Endorehic basin so we use thte lowest dz possible.
dz = elevation_precision
#
if nf.variables["disto"][jstr+j,istr+i] > 0 :
dl = nf.variables["disto"][jstr+j,istr+i]
else :
......@@ -106,7 +107,7 @@ def calctopoindex(nf, istr, iend, jstr, jend, index, hydrogrid) :
ERROR("Topoind close to zero encoutered.")
sys.exit()
#
return gather(topoind, index), "Topographic index which serves for the residence time", minitopo
return gather(topoind, index, default = 10), "Topographic index which serves for the residence time", minitopo
#
class HydroGrid :
def __init__(self, lolacorners, wfile) :
......@@ -158,7 +159,7 @@ class HydroData :
#
# Flow direction
#
self.trip=gather(nf.variables["trip"][jstr:jend,istr:iend].astype(np.float32), index, 97)
self.trip=gather(nf.variables["trip"][jstr:jend,istr:iend].astype(np.float32), index, default = 98)
self.tripdesc=nf.variables["trip"].long_name
#
# ID of basin
......@@ -177,25 +178,25 @@ class HydroData :
#
# Distance to ocean
#
self.disto=gather(nf.variables["disto"][jstr:jend,istr:iend].astype(np.float32), index, 0)
self.disto=gather(nf.variables["disto"][jstr:jend,istr:iend].astype(np.float32), index, default = 500)
self.distodesc=nf.variables["disto"].long_name
#
# Flow accumulation
#
self.fac=gather(nf.variables["fac"][jstr:jend,istr:iend].astype(np.float32), index, 0)
self.fac=gather(nf.variables["fac"][jstr:jend,istr:iend].astype(np.float32), index, default = 0)
self.facdesc=nf.variables["fac"].long_name
#
# If Orography is present in the file then we can compute the topographic index.
# Else the topographic index needs to be present in the file.
#
if "orog" in nf.variables.keys() and "disto" in nf.variables.keys() :
self.orog = gather(nf.variables["orog"][jstr:jend,istr:iend].astype(np.float32), index, 0)
self.orog = gather(nf.variables["orog"][jstr:jend,istr:iend].astype(np.float32), index, default = 0)
self.orogdesc=nf.variables["orog"].long_name
self.topoind, self.topoinddesc, mintopo = calctopoindex(nf, istr, iend, jstr, jend, index, hydrogrid)
self.topoindmin = part.domainmin(mintopo)
elif "topoind" in nf.variables.keys() :
elif "topoind" in nf.variables.keys() and "orog" in nf.variables.keys() :
self.orog = gather(np.zeros((jend-jstr,iend-istr)).astype(np.float32), index)
self.topoind=gather(nf.variables["topoind"][jstr:jend,istr:iend].astype(np.float32), index, 10)
self.topoind=gather(nf.variables["topoind"][jstr:jend,istr:iend].astype(np.float32), index, default = 10)
self.topoinddesc=nf.variables["topoind"].long_name
att = getattrcontaining(nf, "topoind", "min")
if len(att) > 0 :
......
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