def test_raster_equality_to_tolerance(self): """Verify assert_rasters_equal asserts out to the given tolerance.""" from pygeoprocessing.testing import assert_rasters_equal filename_a = os.path.join(self.workspace, 'a.tif') filename_b = os.path.join(self.workspace, 'b.tif') RasterTests.create_raster(filename=filename_a, band_matrices=[numpy.array([[0.1234567]])]) RasterTests.create_raster(filename=filename_b, band_matrices=[numpy.array([[0.123]])]) # 0.005 is greater than the difference between the pixel values in # these two matrices. We're only testing that we can use a # user-defined tolerance here. assert_rasters_equal(filename_a, filename_b, rel_tol=0.005)
def test_raster_different_count(self): """Verify assert_rasters_equal catches different layer counts.""" from pygeoprocessing.testing import assert_rasters_equal filename_a = os.path.join(self.workspace, 'a.tif') filename_b = os.path.join(self.workspace, 'b.tif') RasterTests.create_raster(filename=filename_a, band_matrices=[numpy.array([[0.1]])]) RasterTests.create_raster( filename=filename_b, band_matrices=[numpy.array([[0.1]]), numpy.array([[0.1]])]) with self.assertRaises(AssertionError): assert_rasters_equal(filename_a, filename_b, rel_tol=0.00005)
def test_raster_different_projections(self): """Verify assert_rasters_equal catches differing projections.""" from pygeoprocessing.testing import assert_rasters_equal from pygeoprocessing.testing.sampledata import SRS_COLOMBIA,\ SRS_WILLAMETTE filename_a = os.path.join(self.workspace, 'a.tif') filename_b = os.path.join(self.workspace, 'b.tif') RasterTests.create_raster(projection_wkt=SRS_COLOMBIA.projection, filename=filename_a) RasterTests.create_raster(projection_wkt=SRS_WILLAMETTE.projection, filename=filename_b) with self.assertRaises(AssertionError): assert_rasters_equal(filename_a, filename_b, rel_tol=0.00005)
def test_rasters_different(self): """Test that rasters with different values fail.""" from pygeoprocessing.testing import assert_rasters_equal # band matrices need to have 2 pixels in order to reach the eng of the # iteration loop within assert_rasters_equal. filename_a = os.path.join(self.workspace, 'a.tif') filename_b = os.path.join(self.workspace, 'b.tif') RasterTests.create_raster(filename=filename_a, band_matrices=[numpy.array([[0, 0]])]) RasterTests.create_raster(filename=filename_b, band_matrices=[numpy.array([[0, 1]])]) with self.assertRaises(AssertionError): assert_rasters_equal(filename_a, filename_b, 1e-9)
def test_raster_inequality_to_tolerance(self): """Verify assert_rasters_equal fails if inequal past a tolerance.""" from pygeoprocessing.testing import assert_rasters_equal filename_a = os.path.join(self.workspace, 'a.tif') filename_b = os.path.join(self.workspace, 'b.tif') RasterTests.create_raster(filename=filename_a, band_matrices=[numpy.array([[0.1234567]])]) RasterTests.create_raster(filename=filename_b, band_matrices=[numpy.array([[0.123]])]) # 0.005 is smaller than the difference between the pixel values in # these two matrices, so the relative tolerance check should fail. with self.assertRaises(AssertionError): assert_rasters_equal(filename_a, filename_b, rel_tol=0.00005)