astropy / astropy/specutils

Inplace multiplication of the spectral axis with a constant fails

Open
#720 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
204
Forks
134
Avg merge
12h 55m
Merged PRs (30d)
1

Description

As the title says, inplace multiplication of the spectral axis with a constant fails.
It produces the following error:
```
astropy.units.core.UnitTypeError: Cannot store output with unit 'Angstrom' from multiply function in instance. Use instance instead.
```

Here is the minimal working code:
```
import numpy as np
from astropy import units as u
from specutils.spectra import Spectrum1D

wave = np.linspace(100, 200, 100) << u.AA
flux = np.ones(100) << u.one
spec = Spectrum1D(spectral_axis=wave, flux=flux)

spec._spectral_axis *= 1
```

Contributor guide

Open the contributing guide

Research direction

Run the minimal reproduction and inspect specutils.spectra.spectral_axis.SpectralAxis together with the Astropy unit error. Determine why in-place multiplication rejects the output, then verify that multiplying the spectral axis by a constant completes without UnitTypeError and preserves the expected spectral-axis values and units.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.