-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Raise exception when spectral and flux axes have different lengths #508
Raise exception when spectral and flux axes have different lengths #508
Conversation
Just a note on the docs/diagnostics: the error message now states "must be the same (or uncertainty must be a singleton", but a length-1 or scalar |
specutils/spectra/spectrum1d.py
Outdated
@@ -112,6 +118,12 @@ def __init__(self, flux=None, spectral_axis=None, wcs=None, | |||
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 (or uncertainty must be a singleton)'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ValueError('Flux axis ({}) and uncertainty ({}) shapes must be the same (or uncertainty must be a singleton)'.format( | |
raise ValueError('Flux axis ({}) and uncertainty ({}) shapes must be the same.'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor suggestion but otherwise this looks good to me.
Note: I'm approving to indicate "I like it overall, and don't need to see it again unless someone wants more feedback from me", but the inline comment is meant to mean "don't merge without the comment either being accepting or intentionally rejected" (i.e., if there's a good reason not to be doing this then that's fine).
Co-Authored-By: Erik Tollerud <erik.tollerud@gmail.com>
This will check the spectral_axis and flux axis lengths to make sure they are the same and will raise an exception if that is not the case.
Fixes #326