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 4e627862 authored by Julien Veyssier's avatar Julien Veyssier
Browse files

improve step2 generator-style progress for qgis


Signed-off-by: default avatarJulien Veyssier <eneiluj@posteo.net>
parent fe7b442a
......@@ -503,6 +503,9 @@ def main(parms_file, nbProc, generator=False):
grass_run_command('g.remove', flags='f', type='raster', pattern='basin_tmp*', stdout=DEVNULL, stderr=DEVNULL)
rasters_list = ['basins']
if generator:
yield 5
# with grass7 watershed ids begin at 0
# empty areas value is already NULL, no need to set it
grass_run_command('r.mapcalc', expression='basins=basins+1', overwrite='True', stdout=DEVNULL, stderr=DEVNULL)
......@@ -529,6 +532,9 @@ def main(parms_file, nbProc, generator=False):
output=os.path.join(directory_out, 'step2_watersheds.tif'),
overwrite='True', stdout=DEVNULL, stderr=DEVNULL)
if generator:
yield 10
# Create mask = surface of all watersheds
print('---------- HRU-delin Step 2 : Creating the mask')
grass_run_command('r.null', map=basins_rcl, setnull=0, stdout=DEVNULL, stderr=DEVNULL)
......@@ -558,6 +564,9 @@ def main(parms_file, nbProc, generator=False):
if parms.get('auto_relocation', 'to_do') != 'yes' and maskIsTooSmall:
sys.exit('!!! Relocation is disabled and you are getting a very small mask. Please consider enabling gauge relocation.')
if generator:
yield 15
# Cutting the streams at gauges
print('---------- HRU-delin Step 2 : Cutting the streams at gauges')
cut_streams_at_gauges(directory_out, gauges_reloc_name)
......@@ -589,6 +598,9 @@ def main(parms_file, nbProc, generator=False):
print('---------- Compute cross product cross1*reachraster')
grass_run_command('r.mapcalc', expression='cross2=if(reachraster!=0, cross1, 0)', overwrite='True', stdout=DEVNULL, stderr=DEVNULL)
if generator:
yield 20
print('---------- Setting nulls in \'cross1*reachraster\' and \'reachraster\'')
grass_run_command('r.null', map='cross2', setnull=0, stdout=DEVNULL, stderr=DEVNULL)
grass_run_command('r.null', map='reachraster', setnull=0, stdout=DEVNULL, stderr=DEVNULL)
......@@ -636,7 +648,9 @@ def main(parms_file, nbProc, generator=False):
results = []
for i, _ in enumerate(p.imap_unordered(processReach, params), 1):
results.append(_)
yield (i/nbReachs*100)
loopProgress = i/nbReachs*100
globalProgress = 25 + (loopProgress/100*60)
yield globalProgress
else:
# this is the interesting part, launching N processes in parallel to process basins
# the locks are here to prevent concurrent terminal tqdm writing
......@@ -667,6 +681,9 @@ def main(parms_file, nbProc, generator=False):
pReclass.stdin.close()
pReclass.wait()
if generator:
yield 90
print('---------- Saving \'step2_subbasins.tif\'')
grass_run_command('r.out.gdal', input='cross1_reclassed', output=os.path.join(directory_out, 'step2_subbasins_2.tif'),
overwrite='True', stdout=DEVNULL, stderr=DEVNULL)
......@@ -691,6 +708,9 @@ def main(parms_file, nbProc, generator=False):
grass_run_command('r.to.vect', flags='v', quiet=True, input='cross1', output='cross1_vector', type='area', overwrite='True')
grass_run_command('r.to.vect', flags='v', quiet=True, input='cross1_reclassed', output='cross1_reclassed_vector', type='area', overwrite='True')
if generator:
yield 95
# to make sure there is a projection in exported files (grass78 complains)
grass_run_command('g.proj', flags='c', georef=drain_layer, stdout=DEVNULL, stderr=DEVNULL)
grass_run_command('v.out.ogr',
......
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