Skip to content

Commit

Permalink
Raise error for invalid order, add note to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Jun 27, 2024
1 parent bbbc41e commit 1731f33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ The `~specutils.analysis.moment` function computes moments of any order:
>>> moment(noisy_gaussian, SpectralRegion(7*u.GHz, 3*u.GHz), order=2) # doctest:+FLOAT_CMP
<Quantity 0.58586695 GHz2>
By default the moment is calculated along the spectral axis, but any axis can be specified with
the ``axis`` keyword. Non-spectral-axis moments are calculated using integer pixel values for the
dispersion and return unitless values. Although they are available, they are perhaps of
questionable usefulness.


Line Widths
-----------
Expand Down
4 changes: 2 additions & 2 deletions specutils/analysis/moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def _compute_moment(spectrum, regions=None, order=0, axis='spectral'):
"""
This is a helper function for the above `moment()` method.
"""
if order is None or order < 0:
return None
if int(order) != order or order < 0:
raise ValueError("Order must be a positive integer.")

if axis == "spectral":
if isinstance(spectrum, SpectrumCollection):
Expand Down

0 comments on commit 1731f33

Please sign in to comment.