SciPy Interpolate true_divide warning when making a new spectrum
- Dominant language
- Python
- Stars
- 204
- Forks
- 134
- Avg merge
- 12h 55m
- Merged PRs (30d)
- 1
Description
A seemingly unjustified `true_divide` warning message pops up when normalizing a spectrum:
```python
import warnings
import astropy
import numpy as np
import astropy.units as u
import specutils
# See Issue https://github.com/astropy/specutils/issues/779
warnings.filterwarnings('ignore', category=astropy.utils.exceptions.AstropyDeprecationWarning)
spec = specutils.Spectrum1D(flux=np.random.normal(2.0, 0.01, size=500)*u.erg/u.s,
spectral_axis=np.linspace(1, 1.5, num=500)*u.micron)
```
```python
spec.flux / np.median(spec.flux)
```
:arrow_right: `no warning message`
whereas making a new Spectrum1D object somehow is attempting to interpolate, which seems unnecessary for division by a scalar:
```python
spec_normalized = spec / np.median(spec.flux) # yes warning message
```
:arrow_down:
```
lib/python3.7/site-packages/scipy/interpolate/interpolate.py:2533: RuntimeWarning: invalid value encountered in true_divide
(grid[i + 1] - grid[i]))
```
Contributor guide
Research direction
Reproduce the warning with the Spectrum1D example and compare direct flux division with Spectrum1D division. Trace the Spectrum1D arithmetic and interpolation path used by `spec / np.median(spec.flux)`. Done means scalar normalization no longer emits the unnecessary `true_divide` warning while preserving the expected normalized spectrum.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100