Skip to content

Commit

Permalink
Merge pull request #103 from LabSid-USP/refactoring/rubem-configuration
Browse files Browse the repository at this point in the history
Implement a configuration system within the application that can handle multiple formats
  • Loading branch information
soaressgabriel committed Feb 19, 2024
2 parents 271e074 + 2b98b52 commit 64d08b4
Show file tree
Hide file tree
Showing 46 changed files with 2,872 additions and 905 deletions.
104 changes: 104 additions & 0 deletions appsettings.json
@@ -0,0 +1,104 @@
{
"value_ranges": {
"rasters": {
"dem": {
"min": -100.0,
"max": 10000.0
},
"clone": {
"min": 0.0,
"max": 1.0
},
"ndvi": {
"min": -1.0,
"max": 1.0
},
"soil": {
"min": 0.0,
"max": "Infinity"
},
"sample_locations": {
"min": 0.0,
"max": "Infinity"
},
"etp": {
"min": 0.0,
"max": "Infinity"
},
"precipitation": {
"min": 0.0,
"max": "Infinity"
},
"kp": {
"min": 0.0,
"max": 1.0
},
"landuse": {
"min": 0.0,
"max": "Infinity"
}
},
"variables": {
"fraction_photo_active_radiation": {
"min": 0.0,
"max": 1.0
},
"leaf_area_interception_max": {
"min": 0.0,
"max": 12.0
},
"impervious_area_interception": {
"min": 0.0,
"max": 3.0
},
"initial_soil_moisture_content": {
"min": 0.0,
"max": 1.0
},
"baseflow": {
"min": 0.0,
"max": "Infinity"
},
"initial_saturated_zone_storage": {
"min": 0.0,
"max": "Infinity"
},
"alpha": {
"min": 0.01,
"max": 10.0
},
"beta": {
"min": 0.01,
"max": 1.0
},
"w_1": {
"min": 0.0,
"max": 1.0
},
"w_2": {
"min": 0.0,
"max": 1.0
},
"w_3": {
"min": 0.0,
"max": 1.0
},
"rcd": {
"min": 1.0,
"max": 10.0
},
"f": {
"min": 0.01,
"max": 1.0
},
"alpha_gw": {
"min": 0.01,
"max": 1.0
},
"x": {
"min": 0.0,
"max": 1.0
}
}
}
}
2 changes: 1 addition & 1 deletion doc/source/installation.rst
Expand Up @@ -16,4 +16,4 @@ In the appropriate Conda environment run the following command within the root d

.. code-block:: console
python rubem.py -h
python rubem -h
2 changes: 1 addition & 1 deletion doc/source/tutorials.rst
Expand Up @@ -493,7 +493,7 @@ In a proper Conda environment, run the following command:

.. code-block:: console
$ python rubem.py --configfile Iguazu.ini
$ python rubem -c Iguazu.ini
If all the project's configuration file is specified correctly, the user should be faced with the following:

Expand Down
80 changes: 39 additions & 41 deletions doc/source/userguide.rst
Expand Up @@ -880,9 +880,9 @@ When running RUBEM without any arguments, you will see the following message on

.. code-block:: console
$ python rubem.py
usage: RUBEM [-h] --configfile CONFIGFILE [--version] [--verbose]
RUBEM: error: the following arguments are required: --configfile
$ python rubem
usage: rubem [-h] -c CONFIGFILE [-V] [-s]
rubem: error: the following arguments are required: -c/--configfile
Command Line Options
````````````````````
Expand All @@ -891,59 +891,57 @@ Use ``-h`` or ``--help`` to get a brief description of RUBEM and each argument.

.. code-block:: console
$ python rubem.py --help
usage: RUBEM [-h] --configfile CONFIGFILE [--version] [--verbose]
$ python rubem -h
usage: rubem [-h] -c CONFIGFILE [-V] [-s]
Rainfall rUnoff Balance Enhanced Model (RUBEM)
optional arguments:
-h, --help show this help message and exit
--configfile CONFIGFILE
-c CONFIGFILE, --configfile CONFIGFILE
path to configuration file
--version, -V show program's version number and exit
--verbose, -v set the verbosity level
-V, --version show version and exit
-s, --skip-inputs-validation
disable input files validation before running the model
Developed by LabSid-PHA-EPUSP
RUBEM 0.2.3-beta.2 Copyright (C) 2020-2024 - LabSid/PHA/EPUSP -This program comes with ABSOLUTELY NO WARRANTY.This is free software, and you are welcome to redistribute it under
certain conditions.
Use ``-V`` or ``--version`` to get the version of the RUBEM.

.. code-block:: console
$ python rubem.py --version
RUBEM v0.1.3
$ python rubem --version
RUBEM v0.2.3-beta.2
Use ``-c`` or ``--configfile`` to set the path of the RUBEM configuration file.

.. code-block:: console
$ python rubem.py --configfile project-config.ini
RUBEM::Started
RUBEM::Reading configuration file... OK
RUBEM::Running dynamic model...
RUBEM::Reading input files... OK
.Time: 1
Interception... OK
Evapotranspiration... OK
Surface Runoff... OK
Lateral Flow... OK
Recharge Flow... OK
Baseflow... OK
Soil Balance... OK
Runoff... OK
Exporting variables to files... OK
Ending cycle 1 of 2
.Time: 2
Interception... OK
Evapotranspiration... OK
Surface Runoff... OK
Lateral Flow... OK
Recharge Flow... OK
Baseflow... OK
Soil Balance... OK
Runoff... OK
Exporting variables to files... OK
Ending cycle 2 of 2
RUBEM::Dynamic model runtime: 3.28 seconds
RUBEM::Converting *.tss files to *.csv... OK
RUBEM::Finished
$ python rubem --configfile project-config.ini
.## Timestep 1 of 24
.## Timestep 2 of 24
.## Timestep 3 of 24
.## Timestep 4 of 24
.## Timestep 5 of 24
.## Timestep 6 of 24
.## Timestep 7 of 24
.## Timestep 8 of 24
.## Timestep 9 of 24
.## Timestep 10 of 24
.## Timestep 11 of 24
.## Timestep 12 of 24
.## Timestep 13 of 24
.## Timestep 14 of 24
.## Timestep 15 of 24
.## Timestep 16 of 24
.## Timestep 17 of 24
.## Timestep 18 of 24
.## Timestep 19 of 24
.## Timestep 20 of 24
.## Timestep 21 of 24
.## Timestep 22 of 24
.## Timestep 23 of 24
.## Timestep 24 of 24
35 changes: 29 additions & 6 deletions env-dev.yml
@@ -1,8 +1,31 @@
channels:
- conda-forge
- defaults
- conda-forge
- defaults
dependencies:
- python=3.10
- gdal
- pandas
- pcraster
- python=3.9.*
- gdal
- pandas
- pcraster
- pip
- py
- pyfakefs
- pytest
- pytest-cov
- pytest-forked
- pytest-mock
- pytest-xdist
- python-dateutil
- tzdata
- pip:
- sphinx
- sphinx-autodoc-typehints
- sphinx-rtd-theme
- sphinxcontrib-applehelp
- sphinxcontrib-devhelp
- sphinxcontrib-email
- sphinxcontrib-htmlhelp
- sphinxcontrib-jquery
- sphinxcontrib-jsmath
- sphinxcontrib-qthelp
- sphinxcontrib-serializinghtml
- sphinxcontrib-youtube
5 changes: 5 additions & 0 deletions pytest.ini
@@ -0,0 +1,5 @@
[pytest]
markers =
slow: mark test as slow.
unit: mark a test as a unit test.
integration: mark a test as a integration test.
22 changes: 0 additions & 22 deletions rubem/__init__.py
@@ -1,25 +1,3 @@
# coding=utf-8
# RUBEM is a distributed hydrological model to calculate monthly
# flows with changes in land use over time.
# Copyright (C) 2020-2024 LabSid PHA EPUSP

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Contact: rubem.hydrological@labsid.eng.br

"""Rainfall rUnoff Balance Enhanced Model"""

# Set default logging handler to avoid "No handler found" warnings.
import logging
from logging import NullHandler
Expand Down
9 changes: 8 additions & 1 deletion rubem/__main__.py
@@ -1,4 +1,11 @@
from rubem.cli import main
import os
import sys

try:
from rubem.cli import main
except ModuleNotFoundError:
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
from rubem.cli import main

if __name__ == "__main__":
main()

0 comments on commit 64d08b4

Please sign in to comment.