En raison du déménagement des baies serveurs, les services gitlab.irstea.fr et mattermost.irstea.fr seront interrompus le samedi 2 octobre 2021 au matin. Ils devraient revenir à la normale dans la journée.

Unverified Commit 0a7d968f authored by Julien Veyssier's avatar Julien Veyssier
Browse files

[step4] [reach] fix bug when there is only one reach


Signed-off-by: default avatarJulien Veyssier <eneiluj@posteo.net>
parent 519807e8
......@@ -355,12 +355,12 @@ def main(parms_file, nbProc, generator=False):
print('%s subbasins were found:' % len(basin_ids))
print('%s, %s, %s ... %s, %s, %s ' % (
basin_ids[0].rstrip('\n'),
basin_ids[1].rstrip('\n'),
basin_ids[0].rstrip('\n') if len(basin_ids) > 0 else '???',
basin_ids[1].rstrip('\n') if len(basin_ids) > 1 else '???',
basin_ids[2].rstrip('\n') if len(basin_ids) > 2 else '???',
basin_ids[-3].rstrip('\n') if len(basin_ids) > 2 else '???',
basin_ids[-2].rstrip('\n'),
basin_ids[-1].rstrip('\n')
basin_ids[-2].rstrip('\n') if len(basin_ids) > 1 else '???',
basin_ids[-1].rstrip('\n') if len(basin_ids) > 0 else '???'
))
print('------------- subbasin loop started -------------', time.strftime('%a, %d %b %Y, %H:%M:%S', time.localtime()))
print('')
......
......@@ -57,15 +57,17 @@ def getTopo(inp_vals):
topo = decode(grass_read_command('r.stats', quiet=True, flags='lnN', input='map_c')).rstrip(os.linesep).split(os.linesep)
for relation in topo:
# this only happens with grass74
if relation.strip() == '0':
from_node = a.strip()
to_node = b.strip()
topo_dict[from_node] = to_node
else:
from_node = int(relation.split(' ')[2].rstrip(';'))
to_node = int(relation.split(' ')[4])
topo_dict[from_node] = to_node
relStripped = relation.strip()
if relStripped != '':
# this only happens with grass74
if relStripped == '0':
from_node = a.strip()
to_node = b.strip()
topo_dict[from_node] = to_node
else:
from_node = int(relation.split(' ')[2].rstrip(';'))
to_node = int(relation.split(' ')[4])
topo_dict[from_node] = to_node
outletReachID = getOutletReachID(topo_dict)
topo_dict[outletReachID] = 0
return topo_dict
......@@ -178,6 +180,12 @@ def buildReachPar(streamsP, watershedP, drainageP, demP, outputP, pathP, nbProcP
grass_run_command('r.null', map='%(streams)s' % inp_vals, setnull='0,9999', stdout=DEVNULL, stderr=DEVNULL)
# GET REACH IDs
reachIDs = decode(grass_read_command('r.category', map='%(streams)s' % inp_vals, stdout=DEVNULL, stderr=DEVNULL)).rstrip(os.linesep).split(os.linesep)
# if there is only one reach, it does not make sense to get topology
# we just put the reach as outlet
if len(reachIDs) == 1:
topo_dict = {}
intReachId = int(reachIDs[0].strip())
topo_dict[intReachId] = 0
#print('reach ids: %s' % reachIDs)
len_dict = {}
slp_dict = {}
......
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