Bug report #12450

Raster Calculator giving bogus values

Added by George Rodrigues da Cunha Silva almost 9 years ago. Updated almost 9 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:-
Category:Raster Calculator
Affected QGIS version:2.8.1 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:20615

Description

Issue:

I'm trying to do some simple math on QGIS Raster Calculator. In the attachment there's the original data, and the result of the calculation.

This occurs on Raster Calculator, using it manually and using QgsRasterCalculator, with this code:

    def calculate_radiance(self, rasterLayer, output, param_a=0.03705882, param_b=3.2):

        rasterEntry = QgsRasterCalculatorEntry()
        rasterEntry.ref = "ent@1" 
        rasterEntry.raster = rasterLayer
        rasterEntry.bandNumber = 1

        formula = "(ent@1 * {0}) + {1}".format(param_a, param_b)

        rasterCalculator = QgsRasterCalculator(formula,
                                               output,
                                               "GTiff",
                                               rasterLayer.extent(),
                                               rasterLayer.width(),
                                               rasterLayer.height(),
                                               [rasterEntry, ])

        result = rasterCalculator.processCalculation()
        if result == 0:
            return output

        return None

The calculation is simple (pseudosyntax - I'm using the mouse to assemble the calculation):

(raster * 0.03705882) + 3.2

I'm getting NODATA raster.

I've tried simple calculations, like

raster + 1

And there are still problems.

Information:

Versions affected: 2.6, 2.8.1 (tested only on those)

OS: Linux Mint Cinnamon and Ubuntu Studio.

data.zip (27 KB) George Rodrigues da Cunha Silva, 2015-03-25 01:48 PM

radiance_0.03705882_3.2_.tif - File that Nicolas processed (99 KB) George Rodrigues da Cunha Silva, 2015-03-25 02:58 PM

radiance_0.03705882_3.2_.tif.aux.xml Magnifier - File that Nicolas processed (2.59 KB) George Rodrigues da Cunha Silva, 2015-03-25 02:58 PM

myradiance.tif - File I processed (99 KB) George Rodrigues da Cunha Silva, 2015-03-25 02:58 PM

myradiance.tif.aux.xml Magnifier - File I processed (2.5 KB) George Rodrigues da Cunha Silva, 2015-03-25 02:58 PM

Associated revisions

Revision 559d7bb9
Added by Nyall Dawson almost 9 years ago

[rastercalc] Rework raster calculator to use QGIS raster classes

...rather than reading input layers directly through GDAL.
Benefits include more robust handling of nodata/data type conversions,
less code duplication, also being able to take advantage of features
in QGIS raster code like handling gain/offset in rasters. (fix #12450)

Also, add a choice of output projection to the raster calculator.
Previously the output CRS would be taken from the first raster, with
no guarantees that the output extent matched the output CRS. This
resulted in empty/misplaced rasters. (fix #3649)

History

#1 Updated by Giovanni Manghi almost 9 years ago

  • Status changed from Open to Feedback

Olá George,
I'm also on Mint 14.04, qgis 2.8.1 and master. I just tested your data and it seems that on master the problem is already fixed... please give it a try and report back. Obrigado.

#2 Updated by Giovanni Manghi almost 9 years ago

Giovanni Manghi wrote:

Olá George,
I'm also on Mint 14.04, qgis 2.8.1 and master. I just tested your data and it seems that on master the problem is already fixed... please give it a try and report back. Obrigado.

I spoke too soon... on Windows I get different results with the very same inputs and expressions, but still not sure are the right results...

#3 Updated by Giovanni Manghi almost 9 years ago

it seems that under Linux there is a rounding issue: any factor is rounded to integer, so the result of the

(raster * 0.03705882) + 3.2

formula is always 3 -> (raster * 0) + 3

#4 Updated by George Rodrigues da Cunha Silva almost 9 years ago

Thank you. I'm not insane.

That can surely be it, because, someone else, on list, Nicolas, tried, but he does not get the rounding issues, but weird double precision results.

If you try the minimum for the raster, you'll see that the math is completely off, something like:

149 * 0.03705822 + 3.2 = 8,72167478

Even thought Nicolas values are not rounded off, they are way off!

#5 Updated by Giovanni Manghi almost 9 years ago

  • Priority changed from High to Severe/Regression

I'll tag this as blocker as one way or another we have to figure something about this issue before the next release.

#6 Updated by Giovanni Manghi almost 9 years ago

  • Target version changed from Version 2.8 to Version 2.8.2

#7 Updated by Giovanni Manghi almost 9 years ago

  • Status changed from Feedback to Open

#8 Updated by Giovanni Manghi almost 9 years ago

  • Target version changed from Version 2.8.2 to Version 2.10

#9 Updated by Nyall Dawson almost 9 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF