Skip to content

Issues with NaN treatment and normalisation in convolve_fft #8114

Open

Description

@jamienoss

convolve_fft(nan_treatment='fill') doesn't normalize when passed normalization function

When no NaN or inf are present in the input arrays, nan_treatment=('fill,'interpolate') should have identical behavior. The following test fails.

import numpy as np
from astropy.convolution import convolve, convolve_fft
from astropy.convolution.tests.test_convolve_fft import assert_floatclose

array = [1, 2, 3]
kernel = [3, 3, 3]

fill = convolve_fft(array, kernel, normalize_kernel=np.max, nan_treatment='fill')
interpolate = convolve_fft(array, kernel, normalize_kernel=np.max, nan_treatment='interpolate')

assert_floatclose(fill, interpolate)

This is only an issue when passing a normalization function via normalize_kernel.

This is blocking #8101.

I am currently in the progress of fixing this issue and refactoring the scattered and implicit normalization logic.

Activity

  1. jamienoss commented on Nov 15, 2018

    @jamienoss
    ContributorAuthor

    normalize_kernel=someFunc() and nan_treatment='interpolate'

    Note: I'm not yet sure if this is a bug because I'm not yet 100% sure about how the interpolation works.

    The following exception should be raised regardless of the state of normalize_kernel, i.e. it should be pulled out and checked after the normalization block.

    [src]

    ...
            kernel_scale = kernel.sum()
            if np.abs(kernel_scale) < normalization_zero_tol:
                if nan_treatment == 'interpolate':
                    raise ValueError('Cannot interpolate NaNs with an unnormalizable kernel')
    ...

    Furthermore, if normalize_kernel=someFunc() and nan_treatment='interpolate' then the exception should not be conditional on kernel.sum() but someFunc(kernel). Also, any normalization used for the interpolation should use someFunc.

    I have assumed that it is and refactored it accordingly whilst working on this issue. If it turns out to really be a bug, I'll open an issue and link in the commit message, I'll remove otherwise.

  2. jamienoss commented on Nov 15, 2018

    @jamienoss
    ContributorAuthor
  3. changed the title [-]convolve_fft(nan_treatment='fill') doesn't normalize when passed normalization function[/-] [+]Issues with NaN treatment and normalisation in convolve_fft[/+] on Nov 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions