Skip to content

specutils.manipulation gaussian_smooth does not work on numpy.int64 input stddev #1224

Open
@Rplesha

Description

@Rplesha

I was trying to loop over a range of smoothing factors, which resulted in a confusing error.

Example code:

for factor in np.arange(11, 21, 2):
    smooth_data = gaussian_smooth(spec1d, stddev=factor)

resulting in the error:

ValueError                                Traceback (most recent call last)
Cell In[25], line 2
      1 for factor in np.arange(11, 21, 2):
----> 2     smooth_data = gaussian_smooth(spec1d, stddev=factor)

File ~/miniconda3/envs/jwst/lib/python3.11/site-packages/specutils/manipulation/smoothing.py:185, in gaussian_smooth(spectrum, stddev)
    183 # Parameter checks
    184 if not isinstance(stddev, (int, float)) or stddev <= 0:
--> 185     raise ValueError("The stddev parameter, {}, must be a number greater "
    186                      "than 0".format(stddev))
    188 # Create the gaussian kernel
    189 gaussian_kernel = convolution.Gaussian1DKernel(stddev)

ValueError: The stddev parameter, 11, must be a number greater than 0

There are of course multiple ways to get around this, including changing to np.arange(11.0, 21, 2), or creating a list of numbers, but I don't see a reason why int64 should not be included as an acceptable type. If there is a valid reason though, I suggest adding a more pointed error message.

I believe the relevant code to update is at:

if not isinstance(stddev, (int, float)) or stddev <= 0:

I'm running specutils v1.19.0 on a mac running Sequoia 15.3.2, python 3.11.7. spec1d in this instance is a JWST NIRSpec dataset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions