def test_raster_statistics_column_names_novector(self): """ Test that column_names property matches head(0) for RasterStatistics when vector is None """ r = RasterStatistics(raster="worldpop_gambia") assert r.head(0).columns.tolist() == r.column_names
def test_computes_expected_total_value(self): """ RasterStatistics() computes correct total value of raster. """ r = RasterStatistics(raster="worldpop_gambia") result = r.get_dataframe() self.assertAlmostEqual(result["statistic"].iloc[0], 2083543.79777587)
def test_raster_statistics_column_names_vector(self): """ Test that column_names property matches head(0) for RasterStatistics when vector is not None """ vector = Table(schema="public", name="gambia_admin2") r = RasterStatistics(raster="worldpop_gambia", vector=vector, grouping_element="district_c") assert r.head(0).columns.tolist() == r.column_names
def test_raster_statistics_column_names_novector(get_dataframe): """ Test that column_names property matches head(0) for RasterStatistics when vector is None """ r = RasterStatistics(raster="population.small_nepal_raster") assert get_dataframe(r).columns.tolist() == r.column_names
def test_computes_expected_total_value(get_dataframe): """ RasterStatistics() computes correct total value of raster. """ r = RasterStatistics(raster="population.small_nepal_raster") result = get_dataframe(r) assert result["statistic"].iloc[0] == 2500000
def test_computes_expected_clipping_values(self): """ RasterStatistics() returns correct values when clipping vector and raster layers. """ G = "district_c" vector = Table(schema="public", name="gambia_admin2") r = RasterStatistics(raster="worldpop_gambia", vector=vector, grouping_element=G) result = r.get_dataframe() for expected_result in self.rasterio_results.to_dict("records"): self.assertAlmostEqual( int(result[result[G] == expected_result["district"]].statistic.iloc[0]), expected_result["value"], )
def test_raises_valueerror_when_grouping_element_not_provided(self): """ RasterStatistics() raises ValueError when `grouping_element` not provided. """ G = None with self.assertRaises(ValueError): r = RasterStatistics(raster="worldpop_gambia", vector="gambia_admin2", grouping_element=None)
def test_raises_valueerror_when_grouping_element_not_provided(): """ RasterStatistics() raises ValueError when `grouping_element` not provided. """ G = None vector = Table(schema="geography", name="admin2") with pytest.raises(ValueError): r = RasterStatistics( "population.small_nepal_raster", vector=vector, grouping_element=None )
def test_raster_statistics_column_names_vector(get_dataframe): """ Test that column_names property matches head(0) for RasterStatistics when vector is not None """ vector = Table(schema="geography", name="admin2") r = RasterStatistics( raster="population.small_nepal_raster", vector=vector, grouping_element="admin2pcod", ) assert get_dataframe(r).columns.tolist() == r.column_names
def test_raises_notimplemented_when_wrong_statistic_requested(self): """ RasterStatistics() raises NotImplementedError if wrong statistic requested. """ G = "district_c" with self.assertRaises(NotImplementedError): r = RasterStatistics( raster="worldpop_gambia", vector="gambia_admin2", grouping_element=G, statistic="mean", )
def test_raises_notimplemented_when_wrong_statistic_requested(): """ RasterStatistics() raises NotImplementedError if wrong statistic requested. """ vector = Table(schema="geography", name="admin2") with pytest.raises(NotImplementedError): G = "admin2pcod" r = RasterStatistics( raster="population.small_nepal_raster", vector=vector, grouping_element=G, statistic="foobar", )
def test_computes_expected_clipping_values(get_dataframe): """ RasterStatistics() returns correct values when clipping vector and raster layers. """ G = "admin2pcod" vector = Table(schema="geography", name="admin2") r = RasterStatistics( raster="population.small_nepal_raster", vector=vector, grouping_element=G ) result = get_dataframe(r) # Should have only _one_ entry assert 1 == len(result) assert "524 3 07" in result.admin2pcod.values assert 2500000.0 == result.set_index("admin2pcod").loc["524 3 07"][0]
def test_failure_with_no_grouping_layer(self): """ RasterStatistics() checks that we can get column names when grouping layer omitted. """ r = RasterStatistics(raster="worldpop_gambia") r.column_names