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.

Arithmetic operation on dimensionless mag units

See original GitHub issue

Description

Not sure whether this is a bug or just a misunderstanding: I am wondering how dimensionless units work; especially the conversion to linear.

Expected behavior

I would expect that u.mag works equivalently to f.e. u.ABmag when it comes to conversion:

>>> import astropy.units as u
>>> m = 12 * u.ABmag
>>> print(m)
12.0 mag(AB)
>>> print(m.to(u.erg/u.s/u.m**2/u.Hz))
5.754399373371543e-21 erg / (Hz m2 s)
>>> flux = 1e-20 * u.erg/u.s/u.m**2/u.Hz
>>> print(flux.to(u.ABmag))
11.399999999999997 mag(AB)

i.e. u.mag should be convertible to and from a dimensionless unit.

Actual behavior

>>> import astropy.units as u
>>> m = 1 * u.mag
>>> print(m)
1.0 mag
>>> print(m.to(''))
Traceback (most recent call last):
[…]
  File "/usr/lib/python3/dist-packages/astropy/units/core.py", line 1027, in _apply_equivalencies
    raise UnitConversionError(
astropy.units.core.UnitConversionError: 'mag' and '' (dimensionless) are not convertible
>>> f = u.Quantity(10.0)
>>> print(f.to(u.mag))
Traceback (most recent call last):
[…]
  File "/usr/lib/python3/dist-packages/astropy/units/core.py", line 1027, in _apply_equivalencies
    raise UnitConversionError(
astropy.units.core.UnitConversionError: '' (dimensionless) and 'mag' are not convertible

Specific question: what is the “preferred” way to convert to copy to/from dimensionless magnitudes (except explicitly using -2.5*log10(f))?

Steps to Reproduce

See above

System Details

Astropy 5.0rc1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
pllimcommented, Nov 12, 2021

Maybe we should just stop using the magnitude system…

1reaction
olebolecommented, Nov 12, 2021

I think also with dex the calc is wrong. Normally, it is mag = -2.5*log10(f2/f1), which would for f2/f1=2 give -0.7526. Or, more explicit:

>>> m1 = 15*u.ABmag
>>> fac = 2.0
>>> m2 = (fac * m1.to('erg / (Hz m2 s)')).to(u.ABmag)
>>> print(m2)
14.247425010840047 mag(AB)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dimensionless quantity - Wikipedia
A dimensionless quantity is a quantity to which no physical dimension is assigned, with a corresponding SI unit of measurement of one (or...
Read more >
Dimensionless Unit - an overview | ScienceDirect Topics
Coupling constant dependence of the bound state energies of electrons with an anomalous magnetic moment in a Coulomb potential. The curves show some...
Read more >
Magnitudes and Other Logarithmic Units — Astropy v5.2
This happens generally for division and multiplication, since these processes work only for dimensionless magnitudes (otherwise, the physical unit would have to ...
Read more >
Dimensionless units in the SI - IOPscience
Here we consider dimensionless units as defined in the SI, e.g. angular units ... Angles play an essential role in mathematics, physics, and...
Read more >
The Problem with 'Dimensionless Quantities' - SciTePress
dimensionless quantities that all have the SI unit one. ... The arithmetic, ordering and equivalence operations ... A Treatise on Electricity and Mag-....
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