question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding/subtracting ABmag Quantities loses the "type" of magnitude

See original GitHub issue

The 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:closed
  • Created 5 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
parejkojcommented, Apr 3, 2019

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.

1reaction
parejkojcommented, Mar 8, 2019

Sorry about that!

python 3.6.6 numpy 1.14.5 astropy 3.0.3

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found