Skip to content

Commit

Permalink
Merge pull request #369 from phargogh/bugfix/368-zonal-statistics-log…
Browse files Browse the repository at this point in the history
…ging-bug

Fix minor logging issue in `zonal_statistics`
  • Loading branch information
emlys authored Mar 7, 2024
2 parents e514865 + f9a1915 commit 83e3ffd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Unreleased Changes
provided instead of a vector. If both are provided, the mask raster alone is
used. The new mask raster must have the same dimensions and geotransform as
the output warped raster. https://github.com/natcap/pygeoprocessing/issues/366
* Fixed a bug in ``zonal_statistics`` where the wrong number of disjoint
polygon sets were being reported in the logs.
https://github.com/natcap/pygeoprocessing/issues/368
* Pygeoprocessing is now tested against python 3.12.
https://github.com/natcap/pygeoprocessing/issues/355

Expand Down
11 changes: 6 additions & 5 deletions src/pygeoprocessing/geoprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1890,14 +1890,14 @@ def default_aggregate_dict():
attribute=fid_field_name,
noData=fid_nodata,
outputBounds=aligned_bbox,
xRes=abs(raster_info['pixel_size'][0]), # resolution should always be positive
xRes=abs(raster_info['pixel_size'][0]), # resolution must be > 0
yRes=abs(raster_info['pixel_size'][1]),
format='GTIFF',
outputType=gdal.GDT_UInt16,
creationOptions=DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS[1],
callback=_make_logger_callback(
f'rasterizing disjoint polygon set {i + 1} of '
f'{len(disjoint_fid_set)} set %.1f%% complete (%s)'),
f'{len(disjoint_fid_sets)} set %.1f%% complete (%s)'),
where=(f'{fid_field_name} IN ({fid_set_str})'))
fid_raster_paths.append(fid_raster_path)

Expand All @@ -1912,11 +1912,12 @@ def default_aggregate_dict():
nodata = get_raster_info(raster_path)['nodata'][band - 1]
data_source = gdal.OpenEx(raster_path, gdal.OF_RASTER)
data_band = data_source.GetRasterBand(band)
found_fids = set() # track FIDs that have been found on at least one pixel
found_fids = set() # track FIDs found on at least one pixel

for set_index, fid_raster_path in enumerate(fid_raster_paths):
LOGGER.info(
f'disjoint polygon set {set_index} of {len(fid_raster_paths)}')
f'disjoint polygon set {set_index + 1} of '
f'{len(fid_raster_paths)}')
fid_raster = gdal.OpenEx(fid_raster_path, gdal.OF_RASTER)
fid_band = fid_raster.GetRasterBand(1)

Expand Down Expand Up @@ -2796,7 +2797,7 @@ def rasterize(
"%s doesn't exist, but needed to rasterize." % target_raster_path)

rasterize_callback = _make_logger_callback(
"RasterizeLayer %.1f%% complete %s")
"pygeoprocessing.rasterize RasterizeLayer %.1f%% complete %s")

if burn_values is None:
burn_values = []
Expand Down

0 comments on commit 83e3ffd

Please sign in to comment.