-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
arithmetic operations don't check compatibility of spectral_axis #989
Comments
I don't understand why the operator is so not caring about the type of specutils/specutils/spectra/spectrum1d.py Lines 674 to 681 in 68dd711
Also, this is out of scope, right? specutils/specutils/spectra/spectral_region.py Lines 141 to 145 in 68dd711
|
My proposal for
Is
Do I have to worry about magnitude flux units in |
Thanks for writing up a proposal @pllim. Here are my thoughts:
I think we should also allow
I haven't used this before, from a quick look it's probably sufficient.
These are in scope, but the unit compatibility checks you're proposing below aren't. If you want to add those now, go for it, but the scope of this issue is checking that the spectral axes match.
We do use
No. |
Can you please clarify? It makes sense to allow scalar Quantity, but if the Quantity has an array, it feels wrong to just assume user knows the arrays maps to the same spectral axis. |
Well, I guess they can also be addressed in a different PR... |
Here's my theoretical workflow: I have a 2D or 3D It seems unlikely (thought not impossible) that I would just coincidentally have something of the exact same shape as my original spectrum and be bamboozled by addition/subtraction working when it shouldn't. |
Right, I'm not saying it shouldn't be done, I'm just saying if you want to minimize the scope of your PR for this issue, the units stuff can be separate work. |
To enforce good hygiene, i.e. to avoid adding apples and oranges, I think we should be restrictive on the quantities that can be added to/subtracted from Spectrum 1D's:
For multiplication and division:
While it may be an added burden to attach a spectral axis for the cases discussed by @rosteen above, it only takes one extra step. |
@eteq @nmearl @keflavich Any thoughts you want to throw in the pile here? |
Yeah, I agree with @pllim's suggestion that Scalar addition & subtraction should be allowed with matching units. Scalar multiplication and division should be allowed with or without units. |
What does it even mean physically when you multiply Jy by any random unit, like another Jy? Or Jy with Kelvin? Multiplication/division only makes sense to me when the other operand is unitless. Am I missing something? |
You're right, that's a pretty rare case. There are some where I do that, though. For example, if you want to integrate over a spectrum, you might do so by multiplying by the spectral width of the pixel and then summing. If the pixels have varying width, you need to be able to multiply by a vector of pixel widths. So multiplying by, e.g., km/s or nm or Hz is sometimes reasonable. There may be other cases - I don't think we should strictly exclude multiplication with unit'd quantities. |
Ok, sounds like I'm outvoted on requiring |
Arithmetic operations succeed so long as the flux arrays are of compatible shape, but do not check for equivalent spectral axis values. For example,
succeeds but returns a
Spectrum1D
object with a spectral axis adopted directly fromsp2
. Instead this should raise an error (or perhaps eventually support optional interpolation for cases in which there is sufficient overlap).Related: #198
The text was updated successfully, but these errors were encountered: