PetroFit / petrofit

Python package for calculating Petrosian properties and fitting galaxy light profiles
https://petrofit.readthedocs.io
28 stars 7 forks source link

Default Kernel Size in `make_catalog` is not odd #132

Closed robelgeda closed 2 years ago

robelgeda commented 2 years ago
---------------------------------------------------------------------------
KernelSizeError                           Traceback (most recent call last)
Input In [17], in <cell line: 1>()
----> 1 cat, segm, segm_deblend = make_catalog(data.data, threshold=data_std*5)

File ~/project/repo/petrofit/petrofit/segmentation.py:401, in make_catalog(image, threshold, wcs, deblend, npixels, fwhm, kernel_size, nlevels, contrast, plot, vmax, vmin)
    398     image = image.data
    400 # Make segmentation map
--> 401 segm = make_segments(image,
    402                      threshold=threshold,
    403                      kernel_size=kernel_size,
    404                      fwhm=fwhm, npixels=npixels)
    406 if plot and segm:
    407     # Make plots
    408     if deblend:

File ~/project/repo/petrofit/petrofit/segmentation.py:260, in make_segments(image, npixels, threshold, fwhm, kernel_size)
    256     npixels = fwhm ** 2
    258 kernel = make_kernel(fwhm, kernel_size) if kernel_size else None
--> 260 return detect_sources(image, threshold, npixels=npixels, kernel=kernel)

File ~/miniconda3/envs/petrofit/lib/python3.9/site-packages/astropy/utils/decorators.py:546, in deprecated_renamed_argument.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    543             msg += f'\n        Use {alternative} instead.'
    544         warnings.warn(msg, warning_type, stacklevel=2)
--> 546 return function(*args, **kwargs)

File ~/miniconda3/envs/petrofit/lib/python3.9/site-packages/photutils/segmentation/detect.py:395, in detect_sources(data, threshold, npixels, kernel, connectivity, mask)
    298 @deprecated_renamed_argument('filter_kernel', 'kernel', '1.2')
    299 def detect_sources(data, threshold, npixels, kernel=None, connectivity=8,
    300                    mask=None):
    301     """
    302     Detect sources above a specified threshold value in an image and
    303     return a `~photutils.segmentation.SegmentationImage` object.
   (...)
    393         plt.tight_layout()
    394     """
--> 395     return _detect_sources(data, (threshold,), npixels, kernel=kernel,
    396                            connectivity=connectivity, mask=mask)[0]

File ~/miniconda3/envs/petrofit/lib/python3.9/site-packages/photutils/segmentation/detect.py:247, in _detect_sources(data, thresholds, npixels, kernel, connectivity, mask, deblend_skip)
    245     with warnings.catch_warnings():
    246         warnings.simplefilter('ignore', AstropyUserWarning)
--> 247         data = convolve(data, kernel, mask=mask, normalize_kernel=True)
    249 selem = _make_binary_structure(data.ndim, connectivity)
    251 segms = []

File ~/miniconda3/envs/petrofit/lib/python3.9/site-packages/astropy/nddata/decorators.py:246, in support_nddata.<locals>.support_nddata_decorator.<locals>.wrapper(data, *args, **kwargs)
    240     if ignored:
    241         warnings.warn("The following attributes were set on the "
    242                       "data object, but will be ignored by the "
    243                       "function: " + ", ".join(ignored),
    244                       AstropyUserWarning)
--> 246 result = func(data, *args, **kwargs)
    248 if unpack and repack:
    249     # If there are multiple required returned arguments make sure
    250     # the result is a tuple (because we don't want to unpack
    251     # numpy arrays or compare their length, never!) and has the
    252     # same length.
    253     if len(returns) > 1:

File ~/miniconda3/envs/petrofit/lib/python3.9/site-packages/astropy/convolution/convolve.py:265, in convolve(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol)
    263 # Make sure kernel has all odd axes
    264 if has_even_axis(kernel_internal):
--> 265     raise_even_kernel_exception()
    267 # If both image array and kernel are Kernel instances
    268 # constrain convolution method
    269 # This must occur before the main alias/copy of ``passed_kernel`` to
    270 # ``kernel_internal`` as it is used for filling masked kernels.
    271 if isinstance(passed_array, Kernel) and isinstance(passed_kernel, Kernel):

File ~/miniconda3/envs/petrofit/lib/python3.9/site-packages/astropy/convolution/utils.py:30, in raise_even_kernel_exception()
     29 def raise_even_kernel_exception():
---> 30     raise KernelSizeError("Kernel size must be odd in all axes.")

KernelSizeError: Kernel size must be odd in all axes.