astropy / astropy/specutils

LinearInterpolatedResampler fails on uncertainty of UnknownUncertainty type

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

Description

When (unsuccessfully) trying to reproduce #647 I raised a different exception by modifying the docs' [example](https://specutils.readthedocs.io/en/stable/api/specutils.manipulation.LinearInterpolatedResampler.html):
```
input_spectrum = Spectrum1D(flux=[1, 3, 7, 6, 20] * u.mJy,
spectral_axis=[2, 4, 12, 16, 20] * u.nm,
uncertainty=[0.4, 0.5, 0.6, 0.8, 1])
resample_grid = [1, 5, 9, 13, 14, 17, 21, 22, 23] * u.nm
fluxc_resample = LinearInterpolatedResampler()

input_spectrum.uncertainty
UnknownUncertainty([0.4, 0.5, 0.6, 0.8, 1. ])
output_spectrum1D = fluxc_resample(input_spectra, resample_grid)

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in
----> 1 output_spectrum1D = fluxc_resample(input_spectrum, resample_grid)

~/lib/python3.8/site-packages/specutils/manipulation/resample.py in __call__(self, orig_spectrum, fin_spec_axis)
37 Return the resulting `~specutils.Spectrum1D` of the resampling.
38 """
---> 39 return self.resample1d(orig_spectrum, fin_spec_axis)
40
41 @abstractmethod

~/lib/python3.8/site-packages/specutils/manipulation/resample.py in resample1d(self, orig_spectrum, fin_spec_axis)
321 unit=orig_spectrum.unit)
322
--> 323 return Spectrum1D(spectral_axis=fin_spec_axis,
324 flux=out_flux,
325 uncertainty=new_unc)

~/lib/python3.8/site-packages/specutils/spectra/spectrum1d.py in __init__(self, flux, spectral_axis, wcs, velocity_convention, rest_value, redshift, radial_velocity, **kwargs)
157 spectral_axis.shape[0], flux.shape[-1]))
158
--> 159 super(Spectrum1D, self).__init__(
160 data=flux.value if isinstance(flux, u.Quantity) else flux,
161 wcs=wcs, **kwargs)

~/lib/python3.8/site-packages/astropy/nddata/nddata.py in __init__(self, data, uncertainty, mask, wcs, meta, unit, copy)
232 self._unit = unit
233 # Call the setter for uncertainty to further check the uncertainty
--> 234 self.uncertainty = uncertainty
235
236 def __str__(self):

~/lib/python3.8/site-packages/astropy/nddata/nddata.py in uncertainty(self, value)
324 # to be saved as weakref but that's done by NDUncertainty
325 # setter).
--> 326 value.parent_nddata = self
327 self._uncertainty = value

~/lib/python3.8/site-packages/astropy/nddata/nduncertainty.py in parent_nddata(self, value)
231 unit_from_data = self._data_unit_to_uncertainty_unit(parent_unit)
232 try:
--> 233 unit_from_data.to(self.unit)
234 except UnitConversionError:
235 raise UnitConversionError("Unit {} of uncertainty "

AttributeError: 'NoneType' object has no attribute 'to'
```
Is there other functionality that would handle an `astropy.nddata.nduncertainty.UnknownUncertainty` correctly, or should this best be checked on initialising `Spectrum1D`?

Contributor guide

Open the contributing guide

Research direction

Start with the docs example for LinearInterpolatedResampler and the resample1d entry point shown in the traceback. Reproduce the UnknownUncertainty case and inspect how the resulting uncertainty is passed to Spectrum1D; done means the example no longer raises AttributeError and the intended handling is covered by an appropriate test.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.