Skip to content

Commit ec6b29a

Browse files
author
Médéric RIBREUX
committedMay 29, 2016
Remove NaN values from raster before hash calculation
1 parent 235f986 commit ec6b29a

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed
 

‎python/plugins/processing/gui/TestTools.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
from osgeo import gdal
3333
from osgeo.gdalconst import GA_ReadOnly
3434

35+
from numpy import nan_to_num
36+
3537
from qgis.PyQt.QtCore import QCoreApplication, QMetaObject
3638
from qgis.PyQt.QtWidgets import QDialog, QVBoxLayout, QTextEdit
3739

@@ -195,7 +197,8 @@ def createTest(text):
195197
elif isinstance(out, OutputRaster):
196198
filename = token[1:-1]
197199
dataset = gdal.Open(filename, GA_ReadOnly)
198-
strhash = hashlib.sha224(dataset.ReadAsArray(0).data).hexdigest()
200+
dataArray = nan_to_num(dataset.ReadAsArray(0))
201+
strhash = hashlib.sha224(dataArray.data).hexdigest()
199202

200203
results[out.name] = {
201204
'type': 'rasterhash',

‎python/plugins/processing/tests/AlgorithmsTestBase.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import tempfile
3535

3636
from osgeo.gdalconst import GA_ReadOnly
37+
from numpy import nan_to_num
3738

3839
import processing
3940
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
@@ -100,7 +101,7 @@ def check_algorithm(self, name, defs):
100101

101102
expectFailure = False
102103
if 'expectedFailure' in defs:
103-
exec('\n'.join(defs['expectedFailure'][:-1])) in globals(), locals()
104+
exec('\n'.join(defs['expectedFailure'][:-1]) in globals(), locals()
104105
expectFailure = eval(defs['expectedFailure'][-1])
105106

106107
if expectFailure:
@@ -114,7 +115,6 @@ def check_algorithm(self, name, defs):
114115
else:
115116
alg.execute()
116117
self.check_results(alg.getOutputValuesAsDictionary(), defs['results'])
117-
118118

119119
def load_params(self, params):
120120
"""
@@ -210,7 +210,8 @@ def check_results(self, results, expected):
210210

211211
elif 'rasterhash' == expected_result['type']:
212212
dataset = gdal.Open(results[id], GA_ReadOnly)
213-
strhash = hashlib.sha224(dataset.ReadAsArray(0).data).hexdigest()
213+
dataArray = nan_to_num(dataset.ReadAsArray(0))
214+
strhash = hashlib.sha224(dataArray.data).hexdigest()
214215

215216
self.assertEqual(strhash, expected_result['hash'])
216217
elif 'file' == expected_result['type']:

‎python/plugins/processing/tests/testdata/grass7_algorithm_tests.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tests:
1212
results:
1313
output:
1414
type: rasterhash
15-
hash: 80fe9e022cff3d4cad57fbad40aa7f547b3621a4eec94629d69e16ed
15+
hash: cef69ed56f0b0f991ae2f7f2a54b8a29319eaf8b7d65653c75cbf985
1616

1717
- algorithm: grass7:i.biomass
1818
name: GRASS7 i.biomass
@@ -38,7 +38,7 @@ tests:
3838
type: raster
3939
results:
4040
output:
41-
hash: edbbf2a0866a2fdfa01996d5bef5a06862df2a54c020fc8b1e4aa51a
41+
hash: 358c7745aaa5d7fbc56b34a21821fdfdc61f68e6ca79fb996a2241d8
4242
type: rasterhash
4343

4444
- algorithm: grass7:i.eb.eta
@@ -56,7 +56,7 @@ tests:
5656
type: raster
5757
results:
5858
output:
59-
hash: 5143d76a4d32395f4cfaf22aab33c5ae47f2c219eebbb888663a4e85
59+
hash: 23e65e4c5384b48d7151f781bab10e5caa398b36d363ff8c1049c917
6060
type: rasterhash
6161

6262
- algorithm: grass7:i.eb.netrad
@@ -92,7 +92,7 @@ tests:
9292
type: raster
9393
results:
9494
output:
95-
hash: b38052d5d446aad62dfe46c84d0fb949b9ba0b6f43aa7c95e3de2c92
95+
hash: 361d48c66d978d4844ae7c073c9e6d042fdc8c7739b889a1efce3c3f
9696
type: rasterhash
9797

9898
- algorithm: grass7:i.eb.soilheatflux
@@ -117,7 +117,7 @@ tests:
117117
type: raster
118118
results:
119119
output:
120-
hash: aa195846f7a93d4141c01170751afad055ab6d1caa74cc888c4ad398
120+
hash: a25c4b750dd1f2f2124a117c80ac3f0e3d9b353618a86389eca794e8
121121
type: rasterhash
122122

123123
- algorithm: grass7:i.evapo.mh
@@ -139,7 +139,7 @@ tests:
139139
type: raster
140140
results:
141141
output:
142-
hash: 9bdbd441804b613f0fdb2449572b69fdc3431113810330693c45b87f
142+
hash: b0211772fe8e2c3d8c713551137f014756eb63ccd12f95a322f63ce0
143143
type: rasterhash
144144

145145
- algorithm: grass7:i.evapo.pm
@@ -166,7 +166,7 @@ tests:
166166
type: raster
167167
results:
168168
output:
169-
hash: 7d649cefbf6b0d5581c9cafb285c0598827198fd6f313909325979d7
169+
hash: 419ae792b057d2324354ce76d971d01e36751cf1c45cf3d856634576
170170
type: rasterhash
171171

172172
- algorithm: grass7:i.evapo.pt
@@ -188,7 +188,7 @@ tests:
188188
type: raster
189189
results:
190190
output:
191-
hash: 9bdbd441804b613f0fdb2449572b69fdc3431113810330693c45b87f
191+
hash: b0211772fe8e2c3d8c713551137f014756eb63ccd12f95a322f63ce0
192192
type: rasterhash
193193

194194
- algorithm: grass7:i.topo.coor.ill
@@ -202,7 +202,7 @@ tests:
202202
zenith: 50
203203
results:
204204
output:
205-
hash: d1eb7882b3d68f2bc5785dc052b1c870d84e9a232b72607ca4d7da45
205+
hash: b08dc5b47f557ecadf0c125c99f249e49111c44e43f463c2444ab474
206206
type: rasterhash
207207

208208
- algorithm: grass7:i.vi
@@ -219,7 +219,7 @@ tests:
219219
viname: 10
220220
results:
221221
output:
222-
hash: 9bdbd441804b613f0fdb2449572b69fdc3431113810330693c45b87f
222+
hash: b0211772fe8e2c3d8c713551137f014756eb63ccd12f95a322f63ce0
223223
type: rasterhash
224224

225225
- algorithm: grass7:i.zc
@@ -323,7 +323,7 @@ tests:
323323
type: raster
324324
results:
325325
imaginary:
326-
hash: 0a64ae8d6ba603cbedeee7706df0942f4d7221e394bc76939f33a3dc
326+
hash: 94249384dd8b6019f0024501bc9a093cba9dd025c183d3fb46d77027
327327
type: rasterhash
328328
real:
329329
hash: 09ab93c65aa2dde4da422b62a5ed3e38208e2da072cec2b0eb837a47
@@ -350,7 +350,7 @@ tests:
350350
threshold: 0.5
351351
results:
352352
goodness:
353-
hash: 597d8962276c360ef1efc0b8647c3bd773b5e98898d4e56a2d82928f
353+
hash: 4d7728e28734d2b67427a514bcd155d254d30b3424bf4e0ad8f0f0c6
354354
type: rasterhash
355355
output:
356356
hash: b65992a5d48b867d4a32a533f38e7a72cb1ba18f1e261c6be132baca
@@ -434,13 +434,13 @@ tests:
434434
type: raster
435435
results:
436436
blueoutput:
437-
hash: 75bac89afee968cd5d7027de1acfff3b02a7517eb136f3b73e49b2fa
437+
hash: 906de8be89e302057ed849d00eaf49332ecca73ffaba1374994f1a17
438438
type: rasterhash
439439
greenoutput:
440-
hash: e11274dddcd5f169f03957f41ece1fde7625b8ace342de258ba2873b
440+
hash: 588ad1ef8360ce903fc2defb1a1728a1dc8335d737d5fa77797605ed
441441
type: rasterhash
442442
redoutput:
443-
hash: 9fc943dcf4fcead4f2c662bb6e3f0455caed5df1d9f46ae763955001
443+
hash: ad80c0007faa1b0dc15c0b0c21ff4e0045ff5e67b454df0f65e68899
444444
type: rasterhash
445445

446446
- algorithm: grass7:i.smap
@@ -538,7 +538,7 @@ tests:
538538
vapourpressureactual: 1.511
539539
results:
540540
output:
541-
hash: 10a7144d393e716f721265057d1d1603baa627ceb7c6b29e30865a58
541+
hash: cac9e91f9b5182fbad336fd46ecebcf5185327e009ae8dc4cc0367fc
542542
type: rasterhash
543543

544544
- algorithm: grass7:i.modis.qc
@@ -597,7 +597,7 @@ tests:
597597
vapourpressureactual: 1.511
598598
results:
599599
output:
600-
hash: 77e31601b511602b998168f715756a87a3735b07131a99b27e2de241
600+
hash: b0211772fe8e2c3d8c713551137f014756eb63ccd12f95a322f63ce0
601601
type: rasterhash
602602

603603
- algorithm: grass7:i.atcorr
@@ -615,5 +615,5 @@ tests:
615615
name: custom/grass7/i.atcorr.txt
616616
results:
617617
output:
618-
hash: 46dea0dc5e5a3fed82aed98aa1cb6fe82deb8f1ac0347e930d4bbbeb
618+
hash: e5fada2ec43658e25a34d0486e810dec1cad289b626f6d1c4bbfea18
619619
type: rasterhash

0 commit comments

Comments
 (0)
Please sign in to comment.