forked from DHI-GRAS/budyko-qgis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
budyko_qgis_script.py
55 lines (45 loc) · 1.71 KB
/
budyko_qgis_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
##Budyko=group
##Budyko Hydrological Model=name
##ParameterFile|GEOMETRY_FILE|Geometry setup|False|False
##ParameterFile|MODEL_FILE|Model setup|False|False
##ParameterFile|OBS_REACH_FILE|Observed-discharge file|False|False
##ParameterFile|PARAMETER_FILE|Model parameter file|False|True
##ParameterNumber|REACH_NUMBER|Reach number considered|0|10000|0
##ParameterString|STARTDATE|Start date YYYYJJJ|
##ParameterSelection|MODEL_TYPE_ID|Output type|Hydrograph;Climatology;FDC|0
##OutputDirectory|OUTDIR|Output directory for plots
##ParameterSelection|TIME_RESOLUTION_ID|Time resolution|daily;monthly|0
##*ParameterNumber|N_CLASSES|Number of volume classes for FDC|0|1000|20
##*ParameterString|FIGURE_TITLE|Title for plot|||True
import sys
from contextlib import contextmanager
from budyko_model.scripts import middle_layer
class ProgressLogger:
def __init__(self, progress):
self.progress = progress
def write(self, msg):
self.progress.setConsoleInfo(msg)
@contextmanager
def redirect_stdout(progress):
oldout = sys.stdout
sys.stdout = ProgressLogger(progress)
try:
yield
finally:
sys.stdout = oldout
time_resolution = ['daily', 'monthly'][TIME_RESOLUTION_ID]
model_type = ['hydrograph', 'climatology', 'fdc'][MODEL_TYPE_ID]
with redirect_stdout(progress):
middle_layer.main(
geometry_file=GEOMETRY_FILE,
model_file=MODEL_FILE,
parameter_file=(PARAMETER_FILE or None),
obs_reach_file=OBS_REACH_FILE,
outdir=OUTDIR,
reach_number=REACH_NUMBER,
startdate=STARTDATE,
model_type=model_type,
time_resolution=time_resolution,
n_classes=N_CLASSES,
figure_title=FIGURE_TITLE,
show_figure=True)