grass
grass copied to clipboard
g.gui.gmodeler: add PyWPS export option
Figures containing screenshots of the Python editor should be updated - is there anyone who has the same visual as those that are already there? The GUI looks a bit different in my case and it would be nice to have the look more-or-less standardized (and I would like to avoid taking all the pictures again). @landam?
EDIT: Okay, I'll put them there myself.
Looks nice
process = Model()
processes = [Model()]
application = Service(processes)
@pesekon2 Question: What is purpose of line
process = Model()
?
Suggestion: line
from pywps.app.Service import Service
could be moved into if __name__
block.
Also consider improving comment
# here you could also specify the GRASS location, for example:
- You must specify GRASS location
- Either by providing path to the existing GRASS location
- Or by EPSG code in order to create a new one
process = Model() processes = [Model()] application = Service(processes)
@pesekon2 Question: What is purpose of line
process = Model()
?
@landam: Probably just some residuum from one of the previous versions. Fixed in 024d3cde1f1c8d1aab48400fd6501e5da9c96661, thanks for pointing it out.
Suggestion: line
from pywps.app.Service import Service
could be moved into
if __name__
block.
@landam: Moved in bdc5f35a9438e1c1607f53d8d325d0382c418211
Also consider improving comment
# here you could also specify the GRASS location, for example:
1. You **must** specify GRASS location 2. Either by providing path to the existing GRASS location 3. Or by EPSG code in order to create a new one
@landam: Here I am not sure. Although in most cases you need to specify the location, in the special case you're running the process inside GRASS (being in a mapset and then running the PyWPS process), you don't have to specify it. It is probably not such a very common case, but could happen - and then putting there "must" would be a wrong precept.
I tested PyWPS export functionality on several models. @pesekon2 There is a problem with output options which are not defined. See attached model pywps_grass_test.zip (Gismentors location).
Modeler exports all output options even those which are not set up. Note: output option of v.buffer is skipped (marked in the modeler as intermediate) - fine. But this approach cannot be applied on outputs which are not defined.
outputs.append(ComplexOutput(
identifier="gregion2_save",
title="Save current region settings in named region file",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_slope",
title="Name for output slope raster map",
supported_formats=sup_formats,
default="slope"))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_aspect",
title="Name for output aspect raster map",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_pcurvature",
title="Name for output profile curvature raster map",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_tcurvature",
title="Name for output tangential curvature raster map",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_dx",
title="Name for output first order partial derivative dx (E-W slope) raster map",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_dy",
title="Name for output first order partial derivative dy (N-S slope) raster map",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_dxx",
title="Name for output second order partial derivative dxx raster map",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_dyy",
title="Name for output second order partial derivative dyy raster map",
supported_formats=sup_formats))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_dxy",
title="Name for output second order partial derivative dxy raster map",
supported_formats=sup_formats))
I would expect here only r.slope.aspect's slope option.
@landam The code has been changed (see 7028d12) in the following way: Output options are skipped if they are intermediate or (blank and unparameterized).
Great, now only relevant output parameter is included:
inputs.append(LiteralInput(
identifier="vbuffer1_distance",
title="Buffer distance along major axis in map units",
data_type="float",
default=1000))
outputs.append(ComplexOutput(
identifier="rslopeaspect4_slope",
title="Name for output slope raster map",
supported_formats=sup_formats,
default="slope"))
I just wonder why there are so many empty lines. @pesekon2 I would suggest to keep it consistent (1/2 lines). Similarly here:
return response
if __name__ == "__main__":
@pesekon2 Unfortunately the process fails with:
Traceback (most recent call last):
File "/home/martin/Downloads/pywps-flask-master/demo.py", line 53, in <module>
Model()
File "/home/martin/Downloads/pywps-flask-master/processes/pywps_grass_test.py", line 29, in __init__
outputs.append(ComplexOutput(
TypeError: __init__() got an unexpected keyword argument 'default'
Tested with pywps versions 4.2.11 and 4.5.2.
@landam According to the PyWPS documenatation, PyWPS 4.x does not support parameter default
for ComplexOutput
objects. Updated in 2fc8692 to skip this parameter for ComplexOutput
objects - fortunately the code is written in a way to handle it later in _handler
, so the default value is still used, just later.
Currently it's failing with
File "/home/martin/src/grass/dist.x86_64-pc-linux-gnu/gui/wxpython/gmodeler/model.py", line 2837, in _write_input_outputs
self._write_input_output_object(
TypeError: WritePyWPSFile._write_input_output_object() missing 1 required positional argument: 'value'
@pesekon2 Method WritePyWPSFile._write_input_output_object()
has 7 arguments (https://github.com/pesekon2/grass/blob/gmodeler_export_pywps/gui/wxpython/gmodeler/model.py#L2843) defined, but only called with 6 arguments (https://github.com/pesekon2/grass/blob/gmodeler_export_pywps/gui/wxpython/gmodeler/model.py#L2837).
@landam: Thanks for noticing that. The origin of this bug is actually sort of funny. The latest state of this PR wasn't cool enough according to the Black code style suppression, so I pushed a minimal reformatting commit 8868761. Apparently, it made the code stylish enough, but a small typo broke it to be unusable.
(what to learn: test the code even after those stupid reformatting commits)
Fixed in 0282c38.
New tasks based on our testing
- [x] add
overwrite
flag tor.out.gdal
command (only if overwrite is enabled in preferences) - [x] limit supported formats (raster ->
image/tif
, vector ->application/gml+xml
)
landam: add
overwrite
flag tor.out.gdal
command (only if overwrite is enabled in preferences)
Solved in a249d85
landam: limit supported formats (raster ->
image/tif
, vector ->application/gml+xml
)
Solved in b176b82
I tested sample model with pywps 4.5.2 and it works.
@veroandreo Can we merge this PR?