Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Processing] Port GRASS 7.2 algorithm provider #5426

Merged
merged 23 commits into from Nov 8, 2017
Merged

[Processing] Port GRASS 7.2 algorithm provider #5426

merged 23 commits into from Nov 8, 2017

Conversation

ghost
Copy link

@ghost ghost commented Oct 23, 2017

Description

This PR adds a ported version of Processing GRASS 7.2 provider...

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

  • Commit messages are descriptive and explain the rationale for changes
  • Commits which fix bugs include fixes #11111 in the commit message next to the description
  • Commits which add new features are tagged with [FEATURE] in the commit message
  • Commits which change the UI or existing user workflows are tagged with [needs-docs] in the commit message and containt sufficient information in the commit message to be documented
  • I have read the QGIS Coding Standards and this PR complies with them
  • This PR passes all existing unit tests (test results will be reported by travis-ci after opening this PR)
  • New unit tests have been added for core changes
  • I have run the scripts/prepare-commit.sh script before each commit

What has been done

  • Port code to new QgsProcessingParameter API.
  • Most of the algorithms description files have been converted to the new API.
  • Reviewing of most of the ./ext scripts.
  • Use v.external as an option for vector import into temporary GRASS DB.
  • Accept all OGR vector as data source (needs some tests).

What needs to be done

  • Tests under MS-Windows.
  • Add the new Grass 7.2 algorithms (about 10 algorithms).
  • Review all description files for parameters migration from GRASS 7.0 to GRASS 7.2.
  • Improve unit tests.
  • Handle ParameterTable (for only two algorithms).
  • Better handling of OutputDirectory.
  • Work on r.mapcalc.
  • Improve format supports (exports only into ESRI Shapefile/GTiff).

@timlinux
Copy link
Member

Yay glad to see this work to reinstate grass!

@timlinux
Copy link
Member

timlinux commented Oct 23, 2017

@medspx I tested a little on MacOS here. I used GRASS 7.0 provided by brew. I needed to set the provider option to /usr/local/opt/grass7/ for QGIS to find my GRASS install (can I presume it will work with 7.0 as well as 7.2?

screen shot 2017-10-24 at 00 05 42

I tried testing a few algs but they do not seem to complete properly. Here is an example of the output. The lag dialog closes before I can catch it so I needed to use icecap to capture it:

screen shot 2017-10-24 at 00 03 19

licecap

@ghost
Copy link
Author

ghost commented Oct 24, 2017

@timlinux Ah! I haven't made tests on MacOSX too.
Seems to be a problem with the directory of the GRASS script (there is a space in it). There will be the same problem with MS-Windows, so I need to fix it!

@gioman
Copy link
Contributor

gioman commented Oct 24, 2017

@timlinux @medspx this somehow recalls me this https://issues.qgis.org/issues/16926

@ghost
Copy link
Author

ghost commented Oct 24, 2017

Unfortunately, it seems to be a GRASS bug: https://trac.osgeo.org/grass/ticket/3170
I am not sure there is a workaround...

@timlinux
Copy link
Member

@medspx I guess for all Mac users we will have the same problem - I take care not to use spaces in the file paths I use and create myself, but the QGIS configs go into a system defined path which does have spaces :-( This is a side effect of @NathanW2 's (otherwise cool) profiles work....

@timlinux
Copy link
Member

I do also wonder how come the grass7_batch_job.sh ends up in that folder? Isn't it something we control?

@neteler
Copy link
Contributor

neteler commented Oct 24, 2017

What about using the newish --exec interface?
https://grass.osgeo.org/grass72/manuals/grass7.html#batch-jobs-with-the-exec-interface

@ghost
Copy link
Author

ghost commented Oct 25, 2017

@neteler Thanks, it seems to work with the exec interface. I just need to add a commit in this PR!

@neteler
Copy link
Contributor

neteler commented Oct 25, 2017

Thanks for the improvements! Just one quick minor suggestion concerning the "r.out.gdal" usage: it is recommended to add this flag:

-m
Do not write non-standard metadata
Enhances compatibility with other GIS software

See https://grass.osgeo.org/grass72/manuals/r.out.gdal.html

layers = [l for l in self.inputLayers if isinstance(l, QgsRasterLayer)]

# Use this function to calculate cell size
def cz(l, cellsize): return max(cellsize, (l.extent().xMaximum() - l.extent().xMinimum()) / l.width())
Copy link
Contributor

@alexbruy alexbruy Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I miss something, but why not use rasterUnitsPerPixelX() here?


def loadRasterLayerFromParameter(self, name, parameters, context, external=True, band=1):
"""
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed docstring? Or just remove them


def loadVectorLayerFromParameter(self, name, parameters, context, external=None):
"""
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty docstring

@ghost
Copy link
Author

ghost commented Oct 26, 2017

Ok, I've made some changes:

  • Get rid of cz method and rely on rasterUnitsPerPixelX() @alexbruy
  • Fill docstrings @alexbruy
  • Add -m option for r.out.gdal @neteler
  • Use the --exec method @neteler . It seems to work well on the 3 different OS (GNU/Linux; MacOSX; MS-Windows).
  • Better path normalization, so MacOSX should now handle data or profiles that have space in there file path. @timlinux
  • Improved detection of GRASS binaries and path:
    • GNU/Linux uses shutil.which.
    • MS-Windows use Path Settings or QGS_PREFIX or OSGEO4W or shutil.which.
    • MacOSX use Path Settings or shutil.which or QGS_PREFIX or well-known path for GRASS.
  • I have unified the batch job generation and running for the 3 supported operating systems. I have got some good results even under MS-Windows (with an Osgeo4W installation of QGIS-dev+GRASS). I am still struggling with user profiles that have special characters (é€è) in their user name but for now, you can use data with filepath that have non-ANSI characters.

I still need to work on ext/ scripts but the main code (in Grass7Utils and Grass7Algorithm) should now be (approximatively) stable.

@timlinux
Copy link
Member

@medspx thanks for the updates. I got some new errors now (still on MacOS):

  1. Testing with a Postgis layer:

pg-grass-error

  1. Testing with the same layer as a shape file:

shp-grass-error

I also still have the issue that All window closes directly after the error so I have to use Licecap to get the above screenshots from a screen record...

@ghost
Copy link
Author

ghost commented Oct 27, 2017

@timlinux
I have never made a test with a PostGIS datasource before (in QGIS 2.18, GRASS could not use anything else than an input shapefile). From your screenshot, it seems that there is a problem with datasource connexion string which is not escaped properly. I think I can fix that but I planned to have a global fix for all input format problems (which are huge because I have to test each OGR/GDAL format properly).

From your second screenshot, it seems that this an internal error from GRASS. I have sometimes segmentation faults with some data on different algorithms. If you have another clue, just tell me.

For the closing windows, have you checked the 'Keep dialog open after running an algorithm' option?

@gioman
Copy link
Contributor

gioman commented Oct 27, 2017

have never made a test with a PostGIS datasource before

this should not really matter, meaning that it could be a general processing issue and not something specific to the GRASS provider.

@nyalldawson
Copy link
Collaborator

@medspx there's an inbuilt method to auto convert incompatible inputs to a desired format (e.g. shape). I plan on reviewing this later and will advise then.

@gioman
Copy link
Contributor

gioman commented Oct 27, 2017

I also still have the issue that All window closes directly after the error so I have to use Licecap to get the above screenshots from a screen record...

there is an option among Processing ones that is not enabled by default (at least in 2.*) and if left unchecked that makes dialogs close after run (even when tools hit some issue and do not produce an output). Not sure if this is the case.

@nyalldawson
Copy link
Collaborator

@gioman

In 3.0 that dialog should stay whenever an error is encountered, regardless of the setting.

@gioman
Copy link
Contributor

gioman commented Oct 27, 2017

In 3.0 that dialog should stay whenever an error is encountered, regardless of the setting.

then it maybe this https://issues.qgis.org/issues/16926 it only affects the tools that where added as "external" (python/plugins/processing/algs/grass7/ext/).

Médéric RIBREUX added 7 commits November 4, 2017 15:31
- Improve GRASS detection for all OS.
- Use GRASS --exec command.
- Unified GRASS batch job method for all OS (easier to maintain).
- Handle MS-Windows codepages (for data only, if you have a username with special characters, it will not work).
- Better support for filepath normalization.
- add -m option to r.out.gdal.
* Fix ParameterRange GUI.
* Fix Multiple values Enum support.
* A new createopt textbox has been added to the parameters dialog for algorithms which exports to raster files.
* A new metaopt textbox has also been added to the Algorithm parameters dialog.
* Raster file format is detected from output filename extension.
* GdalUtils has been improved to correctly detect raster formats supported for creation.
* QFileDialog for output rasters now display only file filters for supported output raster file formats.
@hellik
Copy link

hellik commented Nov 6, 2017

any hint how to test it on windows?

@nyalldawson
Copy link
Collaborator

@medspx this looks good to me. Given that it has been granted an exemption from the feature freeze, is there anything you think needs to be addressed before it's merged? I'd vote to merge quickly so that we can get wider testing and identify outstanding issues.

@nyalldawson
Copy link
Collaborator

Actually one question - have you tried reenabling the grass processing tests to see if the work OK now?

@ghost
Copy link
Author

ghost commented Nov 7, 2017

@nyalldawson
I also think it can be merged now: lots of algorithms will work out of the box.
But, for the moment, the provider is not at the same quality level than under QGIS 2.x. mainly because of ext/ scripts that needs to be adapted. It means that there will perhaps be lots of bug reports about it once the PR is merged.

Here is a short list of what should be done during feature freeze:

  • Top priority tasks (to be on par with QGIS 2.x):

    • Review all description files (.txt files which define algorithm parameters). This is a time consuming job because there are a lot of files to review (more than 300). But that work can be shared. I am currently working on this (on r. algorithms) and I plan to finish (the r part only) this week-end.
    • Adapt ext/ Python scripts. This is also time consuming because you have to test each algorithm and there is code involved. Without a functional ext/ python script, algorithms that requires extra logic are useless. I have already worked on lots of ext/ scripts but at least half of them need to be recoded/modified.
  • Nice to have for the release:

    • Handle multiple raster input formats (should be the case, not really tested).
    • Handle multiple vector input formats (need some code).
    • Support multiple vector output file formats (should be easy).
    • Better unicode support under MS-Windows.
  • If we have completed everything else:

    • Re-open test units validation on Travis.
    • Add more unit tests.
    • Better support for modeler or batch jobs.
    • Fix all bugs referenced under Redmine!

I also haven't taken time to launch the tests because it is too early (I'll bet lots of them will fail).

@nyalldawson
Copy link
Collaborator

Ok. It's a +1 to merge in its current state from me. I'll let @alexbruy make the final call here! (not sure if he wants to re-review)

Copy link
Contributor

@alexbruy alexbruy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work. +1 to merge it now, so early adopters can test and report bugs

@nyalldawson nyalldawson merged commit cab807d into qgis:master Nov 8, 2017
@gioman
Copy link
Contributor

gioman commented Nov 14, 2017

@medspx Hi! I started giving GRASS (and SAGA) a go on QGIS3 and noticed the following:

there are GRASS description files where the min/max values for a particular parameter got swapped from the 2.18 description file to the 3 one. Example r.watershed

2.18:

ParameterNumber|convergence|Convergence factor for MFD (1-10)|1|10|5
ParameterNumber|memory|Maximum memory to be used with -m flag (in MB)|1|None|300

master:

QgsProcessingParameterNumber|convergence|Convergence factor for MFD (1-10)|QgsProcessingParameterNumber.Double|5|False|10|1
QgsProcessingParameterNumber|memory|Maximum memory to be used with -m flag (in MB)|QgsProcessingParameterNumber.Double|300|False|None|1

this is causing several symptoms, among the others:

  • default value not being respected (the max one shows instead)
  • for integer/double parameters the spin arrows do not work
  • mandatory parameters that are correctly filled are not accepted

not sure if this is just one case or it is widespead.

@volaya @alexbruy

@gioman
Copy link
Contributor

gioman commented Nov 14, 2017

@medspx apparently is not the only case, for example v.generalize.simplify

2.18
ParameterNumber|reduction|Percentage of the points in the output of 'douglas_reduction' algorithm|0.0|100.0|50.0

master:
QgsProcessingParameterNumber|reduction|Percentage of the points in the output of 'douglas_reduction' algorithm|QgsProcessingParameterNumber.Double|50.0|False|100.0|0.0

@neteler
Copy link
Contributor

neteler commented Nov 14, 2017

FWIW: Fedora users can find a version for testing here:
https://copr.fedorainfracloud.org/coprs/dani/qgis-testing/

@hellik
Copy link

hellik commented Nov 14, 2017

for windows users, it's already available by OSGeo4W.

@neteler
Copy link
Contributor

neteler commented Nov 14, 2017

Questoin: on Linux, how is determined, which GRASS GIS version is used? We tried to change the path to point to my local copy of the upcoming GRASS 7.4.0 version but still 7.2.1 is picked up.

Under:
Settings » Preferences » Processing » Providers
... I cannot select the grass7x start script. However, that would be great.

@gioman
Copy link
Contributor

gioman commented Nov 15, 2017

@medspx Hi! I started giving GRASS (and SAGA) a go on QGIS3 and noticed the following:

disregard, I have seen now you fixed (at least the raster ones) here:
#5603

thanks!

@gioman
Copy link
Contributor

gioman commented Nov 15, 2017

Questoin: on Linux, how is determined, which GRASS GIS version is used? We tried to change the path to point to my local copy of the upcoming GRASS 7.4.0 version but still 7.2.1 is picked up.

Under:
Settings » Preferences » Processing » Providers
... I cannot select the grass7x start script. However, that would be great.

The path to GRASS binaries is only exposed (in Processing configs) on Windows (and macOS apparently), on Linux is automatically configured (if GRASS is installed).

https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py#L56

@jef-n
Copy link
Member

jef-n commented Nov 15, 2017

@gioman
Copy link
Contributor

gioman commented Nov 15, 2017

@neteler
Copy link
Contributor

neteler commented Nov 15, 2017

ok, please replace "grass73" and "grass73.sh" with "grass74" and "grass74.sh" since 7.3 will never be released. However, 7.4.0 RC1 is due today, followed by the final release soon.

@gioman
Copy link
Contributor

gioman commented Nov 15, 2017

ok, please replace "grass73" and "grass73.sh" with "grass74" and "grass74.sh" since 7.3 will never be released. However, 7.4.0 RC1 is due today, followed by the final release soon.

#5641

@neteler
Copy link
Contributor

neteler commented Nov 16, 2017

Important: currently vector data seem to be handled with v.external by default. Please change that to v.in.ogr since v.external is rather limited and does not work properly with all vector data formats. For a good user experience v.in.ogr or v.import are recommended.

See discussion in https://lists.osgeo.org/pipermail/grass-dev/2017-November/086598.html

@ghost ghost deleted the ProcessingPortGrass72 branch November 25, 2017 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants