Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
hru-delin-dev
hru-delin
Commits
4e627862
Unverified
Commit
4e627862
authored
Apr 23, 2020
by
Julien Veyssier
Browse files
improve step2 generator-style progress for qgis
Signed-off-by:
Julien Veyssier
<
eneiluj@posteo.net
>
parent
fe7b442a
Changes
1
Show whitespace changes
Inline
Side-by-side
modules/hrudelin_2_basins.py
View file @
4e627862
...
...
@@ -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'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment