Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce stricter initalizer for Spectrum1D #513

Merged
merged 2 commits into from
Sep 17, 2019
Merged
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
10 changes: 9 additions & 1 deletion specutils/spectra/spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ class Spectrum1D(OneDSpectrumMixin, NDDataRef):
around with the spectrum container object.
"""
def __init__(self, flux=None, spectral_axis=None, wcs=None,
velocity_convention=None, rest_value=None, *args, **kwargs):
velocity_convention=None, rest_value=None, **kwargs):
# Check for pre-defined entries in the kwargs dictionary.
unknown_kwargs = set(kwargs).difference(
{'data', 'unit', 'uncertainty', 'meta', 'mask', 'copy'})

if len(unknown_kwargs) > 0:
raise ValueError("Initializer contains unknown arguments(s): {}."
"".format(', '.join(map(str, unknown_kwargs))))

# If the flux (data) argument is a subclass of nddataref (as it would
# be for internal arithmetic operations), avoid setup entirely.
if isinstance(flux, NDDataRef):
Expand Down
5 changes: 5 additions & 0 deletions specutils/tests/test_spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def test_create_from_arrays():
assert isinstance(spec.flux, u.Quantity)
assert spec.flux.size == 50

# Test creating spectrum with unknown arguments
with pytest.raises(ValueError) as e_info:
spec = Spectrum1D(wavelength=np.arange(1, 50) * u.nm,
flux=np.random.randn(48) * u.Jy)


def test_create_from_multidimensional_arrays():
"""
Expand Down