grass icon indicating copy to clipboard operation
grass copied to clipboard

g.gui.gmodeler: add PyWPS export option

Open pesekon2 opened this issue 3 years ago • 17 comments

pesekon2 avatar Oct 02 '21 17:10 pesekon2

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.

pesekon2 avatar Oct 02 '21 17:10 pesekon2

Looks nice

modeler-wps

    process = Model()

    processes = [Model()]
    application = Service(processes)

@pesekon2 Question: What is purpose of line

 process = Model()

?

landam avatar Nov 28 '21 17:11 landam

Suggestion: line

from pywps.app.Service import Service

could be moved into if __name__ block.

landam avatar Nov 28 '21 17:11 landam

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 avatar Nov 28 '21 17:11 landam

    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.

pesekon2 avatar Dec 02 '21 09:12 pesekon2

Suggestion: line

from pywps.app.Service import Service

could be moved into if __name__ block.

@landam: Moved in bdc5f35a9438e1c1607f53d8d325d0382c418211

pesekon2 avatar Dec 02 '21 09:12 pesekon2

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.

pesekon2 avatar Dec 02 '21 09:12 pesekon2

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).

pywps_grass

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 avatar May 15 '22 20:05 landam

@landam The code has been changed (see 7028d12) in the following way: Output options are skipped if they are intermediate or (blank and unparameterized).

pesekon2 avatar May 23 '22 11:05 pesekon2

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__":

landam avatar May 25 '22 17:05 landam

@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 avatar May 25 '22 17:05 landam

@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.

pesekon2 avatar Jun 05 '22 20:06 pesekon2

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 avatar Aug 29 '22 18:08 landam

@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.

pesekon2 avatar Sep 08 '22 21:09 pesekon2

New tasks based on our testing

  • [x] add overwrite flag to r.out.gdal command (only if overwrite is enabled in preferences)
  • [x] limit supported formats (raster -> image/tif, vector -> application/gml+xml)

landam avatar Sep 14 '22 14:09 landam

landam: add overwrite flag to r.out.gdal command (only if overwrite is enabled in preferences)

Solved in a249d85

pesekon2 avatar Sep 17 '22 08:09 pesekon2

landam: limit supported formats (raster -> image/tif, vector -> application/gml+xml)

Solved in b176b82

pesekon2 avatar Sep 17 '22 11:09 pesekon2

I tested sample model with pywps 4.5.2 and it works.

landam avatar Oct 08 '22 16:10 landam

@veroandreo Can we merge this PR?

landam avatar Oct 08 '22 16:10 landam