Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions specutils/spectra/spectral_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def _edges_from_centers(centers, unit):
centers, with the two outer edges based on extrapolated centers added
to the beginning and end of the spectral axis.
"""
diffs = centers[1:] - centers[:-1]
if not np.all(diffs == diffs[0]):
raise ValueError("Cannot calculate consistent bin edges from"
" unevenly spaced bin centers")

a = np.insert(centers, 0, 2*centers[0] - centers[1])
b = np.append(centers, 2*centers[-1] - centers[-2])
edges = (a + b) / 2
Expand Down
6 changes: 6 additions & 0 deletions specutils/tests/test_spectral_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def test_create_with_bin_edges():
assert np.all(spectral_axis.bin_edges == wavelengths)
assert np.all(spectral_axis == [505., 530., 555., 575.]*u.AA)

def test_uneven_centers():

wavelengths = [10,15,25,28]*u.AA

with pytest.raises(ValueError):
spectral_axis.bin_edges

# GENERAL TESTS

Expand Down