diff --git a/docs/spectrum1d.rst b/docs/spectrum1d.rst index 5318d33f3..8ede69ab6 100644 --- a/docs/spectrum1d.rst +++ b/docs/spectrum1d.rst @@ -36,7 +36,7 @@ create it explicitly from arrays or `~astropy.units.Quantity` objects: .. note:: The ``spectral_axis`` can be either ascending or descending, but must be monotonic - in either case. + in either case. Reading from a File ------------------- @@ -97,7 +97,7 @@ objects will propagate uncertainties. Uncertainties are a special subclass of :class:`~astropy.nddata.NDData`, and their propagation rules are implemented at the class level. Therefore, users must -specify the uncertainty type at creation time +specify the uncertainty type at creation time. .. code-block:: python @@ -248,9 +248,9 @@ axis is always the last. Slicing ------- -As seen above, `~specutils.Spectrum1D` supports slicing in the same way as any -other array-like object. Additionally, a `~specutils.Spectrum1D` can be sliced -along the spectral axis using world coordinates. +As seen above, `~specutils.Spectrum1D` supports slicing in the same way as any +other array-like object. Additionally, a `~specutils.Spectrum1D` can be sliced +along the spectral axis using world coordinates. .. code-block:: python @@ -261,7 +261,7 @@ along the spectral axis using world coordinates. >>> spec_slice.spectral_axis -It is also possible to slice on other axes using simple array indices at the +It is also possible to slice on other axes using simple array indices at the same time as slicing the spectral axis based on spectral values. .. code-block:: python @@ -273,7 +273,7 @@ same time as slicing the spectral axis based on spectral values. >>> spec_slice.shape (2, 4) -If the `specutils.Spectrum1D` was created with a WCS that included spatial +If the `specutils.Spectrum1D` was created with a WCS that included spatial information, for example in case of a spectral cube with two spatial dimensions, the `specutils.Spectrum1D.crop` method can be used to subset the data based on the world coordinates. The inputs required are two sets up `astropy.coordinates` @@ -282,7 +282,7 @@ one of the coordinates is decreasing along an axis, the higher world coordinate value will apply to the lower bound input. .. code-block:: python - + >>> from astropy.coordinates import SpectralCoord, SkyCoord >>> import astropy.units as u @@ -293,9 +293,9 @@ value will apply to the lower bound input. Collapsing ---------- -`~specutils.Spectrum1D` has built-in convenience methods for collapsing the +`~specutils.Spectrum1D` has built-in convenience methods for collapsing the flux array of the spectrum via various statistics. The available statistics are -mean, median, sum, max, and min, and may be called either on a specific axis +mean, median, sum, max, and min, and may be called either on a specific axis (or axes) or over the entire flux array. The collapse methods currently respect the ``mask`` attribute of the `~specutils.Spectrum1D`, but do not propagate any ``uncertainty`` attached to the spectrum. @@ -307,18 +307,18 @@ any ``uncertainty`` attached to the spectrum. The 'axis' argument of the collapse methods may either be an integer axis, or a -string specifying either 'spectral', which will collapse along only the +string specifying either 'spectral', which will collapse along only the spectral axis, or 'spatial', which will collapse along all non-spectral axes. .. code-block:: python >>> spec.mean(axis='spatial') # doctest: +IGNORE_OUTPUT - , + , spectral_axis= -Note that in this case, the result of the collapse operation is a -`~specutils.Spectrum1D` rather than an `astropy.units.Quantity`, because the -collapse operation left the spectral axis intact. +Note that in this case, the result of the collapse operation is a +`~specutils.Spectrum1D` rather than an `astropy.units.Quantity`, because the +collapse operation left the spectral axis intact. It is also possible to supply your own function for the collapse operation by calling `~specutils.Spectrum1D.collapse()` and providing a callable function diff --git a/specutils/spectra/spectrum1d.py b/specutils/spectra/spectrum1d.py index d73f1688e..639e094e0 100644 --- a/specutils/spectra/spectrum1d.py +++ b/specutils/spectra/spectrum1d.py @@ -673,13 +673,19 @@ def radial_velocity(self, val): def __add__(self, other): if not isinstance(other, (NDCube, u.Quantity)): - other = u.Quantity(other, unit=self.unit) + try: + other = u.Quantity(other, unit=self.unit) + except TypeError: + return NotImplemented return self.add(other) def __sub__(self, other): if not isinstance(other, NDCube): - other = u.Quantity(other, unit=self.unit) + try: + other = u.Quantity(other, unit=self.unit) + except TypeError: + return NotImplemented return self.subtract(other)