Skip to content

Commit

Permalink
Avoid duplication in spatial_smooth*
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Apr 16, 2020
1 parent 54f7d41 commit ccef67f
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions spectral_cube/dask_spectral_cube.py
Expand Up @@ -755,20 +755,10 @@ def spatial_smooth(self, kernel,
Passed to the convolve function
"""

kernel = kernel.array
def convolve_wrapper(data, kernel=None, **kwargs):
return convolve(data, kernel, normalize_kernel=True, **kwargs)

def convolve_wrapper(img):
if img.size > 0:
out = np.zeros(img.shape, dtype=img.dtype)
for index in range(img.shape[0]):
out[index] = convolve(img[index], kernel, normalize_kernel=True, **kwargs)
return out
else:
return img

# Rechunk so that there is only one chunk in the image plane
return self._map_blocks_to_cube(convolve_wrapper,
rechunk=('auto', -1, -1))
return self.apply_function_parallel_spatial(convolve_wrapper, kernel=kernel.array)

def spatial_smooth_median(self, ksize, **kwargs):
"""
Expand All @@ -785,12 +775,10 @@ def spatial_smooth_median(self, ksize, **kwargs):
if not SCIPY_INSTALLED:
raise ImportError("Scipy could not be imported: this function won't work.")

def median_filter_wrapper(img, **kwargs):
return ndimage.median_filter(img, (1, ksize, ksize), **kwargs)
def median_filter_wrapper(data, ksize=None):
return ndimage.median_filter(data, ksize)

# Rechunk so that there is only one chunk in the image plane
return self._map_blocks_to_cube(median_filter_wrapper,
rechunk=('auto', -1, -1))
return self.apply_function_parallel_spatial(median_filter_wrapper, ksize=ksize)

def _pix_cen(self, axis=None):
"""
Expand Down

0 comments on commit ccef67f

Please sign in to comment.