Adding/subtracting ABmag Quantities loses the "type" of magnitude
See original GitHub issueThe following code raises a UnitConversionError
, because it appears the math operation lost track of the “type” of magnitude. fluxMag
and color
are both ABmag
, so I would expect their difference to also be an ABmag.
import numpy as np
import astropy.units as u
# color = np.random.random(5)*u.ABmag
color = 10*u.ABmag
flux = 10000
fluxMag = (flux*u.nJy).to(u.ABmag)
diff = fluxMag - color
print(color, fluxMag, diff)
print(diff.to(u.nJy))
prints the following, and then raises:
10.0 mag(AB) 21.4 mag(AB) 11.399999999999999 mag
...
astropy.units.core.UnitConversionError: '' (dimensionless) and 'nJy' (spectral flux density) are not convertible
If the -
is changed to +
, the exception is different:
10.0 mag(AB) 21.4 mag(AB) 31.4 mag(AB2)
...
astropy.units.core.UnitConversionError: 'AB2' and 'nJy' (spectral flux density) are not convertible
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
5.1 Vector Addition and Subtraction: Graphical Methods
The Graphical Method of Vector Addition and Subtraction. Recall that a vector is a quantity that has magnitude and direction. For example, displacement, ......
Read more >How to Add and Subtract Vectors Algebraically - Universal Class
In this article, we are going to review the vector. Vectors--unlike simple numbers (scalars) that have only a magnitude--have both a magnitude (length)...
Read more >Loss of Accuracy
Loss of Accuracy. Addition and Subtraction might necessitate mantissa shift to make exponents match. This can cause the loss of some (or all)...
Read more >Addition and Subtraction
The addition of two IEEE FPS numbers is performed in a similar manner. ... the addition is performed, the result is converted back...
Read more >17. 3.2 Vector Addition and Subtraction: Graphical Methods
A vector is a quantity that has magnitude and direction. Displacement, velocity, acceleration, and force, for example, are all vectors.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
PR #8519 is an attempt at making the message better. I will try to clean it up to merge at the next coworking morning telecon.
Sorry about that!
python 3.6.6 numpy 1.14.5 astropy 3.0.3