Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/pygeoprocessing/geoprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4079,15 +4079,17 @@ def _convolve_2d_worker(

# add zero padding so FFT is fast
fshape = [_next_regular(int(d)) for d in shape]
f_axes_seq = range(len(fshape))

signal_fft = numpy.fft.rfftn(signal_block, fshape)
kernel_fft = numpy.fft.rfftn(kernel_block, fshape)
signal_fft = numpy.fft.rfftn(signal_block, fshape, f_axes_seq)
kernel_fft = numpy.fft.rfftn(kernel_block, fshape, f_axes_seq)

# this variable determines the output slice that doesn't include
# the padded array region made for fast FFTs.
fslice = tuple([slice(0, int(sz)) for sz in shape])
# classic FFT convolution
result = numpy.fft.irfftn(signal_fft * kernel_fft, fshape)[fslice]
result = numpy.fft.irfftn(
signal_fft * kernel_fft, fshape, f_axes_seq)[fslice]
# nix any roundoff error
if set_tol_to_zero is not None:
result[numpy.isclose(result, set_tol_to_zero)] = 0.0
Expand All @@ -4096,9 +4098,9 @@ def _convolve_2d_worker(
# nodata mask too
if ignore_nodata:
mask_fft = numpy.fft.rfftn(
numpy.where(signal_nodata_mask, 0.0, 1.0), fshape)
numpy.where(signal_nodata_mask, 0.0, 1.0), fshape, f_axes_seq)
mask_result = numpy.fft.irfftn(
mask_fft * kernel_fft, fshape)[fslice]
mask_fft * kernel_fft, fshape, f_axes_seq)[fslice]

left_index_result = 0
right_index_result = result.shape[1]
Expand Down
16 changes: 8 additions & 8 deletions tests/test_geoprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ def test_warp_raster_mask_raster(self):
base_a_raster_info = pygeoprocessing.get_raster_info(base_a_path)
pygeoprocessing.warp_raster(
base_a_path, base_a_raster_info['pixel_size'], target_raster_path,
'near', vector_mask_options={'mask_raster_path': mask_raster_path})
'near', mask_options={'mask_raster_path': mask_raster_path})

expected_matrix = numpy.ones((5, 5), numpy.int16)
expected_matrix[0, 0] = target_nodata
Expand Down Expand Up @@ -4205,7 +4205,7 @@ def test_align_and_resize_raster_stack_int_with_vector_mask(self):
resample_method_list,
base_a_raster_info['pixel_size'], bounding_box_mode,
raster_align_index=0,
vector_mask_options={
mask_options={
'mask_vector_path': dual_poly_path,
'mask_layer_name': 'dual_poly',
},
Expand All @@ -4223,7 +4223,7 @@ def test_align_and_resize_raster_stack_int_with_vector_mask(self):
resample_method_list,
base_a_raster_info['pixel_size'], bounding_box_mode,
raster_align_index=0,
vector_mask_options={
mask_options={
'mask_vector_path': dual_poly_path,
'mask_layer_name': 'dual_poly',
'mask_vector_where_filter': 'value=1',
Expand Down Expand Up @@ -4279,7 +4279,7 @@ def test_align_and_resize_raster_stack_int_with_vector_mask_bb(self):
(111000/2, -111000/2), poly_bb_transform,
raster_align_index=0,
target_projection_wkt=utm_31w_srs.ExportToWkt(),
vector_mask_options={
mask_options={
'mask_vector_path': poly_path,
'mask_layer_name': 'poly',
'mask_vector_where_filter': 'value=100'
Expand Down Expand Up @@ -4335,7 +4335,7 @@ def test_align_and_resize_raster_stack_int_with_bad_vector_mask(self):
resample_method_list,
base_a_raster_info['pixel_size'], bounding_box_mode,
raster_align_index=0,
vector_mask_options={
mask_options={
'mask_vector_path': dual_poly_path,
'mask_layer_name': 'dual_poly',
})
Expand All @@ -4349,7 +4349,7 @@ def test_align_and_resize_raster_stack_int_with_bad_vector_mask(self):
resample_method_list,
base_a_raster_info['pixel_size'], bounding_box_mode,
raster_align_index=0,
vector_mask_options={
mask_options={
'bad_mask_vector_path': dual_poly_path,
'mask_layer_name': 'dual_poly',
})
Expand All @@ -4361,7 +4361,7 @@ def test_align_and_resize_raster_stack_int_with_bad_vector_mask(self):
pygeoprocessing.warp_raster(
base_a_path, base_a_raster_info['pixel_size'],
target_path, 'near',
vector_mask_options={
mask_options={
'bad_mask_vector_path': dual_poly_path,
'mask_layer_name': 'dual_poly',
})
Expand All @@ -4373,7 +4373,7 @@ def test_align_and_resize_raster_stack_int_with_bad_vector_mask(self):
pygeoprocessing.warp_raster(
base_a_path, base_a_raster_info['pixel_size'],
target_path, 'near',
vector_mask_options={
mask_options={
'mask_vector_path': 'not_a_file.shp',
'mask_layer_name': 'dual_poly',
})
Expand Down