Example #1
0
    def test_count_pixels_groups(self):
        """WaveEnergy: testing '_count_pixels_groups' function."""
        from natcap.invest import wave_energy

        raster_path = os.path.join(self.workspace_dir, 'pixel_groups.tif')
        srs = sampledata.SRS_WILLAMETTE

        group_values = [1, 3, 5, 7]
        matrix = numpy.array([[1, 3, 5, 9], [3, 7, 1, 5], [2, 4, 5, 7]])

        # Create raster to use for testing input
        raster_path = pygeoprocessing.testing.create_raster_on_disk(
            [matrix],
            srs.origin,
            srs.projection,
            -1,
            srs.pixel_size(100),
            datatype=gdal.GDT_Int32,
            filename=raster_path)

        results = wave_energy._count_pixels_groups(raster_path, group_values)

        expected_results = [2, 2, 3, 2]

        for res, exp_res in zip(results, expected_results):
            pygeoprocessing.testing.assert_close(res, exp_res, 1e-6)
Example #2
0
    def test_count_pixels_groups(self):
        """WaveEnergy: testing '_count_pixels_groups' function."""
        from natcap.invest import wave_energy

        srs = osr.SpatialReference()
        srs.ImportFromEPSG(3157)
        projection_wkt = srs.ExportToWkt()
        origin = (443723.127327877911739, 4956546.905980412848294)

        group_values = [1, 3, 5, 7]
        matrix = numpy.array([[1, 3, 5, 9], [3, 7, 1, 5], [2, 4, 5, 7]],
                             dtype=numpy.int32)

        raster_path = os.path.join(self.workspace_dir, 'pixel_groups.tif')
        # Create raster to use for testing input
        pygeoprocessing.numpy_array_to_raster(matrix, -1, (100, -100), origin,
                                              projection_wkt, raster_path)

        results = wave_energy._count_pixels_groups(raster_path, group_values)

        expected_results = [2, 2, 3, 2]

        for res, exp_res in zip(results, expected_results):
            self.assertAlmostEqual(res, exp_res, places=6)