| 1 | #!/usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | ############################################################################
|
|---|
| 4 | #
|
|---|
| 5 | # MODULE: test_row_above_below_bug.py
|
|---|
| 6 | # AUTHOR: Vaclav Petras
|
|---|
| 7 | # PURPOSE: Show bug reported in #3067
|
|---|
| 8 | # COPYRIGHT: (C) 2016 by Vaclav Petras and the GRASS Development Team
|
|---|
| 9 | #
|
|---|
| 10 | # This program is free software under the GNU General Public
|
|---|
| 11 | # License (>=v2). Read the file COPYING that comes with GRASS
|
|---|
| 12 | # for details.
|
|---|
| 13 | #
|
|---|
| 14 | #############################################################################
|
|---|
| 15 |
|
|---|
| 16 | # #3067
|
|---|
| 17 | # r.mapcalc gives wrong result when neighborhood modifier takes a cell
|
|---|
| 18 | # above first
|
|---|
| 19 | # https://trac.osgeo.org/grass/ticket/3067
|
|---|
| 20 |
|
|---|
| 21 | from grass.gunittest.case import TestCase
|
|---|
| 22 | from grass.gunittest.main import test
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | INPUT = """\
|
|---|
| 26 | north: 10
|
|---|
| 27 | south: 8
|
|---|
| 28 | east: 20
|
|---|
| 29 | west: 18
|
|---|
| 30 | rows: 3
|
|---|
| 31 | cols: 3
|
|---|
| 32 | 1 0 1
|
|---|
| 33 | 1 1 0
|
|---|
| 34 | 1 1 0
|
|---|
| 35 | """
|
|---|
| 36 |
|
|---|
| 37 | OUTPUT = """\
|
|---|
| 38 | north: 10
|
|---|
| 39 | south: 8
|
|---|
| 40 | east: 20
|
|---|
| 41 | west: 18
|
|---|
| 42 | rows: 3
|
|---|
| 43 | cols: 3
|
|---|
| 44 | null: *
|
|---|
| 45 | * * *
|
|---|
| 46 | 2 1 1
|
|---|
| 47 | * * *
|
|---|
| 48 | """
|
|---|
| 49 |
|
|---|
| 50 | class TestRowAboveAndBelowBug(TestCase):
|
|---|
| 51 | # TODO: replace by unified handing of maps
|
|---|
| 52 | to_remove = []
|
|---|
| 53 | input = 'r_mapcalc_test_input'
|
|---|
| 54 | output = 'r_mapcalc_test_output'
|
|---|
| 55 | output_ref = 'r_mapcalc_test_output_ref'
|
|---|
| 56 |
|
|---|
| 57 | def setUp(self):
|
|---|
| 58 | self.use_temp_region()
|
|---|
| 59 | self.runModule('r.in.ascii', input='-', stdin_=INPUT,
|
|---|
| 60 | output=self.input, overwrite=True)
|
|---|
| 61 | self.to_remove.append(self.input)
|
|---|
| 62 | self.runModule('g.region', raster=self.input)
|
|---|
| 63 | self.runModule('r.in.ascii', input='-', stdin_=OUTPUT,
|
|---|
| 64 | output=self.output_ref, overwrite=True)
|
|---|
| 65 | self.to_remove.append(self.output_ref)
|
|---|
| 66 |
|
|---|
| 67 | def tearDown(self):
|
|---|
| 68 | self.del_temp_region()
|
|---|
| 69 | if 0 and self.to_remove:
|
|---|
| 70 | self.runModule('g.remove', flags='f', type='raster',
|
|---|
| 71 | name=','.join(self.to_remove), verbose=True)
|
|---|
| 72 |
|
|---|
| 73 | def r_mapcalc_with_test(self, expression):
|
|---|
| 74 | """Expects just RHS and inputs as ``{m}`` for format function"""
|
|---|
| 75 | expression = expression.format(m=self.input)
|
|---|
| 76 | expression = "{0} = {1}".format(self.output, expression)
|
|---|
| 77 | self.assertModule('r.mapcalc', expression=expression, overwrite=True)
|
|---|
| 78 | self.assertRasterExists(self.output)
|
|---|
| 79 | self.to_remove.append(self.output)
|
|---|
| 80 | ref_univar = dict(null_cells=6, cells=9)
|
|---|
| 81 | self.assertRasterFitsUnivar(raster=self.output,
|
|---|
| 82 | reference=ref_univar, precision=0)
|
|---|
| 83 | self.assertRastersNoDifference(actual=self.output,
|
|---|
| 84 | reference=self.output_ref,
|
|---|
| 85 | precision=0) # it's CELL type
|
|---|
| 86 |
|
|---|
| 87 | def test_below_above(self):
|
|---|
| 88 | self.r_mapcalc_with_test("{m}[1,0] + {m}[-1,0]")
|
|---|
| 89 |
|
|---|
| 90 | def test_above_below(self):
|
|---|
| 91 | self.r_mapcalc_with_test("{m}[-1,0] + {m}[1,0]")
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | if __name__ == '__main__':
|
|---|
| 95 | test()
|
|---|