123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #!/usr/bin/env python
- ############################################################################
- #
- # MODULE: test_row_above_below_bug.py
- # AUTHOR: Vaclav Petras
- # PURPOSE: Show bug reported in #3067
- # COPYRIGHT: (C) 2016 by Vaclav Petras and the GRASS Development Team
- #
- # This program is free software under the GNU General Public
- # License (>=v2). Read the file COPYING that comes with GRASS
- # for details.
- #
- #############################################################################
- # #3067
- # r.mapcalc gives wrong result when neighborhood modifier takes a cell
- # above first
- # https://trac.osgeo.org/grass/ticket/3067
- from grass.gunittest.case import TestCase
- from grass.gunittest.main import test
- INPUT = """\
- north: 10
- south: 8
- east: 20
- west: 18
- rows: 3
- cols: 3
- 1 0 1
- 1 1 0
- 1 1 0
- """
- OUTPUT = """\
- north: 10
- south: 8
- east: 20
- west: 18
- rows: 3
- cols: 3
- null: *
- * * *
- 2 1 1
- * * *
- """
- class TestRowAboveAndBelowBug(TestCase):
- # TODO: replace by unified handing of maps
- to_remove = []
- input = 'r_mapcalc_test_input'
- output = 'r_mapcalc_test_output'
- output_ref = 'r_mapcalc_test_output_ref'
- def setUp(self):
- self.use_temp_region()
- self.runModule('r.in.ascii', input='-', stdin_=INPUT,
- output=self.input, overwrite=True)
- self.to_remove.append(self.input)
- self.runModule('g.region', raster=self.input)
- self.runModule('r.in.ascii', input='-', stdin_=OUTPUT,
- output=self.output_ref, overwrite=True)
- self.to_remove.append(self.output_ref)
- def tearDown(self):
- self.del_temp_region()
- if 0 and self.to_remove:
- self.runModule('g.remove', flags='f', type='raster',
- name=','.join(self.to_remove), verbose=True)
- def r_mapcalc_with_test(self, expression):
- """Expects just RHS and inputs as ``{m}`` for format function"""
- expression = expression.format(m=self.input)
- expression = "{0} = {1}".format(self.output, expression)
- self.assertModule('r.mapcalc', expression=expression, overwrite=True)
- self.assertRasterExists(self.output)
- self.to_remove.append(self.output)
- ref_univar = dict(null_cells=6, cells=9)
- self.assertRasterFitsUnivar(raster=self.output,
- reference=ref_univar, precision=0)
- self.assertRastersNoDifference(actual=self.output,
- reference=self.output_ref,
- precision=0) # it's CELL type
- def test_below_above(self):
- self.r_mapcalc_with_test("{m}[1,0] + {m}[-1,0]")
- def test_above_below(self):
- self.r_mapcalc_with_test("{m}[-1,0] + {m}[1,0]")
- if __name__ == '__main__':
- test()
|