Skip to content

Commit

Permalink
fix initializer based on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eteq authored and nmearl committed Sep 18, 2019
1 parent 994118e commit 3c6f70a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions specutils/spectra/spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def __init__(self, flux=None, spectral_axis=None, wcs=None,
elif not self._rest_value.unit.is_equivalent(u.AA) and not self._rest_value.unit.is_equivalent(u.Hz):
raise u.UnitsError("Rest value must be energy/wavelength/frequency equivalent.")

super(Spectrum1D, self).__init__(
data=flux.value if isinstance(flux, u.Quantity) else flux,
wcs=wcs, **kwargs)

# set redshift after super() - necessary because the shape-checking
# requires that the flux be initialized

if redshift is None:
self.radial_velocity = radial_velocity
elif radial_velocity is None:
Expand All @@ -137,10 +144,6 @@ def __init__(self, flux=None, spectral_axis=None, wcs=None,
raise ValueError('cannot set both radial_velocity and redshift at '
'the same time.')

super(Spectrum1D, self).__init__(
data=flux.value if isinstance(flux, u.Quantity) else flux,
wcs=wcs, **kwargs)

if hasattr(self, 'uncertainty') and self.uncertainty is not None:
if not flux.shape == self.uncertainty.array.shape:
raise ValueError('Flux axis ({}) and uncertainty ({}) shapes must be the same.'.format(
Expand Down Expand Up @@ -245,7 +248,7 @@ def redshift(self, val):
if val is None:
self._radial_velocity = None
else:
self._radial_velocity = val * cnst.c
self.radial_velocity = val * cnst.c

@property
def radial_velocity(self):
Expand All @@ -270,7 +273,7 @@ def radial_velocity(self, val):
# each other. See https://stackoverflow.com/questions/47243451/checking-if-two-arrays-are-broadcastable-in-python
input_shape = val.shape
flux_shape = self.flux.shape[:-1]
if all((m == n) or (m == 1) or (n == 1)
if not all((m == n) or (m == 1) or (n == 1)
for m, n in zip(input_shape[::-1], flux_shape)):
raise ValueError("radial_velocity or redshift must have shape that "
"is compatible with this spectrum's flux array")
Expand Down

0 comments on commit 3c6f70a

Please sign in to comment.