Skip to content

Commit

Permalink
Testing multiple pixel sizes. RE:natcap#722
Browse files Browse the repository at this point in the history
  • Loading branch information
phargogh committed Nov 15, 2021
1 parent 4f3761d commit 10c5f5a
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions tests/test_urban_nature_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ def test_resample_population_raster(self):
projection_wkt=population_wkt,
target_path=source_population_raster_path)

target_population_raster_path = os.path.join(
self.workspace_dir, 'resampled_population.tif')
urban_nature_access._resample_population_raster(
source_population_raster_path=source_population_raster_path,
target_population_raster_path=target_population_raster_path,
target_pixel_size=(30, -30), # 1/3 the population pixel size
target_bb=pygeoprocessing.get_raster_info(
source_population_raster_path)['bounding_box'],
target_projection_wkt=population_wkt,
working_dir=os.path.join(self.workspace_dir, 'working'))
for target_pixel_size in (
(30, -30), # 1/3 the pixel size
(4, -4), # way smaller
(100, -100)): # bigger
target_population_raster_path = os.path.join(
self.workspace_dir, 'resampled_population.tif')
urban_nature_access._resample_population_raster(
source_population_raster_path=source_population_raster_path,
target_population_raster_path=target_population_raster_path,
target_pixel_size=target_pixel_size,
target_bb=pygeoprocessing.get_raster_info(
source_population_raster_path)['bounding_box'],
target_projection_wkt=population_wkt,
working_dir=os.path.join(self.workspace_dir, 'working'))

resampled_population_array = pygeoprocessing.raster_to_numpy_array(
target_population_raster_path)
numpy.testing.assert_allclose(
population_array.sum(), resampled_population_array.sum())
resampled_population_array = pygeoprocessing.raster_to_numpy_array(
target_population_raster_path)
numpy.testing.assert_allclose(
population_array.sum(), resampled_population_array.sum())

0 comments on commit 10c5f5a

Please sign in to comment.