Skip to content

Commit

Permalink
Merge branch 'master' into params_to_hidden_config
Browse files Browse the repository at this point in the history
  • Loading branch information
landam authored Nov 14, 2023
2 parents 150031e + 8678cd5 commit daa2db3
Show file tree
Hide file tree
Showing 438 changed files with 41,981 additions and 84,134 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/cmd_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ jobs:
python-version: ${{ matrix.python-version }}
pytest-suite: tests/test_cmd.py --config config_files/quicktest_sheet_stream.ini

smoderp2d-quicktest-stream-rill:
strategy:
matrix:
python-version:
# - "2.7"
- "3.9"
- "3.11"

uses: ./.github/workflows/cmd_template.yml
with:
python-version: ${{ matrix.python-version }}
pytest-suite: tests/test_cmd.py --config config_files/quicktest_stream_rill.ini

smoderp2d-longtest-sheet:
strategy:
matrix:
Expand Down Expand Up @@ -87,6 +100,19 @@ jobs:
python-version: ${{ matrix.python-version }}
pytest-suite: tests/test_cmd.py --config config_files/test_sheet_stream.ini

smoderp2d-longtest-stream-rill:
strategy:
matrix:
python-version:
# - "2.7"
- "3.9"
- "3.11"

uses: ./.github/workflows/cmd_template.yml
with:
python-version: ${{ matrix.python-version }}
pytest-suite: tests/test_cmd.py --config config_files/test_stream_rill.ini

profile1d:
strategy:
matrix:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/grass_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:

runs-on: ubuntu-22.04
container:
image: mundialis/grass-py3-pdal:latest-debian
image: osgeo/grass-gis:releasebranch_8_3-debian

steps:
- uses: actions/checkout@v3

- name: Install Python dependencies
run: |
pip3 install -r .github/workflows/requirements.txt
pip3 install -r .github/workflows/requirements3.11.txt
pip3 install --break-system-packages -r .github/workflows/requirements.txt
pip3 install --break-system-packages -r .github/workflows/requirements3.11.txt
- name: Run GRASS test suite
run: |
Expand Down
38 changes: 36 additions & 2 deletions bin/grass/r.smoderp2d/r.smoderp2d.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ <h2>DESCRIPTION</h2>

<h2>EXAMPLE</h2>

Run quick test:
<h3>Nucice dataset</h3>

<div class="code"><pre>
grass -c EPSG:5514 /tmp/smoderp2d-nucice --exec python3 tests/data/import_grass.py tests/data/nucice
grass -c /tmp/smoderp2d-nucice/test
</pre></div>

Perform computation on Nucice dataset:

<div class="code"><pre>
r.smoderp2d \
Expand All @@ -14,7 +21,7 @@ <h2>EXAMPLE</h2>
soil_type_fieldname=SID \
vegetation=landuse@PERMANENT \
vegetation_type_fieldname=LandUse \
rainfall_file=tests/data/rainfall.txt \
rainfall_file=tests/data/rainfall_nucice.txt \
maxdt=30 end_time=40 \
points=points@PERMANENT \
table_soil_vegetation=soil_veg_tab_mean@PERMANENT \
Expand All @@ -25,6 +32,33 @@ <h2>EXAMPLE</h2>
output=tests/data/output
</pre></div>

<h3>Rain simulation dataset</h3>

<div class="code"><pre>
grass -c EPSG:5514 /tmp/smoderp2d-rainsim --exec python3 tests/data/import_grass.py tests/data/rain_sim
grass -c /tmp/smoderp2d-rainsim/test
</pre></div>

Perform computation on Rain simulation dataset:

<div class="code"><pre>
r.smoderp2d \
elevation=rastr10_05_t2_5@PERMANENT \
soil=soil@PERMANENT \
soil_type_fieldname=Soil \
vegetation=LandUse@PERMANENT \
vegetation_type_fieldname=LandUse \
rainfall_file=tests/data/rainfall_sim.txt \
maxdt=30 end_time=40 \
points=ObsPointssel@PERMANENT \
table_soil_vegetation=test_soilveg@PERMANENT \
table_soil_vegetation_fieldname=soilveg \
streams=streams@PERMANENT \
channel_properties_table=stream_shape@PERMANENT \
streams_channel_type_fieldname=channel_id \
output=tests/data/output
</pre></div>

<h2>SEE ALSO</h2>

<em>
Expand Down
45 changes: 30 additions & 15 deletions bin/qgis/smoderp2d-plugin/smoderp_2D_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,16 @@ def __init__(self):


class SmoderpTask(QgsTask):
def __init__(self, input_params, input_maps):
def __init__(self, input_params, input_maps, grass_bin_path):
super().__init__()

self.input_params = input_params
self.input_maps = input_maps
self.grass_bin_path = grass_bin_path
self.error = None

def run(self):
# Get GRASS executable
try:
grass_bin_path = find_grass_bin()
except ImportError as e:
self.error = e
return False

runner = QGISRunner(self.setProgress, grass_bin_path)
runner = QGISRunner(self.setProgress, self.grass_bin_path)
runner.set_options(self.input_params)
runner.import_data(self.input_maps)
try:
Expand All @@ -79,6 +73,8 @@ def run(self):
self.error = e
return False

runner.finish()

# resets
Globals.reset()
GridGlobals.reset()
Expand Down Expand Up @@ -173,6 +169,9 @@ def __init__(self, parent=None):
self.dockWidgetContents.setLayout(self.layout)
self.setWidget(self.dockWidgetContents)

self._result_group_name = "SMODERP2D"
self._grass_bin_path = None

def retranslateUi(self):
for section in sections:
section_tab = QtWidgets.QWidget()
Expand Down Expand Up @@ -347,14 +346,29 @@ def set_button_texts(self):
button.setText('...')

def OnRunButton(self):
if not self._grass_bin_path:
# Get GRASS executable
try:
self._grass_bin_path = find_grass_bin()
except ImportError as e:
self._sendMessage(
"ERROR:",
"GRASS GIS not found.",
"CRITICAL"
)
return

if self._checkInputDataPrep():
# remove previous results
root = QgsProject.instance().layerTreeRoot()
result_node = root.findGroup(self._result_group_name)
if result_node:
root.removeChildNode(result_node)

# Get input parameters
self._getInputParams()

# TODO: implement data preparation only

smoderp_task = SmoderpTask(self._input_params, self._input_maps)
smoderp_task = SmoderpTask(self._input_params, self._input_maps, self._grass_bin_path)

# prepare the progress bar
self.progress_bar = QProgressBar()
Expand Down Expand Up @@ -406,7 +420,7 @@ def _layerColorRamp(layer):
def computationFinished(self):
# show results
root = QgsProject.instance().layerTreeRoot()
group = root.insertGroup(0, "SMODERP2D")
group = root.insertGroup(0, self._result_group_name)

outdir = self.main_output_lineEdit.text().strip()
first = True
Expand Down Expand Up @@ -473,7 +487,8 @@ def _getInputParams(self):
# TODO: It would be nicer to use names defined in _input_params before
# this reparsing
for key in self._input_maps.keys():
self._input_params[key] = key
if self._input_params[key] != '':
self._input_params[key] = key

# optional inputs
if self.points_comboBox.currentLayer() is not None:
Expand Down Expand Up @@ -694,7 +709,7 @@ def _loadTestParams(self):
QgsProject.instance().mapLayersByName('stream')[0]
)
self.rainfall_lineEdit.setText(
os.path.join(dir_path, 'rainfall.txt')
os.path.join(dir_path, 'rainfall_nucice.txt')
)
self.table_soil_vegetation_comboBox.setLayer(
QgsProject.instance().mapLayersByName('soil_veg_tab_mean')[0]
Expand Down
4 changes: 2 additions & 2 deletions bin/wps/request-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def file_content(filename):
'soil_types': file_content(
os.path.join(data_dir, 'profile1d', 'data1D_soil_types.csv')
),
'rainfall': file_content(os.path.join(data_dir, 'rainfall.txt')),
'rainfall': file_content(os.path.join(data_dir, 'rainfall_nucice.txt')),
'config': file_content(os.path.join(tests_dir, 'profile1d.ini'))
}
else: # smoderp2d
d = {
'input': file_content(os.path.join(data_dir, 'destak.save')),
'rainfall': file_content(os.path.join(data_dir, 'rainfall.txt')),
'rainfall': file_content(os.path.join(data_dir, 'rainfall_nucice.txt')),
'config': file_content(os.path.join(tests_dir, 'quicktest.ini'))
}

Expand Down
27 changes: 19 additions & 8 deletions smoderp2d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(self, progress_reporter, grass_bin_path='grass'):
# raise SmoderpError('{}'.format(e))

# initialize GRASS session
gsetup.init(gisdb, location, 'PERMANENT', os.environ['GISBASE'])
self._grass_session = gsetup.init(gisdb, location, 'PERMANENT')
# calling gsetup.init() is not enough for PyGRASS
Mapset('PERMANENT', location, gisdb).current()

Expand Down Expand Up @@ -213,19 +213,30 @@ def import_data(options):
Module("r.import", input=options[key], output=key)
# import vectors
elif key in ["soil", "vegetation", "points", "streams"]:
Module(
"v.import", input=options[key], output=key
)
if options[key] != '':
# points and streams are optional
Module(
"v.import", input=options[key], output=key
)
# import tables
elif key in ["table_soil_vegetation",
"channel_properties_table"]:
Module("db.in.ogr", input=options[key], output=key)
if options[key] != '':
# channel_properties_table is optional
from osgeo import ogr
kwargs = {}
ds = ogr.Open(options[key])
if ds:
if ds.GetDriver().GetName() == 'CSV':
kwargs['gdal_doo'] = 'AUTODETECT_TYPE=YES'
ds = None
Module("db.in.ogr", input=options[key], output=key, **kwargs)
except SmoderpError as e:
raise SmoderpError('{}'.format(e))

def __del__(self):
pass

def finish(self):
from grass.script import setup as gsetup
self._grass_session.finish()

class WpsRunner(Runner):
def __init__(self, **args):
Expand Down
2 changes: 2 additions & 0 deletions smoderp2d/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def __getitem__(cls, key):
return cls.rill
elif key == 'sheet_stream':
return cls.sheet_stream
elif key == 'stream_rill':
return cls.stream_rill
elif key == 'subflow_rill':
return cls.subflow_rill
else:
Expand Down
16 changes: 6 additions & 10 deletions smoderp2d/core/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class GridGlobals(object):
yllcorner = None
# no data value for raster
NoDataValue = -9999
# no data integer value for raster
NoDataInt = None
# size of raster cell
dx = None
# size of raster cell
Expand Down Expand Up @@ -146,8 +144,6 @@ def reset(cls):
cls.yllcorner = None
# no data value for raster
cls.NoDataValue = -9999
# no data integer value for raster
cls.NoDataInt = None
# size of raster cell
cls.dx = None
# size of raster cell
Expand Down Expand Up @@ -202,8 +198,8 @@ class Globals:
mat_fd = None
# raster contains digital elevation model
mat_dem = None
# raster contains efective couterline data
mat_efect_cont = None
# raster contains effective couterline data
mat_effect_cont = None
# raster contains surface slopes data
mat_slope = None
# raster labels not a number cells
Expand Down Expand Up @@ -309,8 +305,8 @@ def get_mat_dem(cls):
return cls.mat_dem

@classmethod
def get_mat_efect_cont(cls):
return cls.mat_efect_cont
def get_mat_effect_cont(cls):
return cls.mat_effect_cont

@classmethod
def get_mat_slope(cls):
Expand Down Expand Up @@ -407,8 +403,8 @@ def reset(cls):
cls.mat_fd = None
# raster contains digital elevation model
cls.mat_dem = None
# raster contains efective couterline data
cls.mat_efect_cont = None
# raster contains effective couterline data
cls.mat_effect_cont = None
# raster contains surface slopes data
cls.mat_slope = None
# raster labels not a number cells
Expand Down
6 changes: 3 additions & 3 deletions smoderp2d/core/subsurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ def calc_exfiltration(self, bil):

return bil, exfilt

def runoff(self, delta_t, efect_vrst):
def runoff(self, delta_t, effect_vrst):

arr = self.arr
# print arr .Ks
self.q_subsurface = self.darcy(arr, efect_vrst)
self.q_subsurface = self.darcy(arr, effect_vrst)
# print arr.h
arr.vol_runoff = delta_t * self.q_subsurface
arr.vol_rest = arr.h * self.pixel_area - delta_t * self.q_subsurface
Expand Down Expand Up @@ -222,7 +222,7 @@ def get_exfiltration(self):
def bilance(self, infilt, inflow, dt):
pass

def runoff(self, delta_t, efect_vrst):
def runoff(self, delta_t, effect_vrst):
pass

def runoff_stream_cell(self, indices):
Expand Down
Loading

0 comments on commit daa2db3

Please sign in to comment.