test_r_import.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. from grass.gunittest.case import TestCase
  3. from grass.gunittest.main import test
  4. import grass.script as gs
  5. class TestRImportRegion(TestCase):
  6. imported = 'test_r_import_imported'
  7. @classmethod
  8. def setUpClass(cls):
  9. cls.runModule('g.region', raster='elevation')
  10. def tearDown(cls):
  11. """Remove imported map after each test method"""
  12. cls.runModule('g.remove', flags='f', type='raster',
  13. name=cls.imported)
  14. def test_import_estimate(self):
  15. """Test e flag"""
  16. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  17. resample='nearest', flags='e')
  18. self.assertRasterDoesNotExist(name=self.imported)
  19. def test_import_same_proj_tif(self):
  20. """Import tif in same proj, default params"""
  21. self.assertModule('r.import', input='data/data1.tif', output=self.imported,
  22. resample='bilinear')
  23. reference = dict(north=223490, south=223390, east=636820, west=636710,
  24. nsres=10, ewres=10, datatype='FCELL')
  25. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1e-6)
  26. def test_import_asc_custom_res(self):
  27. """Import ASC in different projection, with specified resolution"""
  28. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  29. resample='nearest', resolution='value', resolution_value=30)
  30. reference = dict(rows=3, cols=4,
  31. nsres=30, ewres=30, datatype='CELL')
  32. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1.1)
  33. def test_import_asc_region_extent(self):
  34. """Import ASC in different projection in specified region"""
  35. self.runModule('g.region', raster='elevation', n=223655, s=223600)
  36. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  37. resample='nearest', extent='region', resolution='region')
  38. reference = dict(north=223655, south=223600)
  39. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1e-6)
  40. def test_import_use_temp_region(self):
  41. """Import in specified region with use_temp_region activated"""
  42. self.runModule('g.region', raster='elevation', n=223660, s=223600)
  43. gs.use_temp_region()
  44. self.runModule('g.region', raster='elevation', n=223630, s=223600)
  45. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  46. resample='nearest', extent='region', resolution='region')
  47. reference = dict(north=223630, south=223600, nsres=10, ewres=10)
  48. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1e-6)
  49. self.runModule('g.region', raster='elevation', s=223390, n=223450)
  50. self.assertModule('r.import', input='data/data1.tif', output=self.imported,
  51. resample='bilinear', extent='region', overwrite=True)
  52. reference = dict(south=223390, north=223450, nsres=10, ewres=10)
  53. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1e-6)
  54. gs.del_temp_region()
  55. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  56. resample='nearest', extent='region', resolution='region', overwrite=True)
  57. reference = dict(north=223660, south=223600, nsres=10, ewres=10)
  58. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1e-6)
  59. if __name__ == '__main__':
  60. test()