Bug report #21405

Raster Calculator wrong results

Added by monokultur - about 5 years ago. Updated almost 5 years ago.

Status:Closed
Priority:High
Assignee:Alessandro Pasotti
Category:Raster Calculator
Affected QGIS version:3.6.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:fixed/implemented
Crashes QGIS or corrupts data:Yes Copied to github as #:29222

Description

In Qgis 3.6.0 the Raster Calculator delivers wrong results.

Example:
two geotiffs Sentinel-2
expression: 0.5*((2*"B08@1"+1)-sqrt((2*"B08@1"+1)^2-8*("B08@1"-"B04@1")))

3.6.0: 0.5*((2*0.4544+1)-sqrt((2*0.4544+1)^2-8*(0.4544-"0.0514")))= nan
3.4.5: 0.5*((2*0.4544+1)-sqrt((2*0.4544+1)^2-8*(0.4544-"0.0514")))= 0.630549
Excel: 0.5*((2*0.4544+1)-sqrt((2*0.4544+1)^2-8*(0.4544-"0.0514")))= 0.630549

3.6.0: 0.5*((2*0.2768+1)-sqrt((2*0.2768+1)^2-8*(0.2768-"0.0448")))= 0.883769
3.4.5: 0.5*((2*0.2768+1)-sqrt((2*0.2768+1)^2-8*(0.2768-"0.0448")))= 0.4034125
Excel: 0.5*((2*0.2768+1)-sqrt((2*0.2768+1)^2-8*(0.2768-"0.0448")))= 0.4034125

Result_3.4.5_no_opencl.tif (58.8 KB) monokultur -, 2019-03-13 01:19 PM

Result_3.4.5_opencl_AMD_RX580.tif (58.8 KB) monokultur -, 2019-03-13 01:19 PM

Result_3.6.0_no_opencl.tif (58.8 KB) monokultur -, 2019-03-13 01:19 PM

Result_3.6.0_opencl_AMD_RX580.tif (58.8 KB) monokultur -, 2019-03-13 01:19 PM

Result_3.6.0_opencl_NVIDIA_1000M.tif (58.8 KB) monokultur -, 2019-03-13 01:19 PM

RT_T33UVV_A008628_20181031T101140_B04_clip.tif (58.8 KB) monokultur -, 2019-03-13 01:19 PM

RT_T33UVV_A008628_20181031T101140_B08_clip.tif (58.8 KB) monokultur -, 2019-03-13 01:19 PM

Associated revisions

Revision 88a96122
Added by Alessandro Pasotti about 5 years ago

[opencl] Fix raster calculator operator precedence

With test

Possibly fixes #21405 (not yet sure if the user was using OpenCL)

History

#1 Updated by Alessandro Pasotti about 5 years ago

  • Assignee set to Alessandro Pasotti

#2 Updated by Alessandro Pasotti about 5 years ago

Can you share a small portion of the rasters where we can reproduce the issue?

Also, can you check if OpenCL acceleration is enabled in the QGIS settings? If it is enabled please check if disabling it does fix the issue.

#3 Updated by Alessandro Pasotti about 5 years ago

  • Status changed from Open to Feedback

#4 Updated by Alessandro Pasotti about 5 years ago

  • Pull Request or Patch supplied changed from No to Yes

PR https://github.com/qgis/QGIS/pull/9305

I've found an issue in the OpenCL implementation of the calculator, but I'm not sure if that is the same issue.

#5 Updated by Alessandro Pasotti about 5 years ago

  • % Done changed from 0 to 100
  • Status changed from Feedback to Closed

#6 Updated by monokultur - about 5 years ago

Sorry I couldn't answer earlier.
Yes, it's an issue in the OpenCL implementation of the calculator.
I've tested some variants:
  • 3.4.5 with OpenCL (AMD RX580) - OK
  • 3.4.5 without OpenCL (AMD RX580) - OK
  • 3.6.0 with OpenCL (AMD RX580) - wrong result
  • 3.6.0 without OpenCL (AMD RX580) - OK
  • 3.6.0 with OpenCL (NVIDIA 1000M) - wrong result
  • 3.6.0 without OpenCL (NVIDIA 1000M) - OK

#7 Updated by Giovanni Manghi about 5 years ago

  • Crashes QGIS or corrupts data changed from No to Yes
  • Easy fix? changed from Yes to No
  • Resolution set to fixed/implemented

#8 Updated by monokultur - almost 5 years ago

  • Status changed from Closed to Reopened

Version 3.6.1, 3.6.2, 3.6.3 > Problem still there.

#9 Updated by Alessandro Pasotti almost 5 years ago

The patch was never backported, can you please check if current master works with OpenCL? If it does I can backport the fixes to 3.6 in time for the next point release.

#10 Updated by monokultur - almost 5 years ago

  • Status changed from Reopened to Closed

Ah, OK I thought it should be fixed since 3.6.1. My mistake.
The current master works with OpenCL.
Next point release is 3.8.0. So I think its no nessesary to backport to 3.6.

Also available in: Atom PDF