astropy / astropy/specutils

Have Spectrum1D(spectrum,...) constructor copy a spectrum with individual attributes set.

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

Description

#600 adds an example of spectral shifting by creating a new `Spectrum1D` object. As it stands this makes sense, but the method shown there has the flow that it requires the user to specify everything the want to copy over manually. So if e.g. there's an ``uncertainty``, or a ``meta`` or a ``mask``, the user has to remember to include them by hand.

Instead, I think it would be better if this worked:
```
>>> original_spectrum = ...
>>> shifted_spectrum = Spectrum1D(original_spectrum, spectral_axis=original_spectrum + shift)
```
i.e., the ``Spectrum1D(spec, ...something else..)`` construct would be understood to copy everything in ``spec`` *except* anything explicitly overridden in ``something else``.

Right now ``Spectrum1D(original_spectrum, spectral_axis=original_spectrum + shift)`` works, but silently fails to update the ``spectral_axis``. So I think this may just be a bug that needs fixing... but once it's fixed the example in #600 should be updated to reflect this idiom instead of explicitly copying the spectral axis.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the Spectrum1D constructor behavior described in this issue and review the spectral-shifting example from #600. Verify the constructor copies unspecified attributes such as uncertainty, meta, and mask while honoring an explicitly provided spectral_axis. Update the #600 example to use this constructor idiom and add or adjust coverage for the resulting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.