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 heatmap algorithm #4843

Merged
merged 3 commits into from
Jul 13, 2017
Merged

[processing] port heatmap algorithm #4843

merged 3 commits into from
Jul 13, 2017

Conversation

alexbruy
Copy link
Contributor

@alexbruy alexbruy commented Jul 12, 2017

Description

Restore Heatmap algorithm (no tests yet)

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

@alexbruy
Copy link
Contributor Author

BTW, I noticed that after executing any already available QGIS algorithm there is an error like this

Python error[1] Traceback (most recent call last):
  File "/tmp/build/qgis/output/python/plugins/processing/algs/qgis/QgisAlgorithm.py", line 39, in shortHelpString
    return shortHelp.get(self.id(), None)
RuntimeError: wrapped C/C++ object of type Heatmap has been deleted

Copy link
Collaborator

@nyalldawson nyalldawson left a comment

Choose a reason for hiding this comment

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

Thanks!

I'm really keen for feedback on how you found the porting process & the new API. Any suggestions for improvement?

def displayName(self):
return self.tr('Heatmap (Kernel Density Estimation)')
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT_LAYER, self.tr('Heatmap')))
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT_LAYER, self.tr('Heatmap')))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is no longer required - since 058271b the output will automatically be created

radius = self.getParameterValue(self.RADIUS)
kernel_shape = self.getParameterValue(self.KERNEL)
radius = self.parameterAsDouble(parameters, self.RADIUS, context)
kernel_shape = self.parameterAsEnums(parameters, self.KERNEL, context)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be parameterAsEnum - parameterAsEnums will return a list and is for multiple value parameters only

output_values = self.getParameterValue(self.OUTPUT_VALUE)
output = self.getOutputValue(self.OUTPUT_LAYER)
decay = self.parameterAsDouble(parameters, self.DECAY, context)
output_values = self.parameterAsEnums(parameters, self.OUTPUT_VALUE, context)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

@@ -170,7 +204,7 @@ def processAlgorithm(self, parameters, context, feedback):
kde = QgsKernelDensityEstimation(kde_params, output, output_format)

if kde.prepare() != QgsKernelDensityEstimation.Success:
raise GeoAlgorithmExecutionException(
raise QgsProcessingException(
Copy link
Collaborator

Choose a reason for hiding this comment

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

it should be fine to keep throwing GeoAlgorithmExecutionException - there's code which handles this and maps it automatically to the c++ exception. I guess there's no harm either way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it is better to use GeoAlgorithmExecutionException or switch to QgsProcessingException to reduce (a little) code to maintain?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, you're right. Let's reduce the workload and switch everything over.

@@ -78,6 +78,7 @@
from .VectorSplit import VectorSplit
from .VoronoiPolygons import VoronoiPolygons
from .ZonalStatistics import ZonalStatistics
from .Heatmap import Heatmap
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mind keeping the alphabetical sorting that's been started here? (and below)

(sorry, pedantic I know!)

@nyalldawson
Copy link
Collaborator

I noticed that after executing any already available QGIS algorithm there is an error like this

It's on my list - there's some weird issue going on buried within the hidden depths of sip. I'll find it....

@@ -179,10 +213,12 @@ def processAlgorithm(self, parameters, context, feedback):
total = 100.0 / layer.featureCount() if layer.featureCount() else 0
for current, f in enumerate(features):
if kde.addFeature(f) != QgsKernelDensityEstimation.Success:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also - better add a check for feedback.isCanceled() here too and break out of the loop

@alexbruy
Copy link
Contributor Author

Also added test (failing for now). Trying to debug what is wrong, probably I did something wrong when porting.

@nyalldawson
Copy link
Collaborator

Does the test pass locally? For me none of the raster hash test values match locally vs Travis (likely the library version differences). I just (make sure the algorithm works) then set them to Travis, and suffer the local failures. Maybe we should make the hash values a list of acceptable values instead?

@alexbruy
Copy link
Contributor Author

No test does not pass locally. Seems there is something wrong with algorithm (my port) itself

@alexbruy
Copy link
Contributor Author

@nyalldawson hopefully test and algorithm now fixed. I will add comments to the documentation PR

@nyalldawson
Copy link
Collaborator

What was the issue?

@alexbruy
Copy link
Contributor Author

Initial output raster declaration

self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT_LAYER, self.tr('Heatmap')))

was wrong and even removing it and using automatically generated output does not helped (probably I just don't know how to use them correctly). It worked after declaring output raster explicitly similarly to the Aspect algorithm

self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT_LAYER, self.tr('Heatmap')))

@nyalldawson
Copy link
Collaborator

Ok - I definitely need to add a lot of detail about that to the porting guide :)

@nyalldawson nyalldawson merged commit cfbed91 into qgis:master Jul 13, 2017
@alexbruy alexbruy deleted the processing-heatmap branch July 13, 2017 10:07
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

2 participants