specutils.Spectrum1D refuses a Pandas Series as input
- Dominant language
- Python
- Stars
- 204
- Forks
- 135
- Avg merge
- 12h 55m
- Merged PRs (30d)
- 1
Description
I tried adapting the specutils demo notebook for my own spectra. The input spectrum is in a pandas dataframe, which specutils.Spectrum1D() refuses as follows:
----> 1 s1723_spec = specutils.Spectrum1D(spectral_axis = df_s1723['wave'] * u.AA, flux=df_s1723['fnu'] * u.Unit('Jansky'))
~/anaconda3/envs/astroconda/lib/python3.6/site-packages/specutils/spectra/spectrum1d.py in __init__(self, flux, spectral_axis, wcs, velocity_convention, rest_value, redshift, radial_velocity, bin_specification, **kwargs)
97 if flux is not None:
98 if not isinstance(flux, u.Quantity):
---> 99 raise ValueError("Flux must be a `Quantity` object.")
100 elif flux.isscalar:
101 flux = u.Quantity([flux])
ValueError: Flux must be a `Quantity` object.
The kludgy workaround is to put .values after each Series:
s1723_spec = specutils.Spectrum1D(spectral_axis = df_s1723['wave'].values * u.AA, flux=df_s1723['fnu'].values * u.Unit('Jansky'))
A better solution would be for astropy to gracefully accept a pandas Series. (And maybe even a pandas dataframe? Hey, I can dream.)
Contributor guide
Research direction
Start at specutils/spectra/spectrum1d.py, particularly the Spectrum1D constructor and its flux validation. Check how pandas Series values interact with Quantity inputs, then verify that the shown Series-based call works without .values while retaining the supplied units; dataframe support is only suggested, not specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100